py4j

## Class Gateway

- java.lang.Object
- - py4j.Gateway

-     public class Gateway
      extends Object

  A Gateway manages various states: entryPoint, references to objects returned to a Python program, etc.

  This class is not intended to be directly accessed by users.

  Author:
    Barthelemy Dagenais

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Gateway(Object entryPoint)`
    `Gateway(Object entryPoint, CallbackClient cbClient)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `closeConnection()` Called when a connection is closed.
    `void` | `deleteObject(String objectId)`
    `protected AtomicInteger` | `getArgCounter()`
    `Map<String,Object>` | `getBindings()`
    `CallbackClient` | `getCallbackClient()`
    `JVMView` | `getDefaultJVMView()`
    `Object` | `getEntryPoint()`
    `protected String` | `getNextObjectId()`
    `protected AtomicInteger` | `getObjCounter()`
    `Object` | `getObject(String objectId)`
    `protected Object` | `getObjectFromId(String targetObjectId)`
    `ReflectionEngine` | `getReflectionEngine()`
    `ReturnObject` | `getReturnObject(Object object)`
    `ReturnObject` | `invoke(String fqn, List<Object> args)` Invokes a constructor and returned the constructed object.
    `ReturnObject` | `invoke(String methodName, String targetObjectId, List<Object> args)` Invokes a method.
    `protected boolean` | `isArray(Object object)`
    `protected boolean` | `isDecimalObject(Object object)`
    `protected boolean` | `isList(Object object)`
    `protected boolean` | `isMap(Object object)`
    `protected boolean` | `isPrimitiveObject(Object object)`
    `protected boolean` | `isSet(Object object)`
    `boolean` | `isStarted()`
    `String` | `putNewObject(Object object)` Adds a new object to the gateway bindings and return the generated ID.
    `Object` | `putObject(String id, Object object)`
    `void` | `resetCallbackClient(InetAddress pythonAddress, int pythonPort)` Replace the callback client with the new one which connects to the given address and port.
    `void` | `setStarted(boolean isStarted)`
    `void` | `shutdown()` Releases all objects that were referenced by this Gateway and shuts down the CallbackClient.
    `void` | `shutdown(boolean shutdownCallbackClient)` Releases all objects that were referenced by this Gateway and optionally shut down the callback client.
    `void` | `startup()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Gateway

          public Gateway(Object entryPoint)

    - #### Gateway

          public Gateway(Object entryPoint,
                         CallbackClient cbClient)

  - ### Method Detail

    - #### resetCallbackClient

          public void resetCallbackClient(InetAddress pythonAddress,
                                          int pythonPort)

      Replace the callback client with the new one which connects to the given address and port. This method is useful if for some reason your CallbackServer changes its address or you come to know of the address after Gateway has already instantiated.

      This method is not thread-safe! Make sure that only one thread calls this method.

      Parameters:
        `pythonAddress` - The address used by a PythonProxyHandler to connect to a Python gateway.
        `pythonPort` - The port used by a PythonProxyHandler to connect to a Python gateway. Essentially the port used for Python callbacks.

    - #### closeConnection

          public void closeConnection()

      Called when a connection is closed.

    - #### deleteObject

          public void deleteObject(String objectId)

    - #### getArgCounter

          protected AtomicInteger getArgCounter()

    - #### getBindings

          public Map<String,Object> getBindings()

      Returns:
        The bindings of the Gateway. Should never be called by other classes except subclasses and testing classes.

    - #### getCallbackClient

          public CallbackClient getCallbackClient()

    - #### getDefaultJVMView

          public JVMView getDefaultJVMView()

    - #### getEntryPoint

          public Object getEntryPoint()

    - #### getNextObjectId

          protected String getNextObjectId()

    - #### getObjCounter

          protected AtomicInteger getObjCounter()

    - #### getObject

          public Object getObject(String objectId)

      Parameters:
        `objectId` -
      Returns:
        The object associated with the id or null if the object id is unknown.

    - #### getObjectFromId

          protected Object getObjectFromId(String targetObjectId)

    - #### getReflectionEngine

          public ReflectionEngine getReflectionEngine()

    - #### getReturnObject

          public ReturnObject getReturnObject(Object object)

    - #### invoke

          public ReturnObject invoke(String fqn,
                                     List<Object> args)

      Invokes a constructor and returned the constructed object.

      Parameters:
        `fqn` - The fully qualified name of the class.
        `args` -
      Returns:

    - #### invoke

          public ReturnObject invoke(String methodName,
                                     String targetObjectId,
                                     List<Object> args)

      Invokes a method.

      Parameters:
        `methodName` -
        `targetObjectId` -
        `args` -
      Returns:

    - #### isArray

          protected boolean isArray(Object object)

    - #### isDecimalObject

          protected boolean isDecimalObject(Object object)

    - #### isList

          protected boolean isList(Object object)

    - #### isMap

          protected boolean isMap(Object object)

    - #### isPrimitiveObject

          protected boolean isPrimitiveObject(Object object)

    - #### isSet

          protected boolean isSet(Object object)

    - #### isStarted

          public boolean isStarted()

    - #### putNewObject

          public String putNewObject(Object object)

      Adds a new object to the gateway bindings and return the generated ID. Should NEVER be called by other classes except subclasses and testing classes.

      Parameters:
        `object` -
      Returns:

    - #### putObject

          public Object putObject(String id,
                                  Object object)

    - #### setStarted

          public void setStarted(boolean isStarted)

    - #### shutdown

          public void shutdown()

      Releases all objects that were referenced by this Gateway and shuts down the CallbackClient.

    - #### shutdown

          public void shutdown(boolean shutdownCallbackClient)

      Releases all objects that were referenced by this Gateway and optionally shut down the callback client.

      Parameters:
        `shutdownCallbackClient` - Shuts down the CallbackClient instance if true.

    - #### startup

          public void startup()