JPPF, java, parallel computing, distributed computing, grid computing, parallel, distributed, cluster, grid, cloud, open source, android, .net
JPPF, java, parallel computing, distributed computing, grid computing, parallel, distributed, cluster, grid, cloud, open source, android, .net
JPPF

The open source
grid computing
solution

 Home   About   Features   Download   Documentation   On Github   Forums 

The ClientWithFailover wrapper class

From JPPF 4.2 Documentation

Jump to: navigation, search
Main Page > Development guide > The ClientWithFailover class



Deprecation notice: as of JPPF 4.1, the functionality provided by this class is now an integral part of the implementation of JPPFClient and its accompanying classes. Hence this class is no longer necessary. If it is used in your code, it will still work as intended, however you should prepare for the fact that this class will be removed in a future version.



The class ClientWithFailover enables the setup of connections failover based on the priority of the server connections defined in the client configuration. With this API, the configuration allows you define sophisticated failover strategies, such that a client can always failover to another driver when connection to the current one is broken.

This class provides an API that is very similar to that of JPPFClient:

public class ClientWithFailover
  implements ClientListener, ClientConnectionStatusListener {
  // Initialize this client wrapper with the specified array of listeners
  public ClientWithFailover(final ClientListener...listeners)

  // Initialize this client wrapper with the specified uuid and array of listeners
  public ClientWithFailover(final String uuid, final ClientListener...listeners)

  // Submit the specified job
  public List<Task<?>> submitJob(final JPPFJob job) throws Exception

  // Cancel the job with the specified uuid
  public boolean cancelJob(final String uuid) throws Exception

  // Close the underlying client and free its resources
  public void  close()

  // Get the JPPF client to which requests are delegated
  public JPPFClient getClient()
}

As you can see, the usage for this class is semantically identical to that of JPPFClient.

Here is an example setup:

In the client configuration we define the following driver connections:

jppf.drivers = driver-1 driver-2

driver-1.jppf.server.host = www.host-1.com
driver-1.priority = 10

driver-2.jppf.server.host = www.host-2.com
driver-2.priority = 20

Note that we define driver-2 with a higher priority than driver-1: we want the client to submit jobs primarily to driver-2, and failover to driver-1 if the connection to driver-2 fails. For this to happen, we use the following code:

ClientWithFailover client = new ClientWithFailover();
JPPFJob job = ...;
List<Task<?>> results = client.submitJob(job);

Simply using ClientWithFailover ensures that the failover strategy defined in the configuration is accounted for, and the job is submitted to the active connection with the highest priority. If the driver connection fails while the job is executing, the failover still occurs and the job's unexecuted tasks will be resubmitted to the currently active driver connection.

This feature is not limited to two driver connections: you can have multiple connections with the same priority, as well as a hierarchy of nested connection priorities without any size constraint.

Main Page > Development guide > The ClientWithFailover class

JPPF Copyright © 2005-2020 JPPF.org Powered by MediaWiki