Package org.jppf.management.forwarding
node selector.
This provides two major benefits:
- this allows managing and monitoring the nodes in situations where the nodes are not reachable from the client, for instance when the client and nodes are on different networks or subnets
- the requests and notification forwarding mechanism automatically adapts to node connection and disconnection events, which means that if new nodes are started in the grid, they will be automatically enrolled in the forwarding mechanism, provided they match the node selector
Forwarding management requests
The request forwarding mechanism is based on a built-in driver MBean: NodeForwardingMBean, which provides methods to invoke methods, or get or set attributes on remote node MBeans.
Each of its methods requires a NodeSelector argument and an MBean name, to determine to which nodes, and which MBean in these nodes, the request will be performed.
The return value is always a map of node UUIDs to the corresponding value returned by the request (if any) to the corresponding node.
If an exception is raised when performing the request on a specific node, then that exception is returned in the map.
Here is an example:
JPPFClient client = ...;
AbstractJPPFClientConnection conn = (AbstractJPPFClientConnection) client.getClientConnection();
JMXDriverConnectionWrapper driverJmx = conn.getJmxConnection();
NodeForwardingMBean proxy =
driverJmx.getProxy(NodeForwardingMBean.MBEAN_NAME, NodeForwardingMBean.class);
// this selector selects all nodes attached to the driver
NodeSelector selector = new NodeSelector.AllNodes();
// this selector selects all nodes that have more than 2 processors
ExecutionPolicy policy = new MoreThan("availableProcessors ", 2);
NodeSelector selector2 = new NodeSelector.ExecutionPolicySelector(policy);
// invoke the state() method on the remote 'JPPFNodeAdminMBean' node MBeans.
// note that the MBean name does not need to be stated explicitely.
ResultsMapélt;String, JPPFNodeState> results = proxy.state(selector);
// this is an exact equivalent, explicitely stating the target MBean on the remote nodes:
String targetMBeanName = JPPFNodeAdminMBean.MBEAN_NAME;
ResultsMapélt;String, JPPFNodeState> results2 = proxy.forwardInvoke(selector, targetMBeanName, "state");
// handling the results
for (Map.Entry<String, InvocationResult<JPPFNodeState>> entry : results.entrySet()) {
InvocationResult<JPPFNodeState> res = entry.getValue();
if (res.isException()) {
// handle the exception ...
} else {
JPPFNodeState state = res.result();
// handle the result ...
}
}
Forwarding JMX notifications
JPPF provides a way to subscribe to notifications from a set of selected nodes, which differs from the one specified in the JMX API. This is due to the fact that the server-side mechanism for the registration of notification listeners is unspecified and thus provides no reliable way of overriding it.
To circumvent this, the notification listener registration is performed via the JMX client wrapper JMXDriverConnectionWrapper:
- to add a notification listener, use
registerForwardingNotificationListener(NodeSelector selector, String mBeanName, NotificationListener listener, NotificationFilter filter, Object handback). This will register a notification listener for the specified MBean on each of the selected nodes. This method returns a listener ID which will be used to remove the notfication listener later on. Thus, the application must be careful to keep track of all registered listener IDs. - to remove a notification listener, use
unregisterForwardingNotificationListener(String listenerID).
The notifications forwarded from the nodes are all wrapped into instances of JPPFNodeForwardingNotification.
This class, which inherits from Notification, provides additional APIs to identify from which node and which MBean the notification was emitted.
The following code sample puts it all together:
JPPFClient client = ...;
AbstractJPPFClientConnection conn = (AbstractJPPFClientConnection) client.getClientConnection();
JMXDriverConnectionWrapper driverJmx = conn.getJmxConnection();
// this selector selects all nodes attached to the driver
NodeSelector selector = new NodeSelector.AllNodes();
// create a JMX notification listener
NotificationListener myListener = new NotificationListener() {
@Override
public void handleNotification(Notification notification, Object handback) {
JPPFNodeForwardingNotification notif = (JPPFNodeForwardingNotification) notification;
System.out.println("received notification from nodeUuid=" + notif.getNodeUuid()
+ ", mBeanName=" + notif.getMBeanName());
// get the actual notification sent by the node
TaskExecutionNotification actualNotif = (TaskExecutionNotification) notif.getNotification();
// handle the notification data ...
}
}
// register the notification listener with the JPPFNodeTaskMonitorMBean on the selected nodes
String listenerID = driverJmx.registerForwardingNotificationListener(
selector, JPPFNodeTaskMonitorMBean.MBEAN_NAME, listener, null, null);
// ... submit a JPPF job ...
// once the job has completed, unregister the notification listener
driverJmx.unregisterForwardingNotificationListener(listenerID);
Found in: jppf-common.jar, jppf-server.jar
-
ClassDescriptionImplementation of the
JPPFNodeForwardingMBeaninterface.Instances of this class represent events emitted each time a JMX notification is received from a node.Registered instances of this class will be notified of JMX notifications received from the nodes.This class implements the logic of registering JMX notification listeners to the nodes and dispatching the received notifications to the client-side JMX listeners.Deprecated.Implementation of theJPPFNodeForwardingMBeaninterface.
NodeForwardinginstead.