Using Py4J is usually as simple as creating a JavaGateway object:
java_gateway = JavaGateway()
# you are now connected to the JVM
# and you can call any method defined on the Java side.
You can still customize and extend Py4J in many ways (e.g., you can choose the port to which you want to connect), so here are the classes you are the most likely to interact with:
A JavaGateway is the Python entry point to the JVM. A JavaGateway instance must be connected to a Gateway instance on the Java side.
Parameters: |
|
---|
javaGateway = JavaGateway(auto_start=False)
javaGateway.comm_channel.start()
# ... do some work here
javaGateway.comm_channel.stop()
Default communication channel (socket based) responsible for communicating with the Java Virtual Machine.
Parameters: |
|
---|
Closes the socket if auto_delete is True and the socket is opened.
This is an acceptable practice if you know that your Python VM implements garbage collection and closing sockets immediately is not a concern. Otherwise, it is always better (because it is predictable) to explicitly close the socket by calling CommChannel.close().
Sends a command to the JVM. This method is not intended to be called directly by Py4J users: it is usually called by JavaMember instances.
Parameter: | command – the string command to send to the JVM. The command must follow the Py4J protocol. |
---|---|
Return type: | the string answer received from the JVM. The answer follows the Py4J protocol. |
TBD
Exception thrown when a problem occurs with Py4J.
Parameter: | value – the error message |
---|
TBD
Represents a Java object from which you can call methods.
Parameters: |
|
---|
TBD
TBD
Maps a Python list to a Java list.
All operations possible on a Python list are implemented. For example, slicing (e.g., list[1:3]) will create a copy of the list on the JVM. Slicing is thus not equivalent to subList(), because a modification to a slice such as the addition of a new element will not affect the original list.
TBD