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

The open source
grid computing

 Home   About   Features   Download   Documentation   On Github   Forums 
June 04, 2023, 08:04:11 PM *
Please login or register.

Login with username, password and session length
Advanced search  
News: New users, please read this message. Thank you!
  Home Help Search Login Register  
Pages: [1]   Go Down

Author Topic: [5.0.3] Receive notifications from different drivers  (Read 1743 times)


  • JPPF Padawan
  • *
  • Posts: 4
[5.0.3] Receive notifications from different drivers
« on: December 14, 2015, 12:27:05 PM »


I am using JPPF in Version 5.0.3. to scale an application to a few virtual machines.

My setup is just the following:

Driver 1: 7 Nodes
Driver 2: 7 Nodes
Driver 3: 7 Nodes

The drivers are configured to work as peers. Each node executes one task, which will take a lot of time until it completes.
For this reason I've registred a ClientTaskListener on my executing client assuming, that it will catch all notifications from every node.

However it seems, that only the notifications from Driver 1 are retrieved on my client.

The relevant piece of code should be this one:

Code: [Select]
    try (JPPFClient jppfClient = new JPPFClient()) {
            JMXDriverConnectionWrapper jmxDriver = waitForJMXConnection(jppfClient);

            String listenerID = registerJMXListener(jmxDriver);



        } catch (Exception e) {
            throw new RuntimeException("Starting failed", e);

    private String registerJMXListener(JMXDriverConnectionWrapper jmxDriver) throws Exception {
        // this selector selects all nodes attached to the driver
        NodeSelector selector = new AllNodesSelector();
        // create a JMX notification listener
        NotificationListener clientTaskListener = new ClientTaskListener(clientTaskListenerHandler);
        // register the notification listener with the JPPFNodeTaskMonitorMBean
        // on the selected nodes
        return jmxDriver.registerForwardingNotificationListener(
                selector, JPPFNodeTaskMonitorMBean.MBEAN_NAME, clientTaskListener, null, null);

    private JMXDriverConnectionWrapper waitForJMXConnection(JPPFClient jppfClient) throws InterruptedException {
        // wait until a JMX connection to the driver is established
        while (!jppfClient.hasAvailableConnection()) {

        JMXDriverConnectionWrapper jmxDriver;
        while ((jmxDriver = jppfClient.getClientConnection().getConnectionPool().getJmxConnection()) == null) {

        while (!jmxDriver.isConnected()) {
        return jmxDriver;

    private void sleep() throws InterruptedException {

How can I achieve, that notifications from all nodes (even if they are connected via Driver 2 or Driver 3) are received by my client?

//EDIT: Currently i manually connect to each driver to register my client task listener. Is this the intended way or is there any possibility to do this automatically?
Thanks in advance,
« Last Edit: December 14, 2015, 05:49:34 PM by rzo »


  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 2272
    • JPPF Web site
Re: [5.0.3] Receive notifications from different drivers
« Reply #1 on: December 14, 2015, 08:52:16 PM »


The easiest way to monitor a multi-driver topology is to use the dedicated grid topology monitoring API. The idea is to build a TopologyManager based on your JPPF client, and register a TopologyListener that will itself register a ClientTaskListener with each new driver detected in the topology. The code would look like this:

Code: [Select]
public static void main(String... args) {
  try (JPPFClient client = new JPPFClient()) {
    // a map of drivers to registered listener id
    final Map<TopologyDriver, String> listenerMap = new ConcurrentHashMap<>();
    final ClientTaskListener clientTaskListener = new ClientTaskListener();

    // register a topology event listener that registers a notification listener for each new driver
    TopologyManager manager = new TopologyManager(client, new TopologyListenerAdapter() {
      public void driverAdded(TopologyEvent event) {
        // get the new driver and its jmx connection
        TopologyDriver driver = event.getDriver();
        JMXDriverConnectionWrapper jmxDriver = driver.getJmx();
        try {
          String listenerId = jmxDriver.registerForwardingNotificationListener(
            // we use the driver as handback parameter, so we can identify from which driver notifications are sent
            NodeSelector.ALL_NODES, JPPFNodeTaskMonitorMBean.MBEAN_NAME, clientTaskListener, null, driver);
          // store the listener id, so we can unregister it later
          listenerMap.put(driver, listenerId);
        } catch(Exception e) {

    // execute a job

    // unregister all listeners
    for (Map.Entry<TopologyDriver, String> entry: listenerMap.entrySet()) {
      JMXDriverConnectionWrapper jmxDriver = entry.getKey().getJmx();
  } catch (Exception e) {

public static class ClientTaskListener implements NotificationListener {
  public void handleNotification(Notification notification, Object handback) {
    // handback parameter identifies the driver from which the notification is issued
    TopologyDriver driver = (TopologyDriver) handback;
    // ... process the notification

As you can see, this code has many similarities with the code you posted, the main difference being that it will register a listener for each and every driver discovered by the client.

Another approach could be to use the connection pools API, however it will be less easy, especially with JPPF 5.0.x which doesn't have the connection pool events (this feature came in v5.1).



  • JPPF Padawan
  • *
  • Posts: 4
Re: [5.0.3] Receive notifications from different drivers
« Reply #2 on: December 15, 2015, 12:25:02 PM »


thanks for your detailed answer regarding the grid topology monitoring AP. It seems, that it will do exactly the thing, which I need :)

Will go for your suggested approach. Thanks!

Pages: [1]   Go Up
JPPF Powered by SMF 2.0 RC5 | SMF © 2006–2011, Simple Machines LLC Get JPPF at Fast, secure and Free Open Source software downloads