JPPF
 Home   About   Download   Documentation   Forums 

Initialization Hook sample

What does the sample do?

This sample demonstrates the use of a node initialization hook to implement a failover mechanism for the connection to the server. The hook reads a list of JPPF server addresses from the node configuration, and uses these addresses in the configured order.

The failover is performed as follows:

  1. At node startup time, read the list of servers and store it in memory
  2. Use the first server in the list and attempt to connect
  3. When the connection fails, the recovery mechanism will attempt to reconnect to the current server
  4. If the recovery fails, the current server is put at the end of the list and we get back to step 2

How do I run it?

Before running this sample, you need to install at least two JPPF server and at least one node.
For information on how to set up a node and server, please refer to the JPPF documentation.

For convenience, this sample provides 2 configurations for the servers, which you will find in InitializationHook/config/driver1 and InitializationHook/config/driver2. Additionally, a node configuration is provided in InitializationHook/config/node.
Once you have installed the 2 servers and at least one node, perform the following steps:

  1. Open a command prompt in JPPF-x.y-samples-pack/InitializationHook
  2. Build the sample: type "ant jar"; this will create a file named InitializationHook.jar
  3. Copy InitializationHook.jar in the "lib" folder of the JPPF node installation, to add it to the node's classpath.
  4. Replace the node's configuration with the one provided in this sample
  5. Replace the servers configurations with those provided in this sample
  6. Start the two drivers
  7. Start the node. Upon startup you should see the following messages in the node's console:
    *** found 3 servers ***
      registered server localhost:11111
      registered server localhost:11121
      registered server localhost:11131
  8. Kill the first driver (the one listening to port 11111), the node console will display the following:
    Attempting connection to the node server at localhost:11111
    SocketInitializer.initializeSocket(): Could not reconnect to the remote server
    Attempting connection to the class server at localhost:11121
    Reconnected to the class server
    JPPF Node management initialized
    Attempting connection to the node server at localhost:11121
    Reconnected to the node server
    Node successfully initialized
    The first two lines show the node trying to reconnect to the same driver, and failing to do so. This is the built-in connection recovery mechanism. The next lines show the node connecting to the second driver (port 11121), this is our failover mechanism taking place.
  9. Now, start the first driver again, and kill the second driver (port 11121), and you should see the following:
    Attempting connection to the node server at localhost:11121
    SocketInitializer.initializeSocket(): Could not reconnect to the remote server
    Attempting connection to the class server at localhost:11131
    Attempting connection to the class server at localhost:11111
    Reconnected to the class server
    JPPF Node management initialized
    Attempting connection to the node server at localhost:11111
    Reconnected to the node server
    Node successfully initialized
    In the same way as previously, we first see the node attempting to recover the broken connection. Then our failover mechanism attempts to connect to a driver listening to port 11131. Since we never started this driver, the connection attempt fails. The last lines show the node connecting to the first driver again. The failover mechanism browses the configured servers as if they were in a ring.

Related source files

What features of JPPF are demonstrated?

The main feature demonstrated is detailed in the JPPF documentation, in the Node Initialization Hooks section.

I have additional questions and comments, where can I go?

There are 2 privileged places you can go to:

Support This Project Copyright © 2005-2014 JPPF.org
Powered by Parallel Matters  Get JPPF at SourceForge.net. Fast, secure and Free Open Source software downloads