|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpy4j.GatewayServer
public class GatewayServer
This class enables Python programs to access a Java program. When a GatewayServer instance is started, Python programs can connect to the JVM by calling:
gateway = JavaGateway()
The
entryPoint passed to a GatewayServer can be accessed with the
entry_point
member:
gateway.entry_point
Technically, a GatewayServer is only responsible for accepting connection.
Each connection is then handled by a GatewayConnection
instance and the various states (e.g., entryPoint,
reference to returned objects) are managed by a Gateway
instance.
Field Summary | |
---|---|
static int |
DEFAULT_CONNECT_TIMEOUT
|
static int |
DEFAULT_PORT
|
static int |
DEFAULT_PYTHON_PORT
|
static int |
DEFAULT_READ_TIMEOUT
|
static String |
GATEWAY_SERVER_ID
|
Constructor Summary | |
---|---|
GatewayServer(Object entryPoint)
Creates a GatewayServer instance with default port (25333), default address (localhost), and default timeout value (no timeout). |
|
GatewayServer(Object entryPoint,
int port)
|
|
GatewayServer(Object entryPoint,
int port,
int connectTimeout,
int readTimeout)
|
|
GatewayServer(Object entryPoint,
int port,
int pythonPort,
int connectTimeout,
int readTimeout,
List<Class<? extends py4j.commands.Command>> customCommands)
|
|
GatewayServer(Object entryPoint,
int port,
int connectTimeout,
int readTimeout,
List<Class<? extends py4j.commands.Command>> customCommands,
CallbackClient cbClient)
|
Method Summary | |
---|---|
void |
addListener(GatewayServerListener listener)
|
protected Object |
createConnection(Gateway gateway,
Socket socket)
|
protected void |
fireConnectionError(Exception e)
|
protected void |
fireConnectionStarted()
|
protected void |
fireServerError(Exception e)
|
protected void |
fireServerPostShutdown()
|
protected void |
fireServerPreShutdown()
|
protected void |
fireServerStarted()
|
protected void |
fireServerStopped()
|
CallbackClient |
getCallbackClient()
|
int |
getConnectTimeout()
|
int |
getListeningPort()
|
int |
getPort()
|
int |
getPythonPort()
|
int |
getReadTimeout()
|
void |
removeListener(GatewayServerListener listener)
|
void |
run()
|
void |
shutdown()
Stops accepting connections, closes all current connections, and calls Gateway.shutdown() |
void |
start()
Starts to accept connections in a second thread (non-blocking call). |
void |
start(boolean fork)
Starts to accept connections. |
protected void |
startSocket()
Starts the ServerSocket. |
static void |
turnLoggingOff()
Utility method to turn logging off. |
static void |
turnLoggingOn()
Utility method to turn logging on. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_PORT
public static final int DEFAULT_PYTHON_PORT
public static final int DEFAULT_CONNECT_TIMEOUT
public static final int DEFAULT_READ_TIMEOUT
public static final String GATEWAY_SERVER_ID
Constructor Detail |
---|
public GatewayServer(Object entryPoint, int port, int connectTimeout, int readTimeout)
entryPoint
- The entry point of this Gateway. Can be null.port
- The port the GatewayServer is listening to.connectTimeout
- Time in milliseconds (0 = infinite). If a GatewayServer does
not receive a connection request after this time, it closes
the server socket and no other connection is accepted.readTimeout
- Time in milliseconds (0 = infinite). Once a Python program is
connected, if a GatewayServer does not receive a request
(e.g., a method call) after this time, the connection with the
Python program is closed.public GatewayServer(Object entryPoint, int port, int pythonPort, int connectTimeout, int readTimeout, List<Class<? extends py4j.commands.Command>> customCommands)
entryPoint
- The entry point of this Gateway. Can be null.port
- The port the GatewayServer is listening to.pythonPort
- The port used by a PythonProxyHandler to connect to a Python
gateway. Essentially the port used for Python callbacks.connectTimeout
- Time in milliseconds (0 = infinite). If a GatewayServer does
not receive a connection request after this time, it closes
the server socket and no other connection is accepted.readTimeout
- Time in milliseconds (0 = infinite). Once a Python program is
connected, if a GatewayServer does not receive a request
(e.g., a method call) after this time, the connection with the
Python program is closed.customCommands
- A list of custom Command classes to augment the Server
features. These commands will be accessible from Python
programs. Can be null.public GatewayServer(Object entryPoint, int port, int connectTimeout, int readTimeout, List<Class<? extends py4j.commands.Command>> customCommands, CallbackClient cbClient)
public GatewayServer(Object entryPoint)
Creates a GatewayServer instance with default port (25333), default address (localhost), and default timeout value (no timeout).
entryPoint
- The entry point of this Gateway. Can be null.public GatewayServer(Object entryPoint, int port)
entryPoint
- The entry point of this Gateway. Can be null.port
- The port the GatewayServer is listening to.Method Detail |
---|
protected void startSocket() throws Py4JNetworkException
Starts the ServerSocket.
Py4JNetworkException
- If the port is busy.public void run()
run
in interface Runnable
protected Object createConnection(Gateway gateway, Socket socket) throws IOException
IOException
public void start(boolean fork)
Starts to accept connections.
fork
- If true, the GatewayServer accepts connection in another
thread and this call is non-blocking. If False, the
GatewayServer accepts connection in this thread and the call
is blocking (until the Gateway is shutdown by another thread).
Py4JNetworkException
- If the server socket cannot start.public void start()
Starts to accept connections in a second thread (non-blocking call).
public void shutdown()
Stops accepting connections, closes all current connections, and calls
Gateway.shutdown()
public int getConnectTimeout()
public int getReadTimeout()
public int getPythonPort()
public int getPort()
public int getListeningPort()
public CallbackClient getCallbackClient()
public void addListener(GatewayServerListener listener)
public void removeListener(GatewayServerListener listener)
protected void fireServerStarted()
protected void fireServerStopped()
protected void fireServerError(Exception e)
protected void fireServerPreShutdown()
protected void fireServerPostShutdown()
protected void fireConnectionStarted()
protected void fireConnectionError(Exception e)
public static void turnLoggingOff()
Utility method to turn logging off. Logging is turned off by default.
public static void turnLoggingOn()
Utility method to turn logging on. Logging is turned off by default.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |