Thread: [Batchserver-cvs] batchserver/src/org/jmonks/batchserver/framework/management JobNotification.java,N
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-04-05 22:22:54
|
Update of /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/management In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25437 Modified Files: JobManagementClient.java JobManager.java Added Files: JobNotification.java Log Message: no message Index: JobManagementClient.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/management/JobManagementClient.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JobManagementClient.java 5 Apr 2006 20:54:45 -0000 1.1 --- JobManagementClient.java 5 Apr 2006 22:22:48 -0000 1.2 *************** *** 21,26 **** --- 21,28 ---- import javax.management.MBeanServerInvocationHandler; import javax.management.MalformedObjectNameException; + import javax.management.Notification; import javax.management.NotificationListener; import javax.management.ObjectName; + import javax.management.remote.JMXConnectionNotification; import javax.management.remote.JMXConnector; import org.apache.log4j.Logger; *************** *** 92,97 **** logger.info("New job has been found in the lookup = " + jobName); JMXConnector jmxConnector=this.jobConnectorHelper.createConnector(jobName); ! this.connectorMap.put(jobName, jmxConnector); ! logger.debug("Successfully added the job to connection map = " + jobName); } } --- 94,108 ---- logger.info("New job has been found in the lookup = " + jobName); JMXConnector jmxConnector=this.jobConnectorHelper.createConnector(jobName); ! if(jmxConnector==null) ! { ! logger.error("Unable to get the jmx connector for the job name = " + jobName); ! } ! else ! { ! JMXConnectionListener connectorListener=new JMXConnectionListener(jobName); ! jmxConnector.addConnectionNotificationListener(connectorListener, null, this); ! this.connectorMap.put(jobName, jmxConnector); ! logger.info("Successfully added the job to connection map = " + jobName); ! } } } *************** *** 338,340 **** --- 349,396 ---- return unregistered; } + + /** + * Notification listener listens for the jmx connector close notifications. + * This is to clear the entries from the connector map as soon as the connection + * has been closed. New listener will be created for each jmx conector. + * + * @author Suresh Pragada + * @version 1.0 + * @since 1.0 + */ + private class JMXConnectionListener implements NotificationListener + { + /** + * Name of the job this listener is associated with. + */ + private String jobName; + + /** + * Initializes with the job name. + */ + private JMXConnectionListener(String jobName) + { + if(jobName==null) + throw new IllegalArgumentException("job name cannot be null to create jmx connection listener."); + this.jobName=jobName; + } + + /** + * Listens for the connector closed notifications and removes the job name + * entry from the connector map. + */ + public void handleNotification(Notification notification, Object obj) + { + if(JMXConnectionNotification.CLOSED.equalsIgnoreCase(notification.getType())) + { + logger.info("jmx connector has been closed for the job name = " + jobName); + connectorMap.remove(jobName); + } + else + { + logger.trace("Received notification from jmx connector. But, no " + + "action has been taken. = " + jobName + " Notification info = " + notification); + } + } + } } Index: JobManager.java =================================================================== RCS file: /cvsroot/batchserver/batchserver/src/org/jmonks/batchserver/framework/management/JobManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JobManager.java 28 Mar 2006 04:55:18 -0000 1.1 --- JobManager.java 5 Apr 2006 22:22:48 -0000 1.2 *************** *** 11,14 **** --- 11,15 ---- package org.jmonks.batchserver.framework.management; + import javax.management.NotificationBroadcasterSupport; import org.apache.log4j.Level; import org.jmonks.batchserver.framework.controller.JobController; *************** *** 22,26 **** * @since 1.0 */ ! public class JobManager implements JobManagerMBean { private JobManagerMBean jobManager=null; --- 23,28 ---- * @since 1.0 */ ! public class JobManager extends NotificationBroadcasterSupport ! implements JobManagerMBean { private JobManagerMBean jobManager=null; --- NEW FILE: JobNotification.java --- /* * JobNotification.java * * Created on April 5, 2006, 5:08 PM * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */ package org.jmonks.batchserver.framework.management; import java.util.Calendar; import javax.management.Notification; /** * Notification to send the specified job information and define the various * notification types. * * @author Suresh Pragada * @version 1.0 * @since 1.0 */ public class JobNotification extends Notification { /** * Name of the job this notification belongs to. */ private String jobName=null; /** * Used to generate the sequence number. */ private static int sequence=1; /** * Notification type specifies that the job got finished. */ public static final String JOB_FINISHED = "job.status.finished"; /** * Creates a new instance of JobNotification */ public JobNotification(String jobName,String type,Object source,String message) { super(type,source,JobNotification.sequence++,Calendar.getInstance().getTimeInMillis(),message); if(jobName==null) throw new IllegalArgumentException("job name cannot be null to create the job notification."); this.jobName=jobName; } /** * Gets the job name; */ public String getJobName() { return this.jobName; } /** * <p> * Returns the string representation of JobNotification class in the format * <br> {JobNotification [jobName = value] [rest = value] } * </p> * * @return Returns the string representation of JobNotification. */ public String toString() { StringBuffer stringValue=new StringBuffer("{JobNotification "); stringValue.append("[jobName = " + this.jobName + "]"); stringValue.append("[rest = " + super.toString() + "]"); stringValue.append("}"); return stringValue.toString(); } } |