4.3. py4j.java_callback — Py4J Callback API

The py4j.java_callback module defines the classes that manage callbacks, i.e., Java objects calling Python objects. These classes should never be accessed directly by the users.

4.3.1. PythonProxyPool

class py4j.java_callback.PythonProxyPool

A PythonProxyPool manages proxies that are passed to the Java side. A proxy is a Python class that implements a Java interface.

A proxy has an internal class named Java with a member named implements which is a list of fully qualified names (string) of the implemented interfaces.

The PythonProxyPool implements a subset of the dict interface: pool[id], del(pool[id]), pool.put(proxy), pool.clear(), id in pool, len(pool).

The PythonProxyPool is thread-safe.

clear()
put(object)

Adds a proxy to the pool.

Parameters:
  • object – The proxy to add to the pool.
Return type:

A unique identifier associated with the object.

4.3.2. CallbackServer

class py4j.java_callback.CallbackServer(pool, gateway_client, port=25334)

The CallbackServer is responsible for receiving call back connection requests from the JVM. Usually connections are reused on the Java side, but there is at least one connection per concurrent thread.

Parameters:
  • pool – the pool responsible of tracking Python objects passed to the Java side.
  • gateway_client – the gateway client used to call Java objects.
  • port – the port the CallbackServer is listening to.
run()

Starts listening and accepting connection requests.

This method is called when invoking CallbackServer.start(). A CallbackServer instance is created and started automatically when a JavaGateway instance is created.

shutdown()

Stops listening and accepting connection requests. All live connections are closed.

This method can safely be called by another thread.

4.3.3. CallbackConnection

class py4j.java_callback.CallbackConnection(pool, input, socket, gateway_client)

A CallbackConnection receives callbacks and garbage collection requests from the Java side.

run()

Questions/Feedback?

blog comments powered by Disqus