Embedded driver and node
From JPPF 6.1 Documentation
|
Main Page > Deployment > Embedded driver and node |
1 Embedded driver
A JPPF driver can be started programmatically suing the JPPFDriver class , defined as:
public class JPPFDriver {
// Initialize this JPPF driver with the specified configuration
public JPPFDriver(TypedProperties configuration)
// Initialize and start this driver
public JPPFDriver start() throws Exception
// Get this driver's unique identifier
public String getUuid()
// Get a server-side representation of a job from its uuid
public JPPFDistributedJob getJob(String jobUuid)
// Get the object which manages the job dispatch listeners
public JobTasksListenerManager getJobTasksListenerManager()
// Get the system ibnformation for this driver
public JPPFSystemInformation getSystemInformation()
// Get the object holding the statistics monitors
public JPPFStatistics getStatistics()
// Add a custom peer driver discovery mechanism to those already registered, if any
public void addDriverDiscovery(PeerDriverDiscovery discovery)
// Remove a custom peer driver discovery mechanism from those already registered
public void removeDriverDiscovery(PeerDriverDiscovery discovery)
// Determine whether this server is shutting down, in which case it does not accept connections anymore
public boolean isShuttingDown()
// Get this driver's configuration
public TypedProperties getConfiguration()
// Shutdown this driver and all its components
public void shutdown()
}
The driver's life cycle is as follows:
- create it using the constructor JPPFDriver(TypedProperies) which takes a configuration object
- start the driver using the start() method
- when it is no longer needed, suht it down with the shutdown() method
Here is an example usage:
// create the driver configuration TypedProperties driverConfig = new TypedProperties() .set(JPPFProperties.SERVER_PORT, 11111) // disable SSL .set(JPPFProperties.SSL_SERVER_PORT, -1); // start the JPPF driver final JPPFDriver driver = new JPPFDriver(driverConfig).start(); // ... use the driver ... // now shut it down driver.shutdown();
2 Embedded node
A JPPF node can be created and started using the NodeRunner class, which will create a Node object. NodeRunner exposes the following API:
public class NodeRunner {
// Initialize this node runner with the specified configuration
public NodeRunner(TypedProperties configuration)
// Run a node embedded in the current JVM
public void start(String...args)
// Shutdown the node
public void shutdown()
// Get the node's universal unique identifier
public String getUuid()
// Determine whether the node is offline
public boolean isOffline()
// Get the actual node started by this node runner, if any
public Node getNode()
}
From this API, the node life cycle is straightforward:
- create a NodeRunner using the constructor NodeRunner(TypedProperties) which takes a configuration object
- start the node with the start() method
Important note: the start() method is blocking, therefore it should be called from a separate thread to avoid blocking the current thread, as in this example:
final NodeRunner runner = ...; new Thread(() -> runner.start()).start();
- when the node is no longer needed, shut it down by calling shutdown()
Note: the Node instance returned by getNode() may vary over time: whenever the node is disconnected from the driver, the NodeRunner will create a new Node isntance and attempt to connect it back.
Example usage:
// create the node configuration TypedProperties nodeConfig = new TypedProperties() .set(JPPFProperties.SERVER_HOST, "localhost") .set(JPPFProperties.SERVER_PORT, 11111) .set(JPPFProperties.MANAGEMENT_PORT, 11111) .set(JPPFProperties.SSL_ENABLED, false); final NodeRunner nodeRunner = new NodeRunner(nodeConfig); // start the node in a separate thread new Thread(() -> nodeRunner.start()).start(); // ... use the node ... // shut down the node nodeRunner.shutdown();
3 Related sample
Please refer to the Embedded Grid demo.
| Main Page > Deployment > Embedded driver and node |

