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 

Receiving node connection events in the server

From JPPF 3.3 Documentation

Jump to: navigation, search
Main Page > Customizing JPPF > Receiving node connection events

This extension point allows you to register a listener for receiving notifications when a node is connected to, or disconnected from the server. As for other JPPF extensions, it relies on the Service Provider Interface (SPI) mechanism to enable an easy registration.

To implement this extension, you first need to create an implementation of the NodeConnectionListener interface, defined as follows:

 public interface NodeConnectionListener extends EventListener {
   // Called when a node is connected to the server
   void nodeConnected(NodeConnectionEvent event);
 
   // Called when a node is disconnected from the server
   void nodeDisconnected(NodeConnectionEvent event);
 }

Each notification method receives instances of the NodeConnectionEvent class, which is defined as:

 public class NodeConnectionEvent extends EventObject {
   // Get the node information for this event
   public JPPFManagementInfo getNodeInformation()
 }

As we can see, these event objects are simple wrappers carrying detailed information about the node, via the class JPPFManagementInfo:

 public class JPPFManagementInfo
   implements Serializable, Comparable<JPPFManagementInfo> {
 
   // Get the host on which the node is running
   public String getHost()
 
   // Get the port on which the node's JMX server is listening
   public int getPort()
 
   // Get the system information associated with the node at the time
   // it established the connection
   public JPPFSystemInformation getSystemInfo()
 
   // Get the node's unique id (UUID)
   public String getId()
 
   // Determine whether this information represents another driver,
   // connected as a peer to the current driver
   public boolean isDriver()
 
   // Determine whether this information represents a real node
   public boolean isNode()
 }

For details on the available information, we encourage you to read the Javadoc for the class JPPFSystemInformation.


Note: from the nodeConnected() method, you may refuse the connection by throwing a RuntimeException. This will cause the JPPF driver to terminate the connection.


To deploy the extension:

  • create a file named org.jppf.server.event.NodeConnectionListener in the META-INF/services folder
  • in this same file, add the fully qualified class name of your NodeConnectionListener implementation, for example: mypackage.MyNodeConnectionListener. This is the service definition file for the extension.
  • create a jar with your code and and service definition file and add it to the driver's classpath, or simply add your classes folder to the driver's classpath.
Main Page > Customizing JPPF > Receiving node connection events

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