public static JPPFClient createClient() { TypedProperties clientConfig = new TypedProperties(); clientConfig.setBoolean("jppf.discovery.enabled", false) // disable server discovery .setString("jppf.drivers", "driver1") // declare a named driver connection pool .setString("driver1.jppf.server.host", "localhost") // set the driver host or IP .setInt("driver1.jppf.server.port", 11111) // set the driver port .setInt("driver1.jppf.pool.size", 1); // set the connection pool size // let the client generate its own uuid, use the specified configuration, with no connection pool listener return new JPPFClient(null, clientConfig, new ConnectionPoolListener[0]);}
can I tell driver to use port 0 to select its ports, then programmatically find out which ports it chose, and dynamically start client+node with the proper driver ports configured?
// set port 0 to have the driver chose an arbitrary portJPPFConfiguration.getProperties().setInt("jppf.server.port", 0):JPPFDriver.main("noLauncher");// retrieve the port number (using undocumented APIs)JPPFDriver driver = JPPFDriver.getInstance();int port = -1;int[] ports = driver.getAcceptorServer().getPorts();if ((ports != null) && (ports.length > 0)) port = ports[0];else { int[] sslPorts = driver.getAcceptorServer().getSSLPorts(); if ((sslPorts != null) && (sslPorts.length > 0)) port = sslPorts[0];}// setup the client with the port numberTypedProperties clientConfig = new TypedProperties().setBoolean("jppf.discovery.enabled", false) .setString("jppf.drivers", "driver1") .setString("driver1.jppf.server.host", "localhost") .setInt("driver1.jppf.server.port", port);JPPFClient client = new JPPFClient(null, clientConfig, new ConnectionPoolListener[0]);
What would be a nice way of shutting it down when my client is closed?
One thing I'm wondering about is why not simply use the client's local executor in this use case?
There isn't a nice way to do that.
JPPFConfiguration.getProperties().setBoolean("jppf.server.exitOnShutdown", false);// no-arg contructor ==> no network connection nor remote JMX connectorJMXDriverConnectionWrapper jmx = new JMXDriverConnectionWrapper();jmx.connect();jmx.restartShutdown(1L, -1L);jmx.close();