JPPF management and monitoring

From JPPFWiki

Jump to: navigation, search

Contents

Main Page > JPPF management and monitoring

Through its integration with JMX, JPPF now provides an efficient way to monitor and administrate

JPPF driver administration and monitoring

The administration and monitoring features for a JPPF driver are currently accessible from the JPPF administration console (GUI)

JPPF node and task monitoring

New in JPPF 1.0 beta2, it is now possible to receive notifications from the nodes or from tasks being executed.

The information you can get from a node is fixed:

  • host and port of its JMX/RMI connection
  • connection status
  • execution status

The tasks provide more flexibility and enable the developers to send their own notifications, from anywhere in the code of a task.

Monitoring support in the JPPF task API

A new set of methods was added to the JPPFTask class, enabling objects to register listeners on the tasks and receive events from them. These methods are:

 public synchronized void addJPPFTaskListener(JPPFTaskListener listener)
 public synchronized void removeJPPFTaskListener(JPPFTaskListener listener)
 public synchronized void fireNotification(Serializable source)

You will notice that the method fireNotification(Serializable source) takes a serializable object as its input. This constraint answers the need to send the notifications to any JMX client, local or remote, that connects to the node's JMX server.

So how is this done? In fact, the node registers a listener to every task before it starts executing, and unregisters it after it is executed. The goal of this listener is to propagate notifications to the node's JMX MBean, so it becomes available from the monitoring interface. In effect, all you have to do, to send a notification on the status of a task, is to invoke the fireNotification() method. The object that you pass a parameter can be any kind of object, as long as it is serializable.

A new code sample is available to demonstrate this.


Note: if you use custom objects for tasks notifications, you must ensure that the corresponding classes are in the JPPF client or console classpath


Administration support in the JPPF task API

JPPF now supports the following functionalities:

  • task timeout: tasks are canceled after a given amount of time or at a specific date/time

This functionality is supported through the following APIs in JPPFTask:

 public long getTimeout()
 public void setTimeout(long timeout)
 public String getTimeoutDate()
 public SimpleDateFormat getTimeoutDateFormat()
 public void setTimeoutDate(String timeoutDate, SimpleDateFormat timeoutDateFormat)
 public void onTimeout()

Method onTimeout() is a callback invoked when a task times out, developers can override it to perform specific processing when this happens.

  • task cancellation and restart

Since a node can be multithreaded and execute multiple tasks concurrently, it is necessary to identify a task that we want to cancel. To this effect, a new attribute, id, of type String, has been added to the tasks. It is available through its public accessors:

 public String getId()
 public void setId(String id)

Callbacks have also been added to enable a custom processing when a task is canceled or restarted:

 public void onCancel()
 public void onRestart()

For more details, please take a look at the API documentation for the class JPPFTask. api/org/jppf/server/protocol/JPPFTask.html

Visualization in the monitoring console

The administration and monitoring console takes full advantage of this capability. A picture will tell more than a long explanation:

nodeMonitoring.gif

Here the console displays a tree with all the servers it is attached to, along with the nodes attached to each server.

Task administration from the console

By right-clicking on a node in the tree view, you will pop-up a menu that will allow you to cancel or restart tasks that are currently running:

cancelTask.gif restartTask.gif

Node-level administration and monitoring from the console

The right-click pop-up menu will also present you with the option to visualize the node's environment, and gives you the possibility to manually adjust its number of processing threads:

NodeAdminPopup.gif NodeUpdateThreads.gif NodeInformation.gif

Programmatic access

  • To connect to the JMX server of a JPPF driver from a client:
 JPPFClient jppfClient = new JPPFClient();
 // ... some code ...
 // get a handle to the driver connection
 JPPFClientConnectionImpl c = (JPPFClientConnectionImpl) jppfClient.getClientConnection("driver1");
 // query the driver's JMX server for the attached nodes
 Collection<NodeManagementInfo> nodeList = c.getNodeManagementInfo();
  • To connect to the JMX servers of the attached nodes:
 // establish the connection to every node
 final List<JMXNodeConnectionWrapper> jmxConnections = new ArrayList<JMXNodeConnectionWrapper>();
 for (NodeManagementInfo info: nodeList)
 {
   // obtain a wrapper around the JMX connection
   JMXNodeConnectionWrapper jmxClient =
     new JMXNodeConnectionWrapper(info.getHost(), info.getPort());
   // perform the actual connection to the JMX server
   jmxClient.connect();
   jmxConnections.add(jmxClient);
 }

Notice here that you can also directly connect to the node's JMX server, if you know the RMI host and port it uses, without having to lookup that information form the JPPF driver.

  • To setup an automatic refresh of the monitored data on each node:
 // create a task that will periodically query each node for the latest task notification
 TimerTask timerTask = new TimerTask()
 {
   public void run()
   {
     for (JMXConnectionWrapper jmxClient: jmxConnections)
     {
       try
       {
         String mbeanName = JPPFAdminMBean.NODE_MBEAN_NAME;
         // invoke the method "notification" on the node's MBean
         TaskNotification notif = jmxClient.notification();
         // display the resulting notification
         System.out.println("Monitored node " + jmxClient.getId() +
           " received notification: " + notif);
       }
       catch(Exception e)
       {
         e.printStackTrace()
       }
     }
   }
 };
 Timer timer = new Timer("JMX notifications timer");
 // schedule the task with a 1 second delay between executions
 timer.schedule(timerTask, 100L, 1000L);
  • To cancel a running task
   // obtain a wrapper around the JMX connection
   JMXNodeConnectionWrapper jmxClient = new JMXNodeConnectionWrapper(myHost, myPort);
   // perform the actual connection to the JMX server
   jmxClient.connect();
   // cancel the task with the specified id
   jmxClient.cancelTask(taskId);
  • To restart a running task
   // obtain a wrapper around the JMX connection
   JMXNodeConnectionWrapper jmxClient = new JMXNodeConnectionWrapper(myHost, myPort);
   // perform the actual connection to the JMX server
   jmxClient.connect();
   // cancel the task with the specified id
   jmxClient.restartTask(taskId);
  • Getting and setting the number of processing threads
   // obtain a wrapper around the JMX connection
   JMXNodeConnectionWrapper jmxClient = new JMXNodeConnectionWrapper(myHost, myPort);
   jmxClient.connect();
   // get the node's number of processing threads
   int nbThreads = jmxClient.state().getThreadPoolSize();
   // update the number of threads
   if (nbThreads > 2) jmxClient.updateThreadPoolSize(2);
  • Obtaining information on the node's environment
   JMXNodeConnectionWrapper jmxClient = new JMXNodeConnectionWrapper(myHost, myPort);
   jmxClient.connect();
   // Get detailed information about the node's environment
   JPPFSystemInformation info = jmxClient.systemInformation();


Personal tools