FileDocCategorySizeDatePackage
JVMChangeHandler.javaAPI DocGlassfish v2 API7590Fri May 04 22:24:20 BST 2007com.sun.enterprise.admin.monitor.registry.spi.reconfig

JVMChangeHandler

public class JVMChangeHandler extends Object implements ChangeHandler
Provides for dynamic reconfiguration of jvm. This class decides the actions to take when there are changes to the monitoring level through administrative interfaces.
since
S1AS8.1

Fields Summary
private final ChangeHandler
successor
private final com.sun.enterprise.admin.monitor.registry.spi.ValueListMap
listeners
private static final Logger
logger
Constructors Summary
JVMChangeHandler(ChangeHandler successor, com.sun.enterprise.admin.monitor.registry.spi.ValueListMap listeners)


	    
		this.successor	= successor;
		this.listeners	= listeners;
	
Methods Summary
public voidhandleChange(com.sun.enterprise.admin.monitor.registry.MonitoredObjectType t, com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to)

		if (isJvmType(t)) {
			handleChange(from, to, t);
		}
		else {
			successor.handleChange(t, from, to);
		}
	
private voidhandleChange(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to, com.sun.enterprise.admin.monitor.registry.MonitoredObjectType t)

		if (off2Low(from, to) || off2High(from, to)) {
			boolean threadInfo = false;
			notifyListeners(from, to, t);
			// register the threadinfo mbeans only if the "to" level is HIGH
			if(to == MonitoringLevel.HIGH)
				threadInfo = true;
			registerMBeans(threadInfo);
		}
		if (low2Off(from, to) || high2Off(from, to)) {
			boolean threadInfo = false;
			// need to include the threadinfo mbeans, if the "from" level is HIGH
			if(from == MonitoringLevel.HIGH)
				threadInfo = true;
			unregisterMBeans(threadInfo);
			notifyListeners(from, to, t);
		}
		if (low2High(from, to)) {
			// register the threadinfo mbeans
			notifyListeners(from, to, t);
			registerThreadInfoMBeans();
		}
		if (high2Low(from, to)) {
			// unregister the threadinfo mbeans
			unregisterThreadInfoMBeans();
			notifyListeners(from, to, t);
		}
		
	
private booleanhigh2Low(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to)

		return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.LOW );
	
private booleanhigh2Off(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to)

 
		return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.OFF );
	
private booleanisJvmType(com.sun.enterprise.admin.monitor.registry.MonitoredObjectType t)

        return (t == MonitoredObjectType.JVM);
    
private booleanlow2High(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to)

 
		return ( from == MonitoringLevel.LOW && to == MonitoringLevel.HIGH);
	
private booleanlow2Off(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to)

 
		return ( from == MonitoringLevel.LOW && to == MonitoringLevel.OFF);
	
private voidnotifyListeners(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to, com.sun.enterprise.admin.monitor.registry.MonitoredObjectType t)

		logger.finer("DynamicReconfigurator: Now notifying the listeners for jvm stats --- from = " + from.toString() + " to = " + to.toString());
		final Map l = (Map)listeners.get(t); // map of listeners;
		if (l == null)
			return; //do nothing
		final Iterator it = l.keySet().iterator();
		while (it.hasNext()) {
			final MonitoringLevelListener ml = (MonitoringLevelListener)it.next();
			ml.changeLevel(from, to, t);
		}
	
private booleanoff2High(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to)

 
		return ( from == MonitoringLevel.OFF && to == MonitoringLevel.HIGH );
	
private booleanoff2Low(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to)

 
		return ( from == MonitoringLevel.OFF && to == MonitoringLevel.LOW );
	
private voidregisterMBeans(boolean threadInfo)

		final MonitoringRegistrationHelper registryImpl	= 
			(MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance();
		
		final Iterator iter = registryImpl.getJvmNodes(threadInfo).iterator();
		while (iter.hasNext()) {
			final StatsHolder c = (StatsHolder) iter.next();
			c.registerMBean();
			logger.finer("DynamicReconfigurator: Now Registering MBean for --- " + c.getName());
		}
	
private voidregisterThreadInfoMBeans()

		final MonitoringRegistrationHelper registryImpl	= 
			(MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance();

		final Iterator iter = registryImpl.getJvmThreadInfoNodes().iterator();
		while (iter.hasNext()) {
			final StatsHolder c = (StatsHolder) iter.next();
			c.registerMBean();
			logger.finer("DynamicReconfigurator: Now Registering MBean for --- " + c.getName());
		}
	
private voidunregisterMBeans(boolean threadInfo)

		final MonitoringRegistrationHelper registryImpl	= 
			(MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance();

		final Iterator iter = registryImpl.getJvmNodes(threadInfo).iterator();
		while (iter.hasNext()) {
			final StatsHolder c = (StatsHolder) iter.next();
			c.unregisterMBean();
			logger.finer("DynamicReconfigurator: Now UnRegistering MBean for --- " + c.getName());
		}
	
private voidunregisterThreadInfoMBeans()

		final MonitoringRegistrationHelper registryImpl	= 
			(MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance();

		final Iterator iter = registryImpl.getJvmThreadInfoNodes().iterator();
		while (iter.hasNext()) {
			final StatsHolder c = (StatsHolder) iter.next();
			c.unregisterMBean();
			logger.finer("DynamicReconfigurator: Now UnRegistering MBean for --- " + c.getName());
		}