FileDocCategorySizeDatePackage
ConnectorPoolMonitoringLevelListener.javaAPI DocGlassfish v2 API12681Fri May 04 22:35:18 BST 2007com.sun.enterprise.resource.monitor

ConnectorPoolMonitoringLevelListener

public class ConnectorPoolMonitoringLevelListener extends Object implements com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener
Provides an implementation of the MonitoringLevelListener interface to receive callbacks from admin regarding change in the monitoring level. Though there are 3 monitoring levels defined by JSR77, we support only 2 levels - OFF and ON (HIGH/LOW). So essentially, HIGH and LOW for us is only ON
author
Aditya Gore
since
s1aspe 8.0

Fields Summary
private com.sun.enterprise.admin.monitor.registry.MonitoringRegistry
registry_
private static final com.sun.enterprise.admin.monitor.registry.MonitoringLevel
OFF
private static final com.sun.enterprise.admin.monitor.registry.MonitoringLevel
HIGH
private static final com.sun.enterprise.admin.monitor.registry.MonitoringLevel
LOW
private static Logger
_logger
Constructors Summary
public ConnectorPoolMonitoringLevelListener()


      
    
Methods Summary
public voidchangeLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to, javax.management.j2ee.statistics.Stats handback)
This is the callback invoked by the MonitoringRegistry on change in monitoring level

param
from - the past level
param
to - the new level
param
handback - the Stats object this listener was registered for
deprecated

public voidchangeLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to, com.sun.enterprise.admin.monitor.registry.MonitoredObjectType type)

        
    	//If we were called, the MonitoredObjectType is definitely
    	//CONNECTOR_CONNECTION_POOL, so we can safely ignore it

        if ( from == to ) {
            //Its a no-op, so return
            return;
        }

        AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
    	        ServerContext ctxt = ApplicationServer.getServerContext();
                if (ctxt != null ) {
                    registry_ = ctxt.getMonitoringRegistry();
                }
                return null;
            }
        });

        if (from == OFF || from == LOW ) {
            if ( to == HIGH ) {
                logFine("Changing level from " + from +"  to HIGH");	
                transitionToHigh();
            }
        }
    
        if (from == HIGH  || from == LOW ) {
            if ( to == OFF ) {
                logFine("Switching level from " + from + " to OFF");
                switchOffMonitoring();
            }
        }

    	if (from == OFF || from == HIGH )  {
	    if ( to == LOW  ) {
		logFine("Changing level from " + from + " to LOW");	
                transitionToLow();
	    }
	}

    
private com.sun.enterprise.PoolManagergetPoolManager()

        return Switch.getSwitch().getPoolManager();
    
private voidlogFine(java.lang.String msg)

        if ( msg != null && _logger.isLoggable( Level.FINE ) ) {
            _logger.fine( msg );
        }
    
public voidsetLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel level)

see
com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener#setLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel)
deprecated

private voidswitchOffMonitoring()

        final ResourcesUtil resUtil = ResourcesUtil.createInstance();
        //deregister stats
        AccessController.doPrivileged( new PrivilegedAction() {
            public Object run() {
                //Unregister all connector connection pools
                Map<ConnectorConnectionPool, MonitorableResourcePool> 
                    pools = resUtil.getPoolMap();
                if (pools == null) {
                    return null;
                }
                        
                for (Map.Entry<ConnectorConnectionPool, MonitorableResourcePool> entry :  pools.entrySet() ) {
                    ConnectorConnectionPool ccp = entry.getKey();
                    MonitorableResourcePool pool = entry.getValue();
                    if (pool != null) {
                        try {
                            registry_.unregisterConnectorConnectionPoolStats(
                                pool.getPoolName(), 
                                resUtil.getAppName(ccp), 
                                resUtil.getRAName(ccp) );
                            getPoolManager().disableMonitoring(
                                pool.getPoolName());
                        } catch( Exception mre ) {
                            _logger.log( Level.INFO, "poolmon.cannot_unreg");
                        }
                    }
                }
                       
                return null;
            }
        });
    
private voidtransitionToHigh()

        final ResourcesUtil resUtil = ResourcesUtil.createInstance();
        AccessController.doPrivileged( new PrivilegedAction() {    
            public Object run() {
                //we should create a new pool object everytime since
                //the stats have to be collected afresh
                Map<ConnectorConnectionPool, MonitorableResourcePool> poolMap
                    = resUtil.getPoolMap();
                if (poolMap == null) {
                    return null;
                }
        
                for (Map.Entry<ConnectorConnectionPool, MonitorableResourcePool> entry :
                        poolMap.entrySet() ) {
                    ConnectorConnectionPool ccp = entry.getKey();
                    MonitorableResourcePool pool = entry.getValue();
                    if ( pool != null ) {
                        try {
                            ConnectorConnectionPoolStatsImpl stats = new 
                                ConnectorConnectionPoolStatsImpl(pool);
                            getPoolManager().setMonitoringEnabledHigh(
                                pool.getPoolName());
                            registry_.registerConnectorConnectionPoolStats(
                                stats, pool.getPoolName(), 
                                resUtil.getAppName(ccp), 
                                resUtil.getRAName(ccp), 
                                null);
                        } catch (Exception mre) {
                            try {
                                _logger.log( Level.WARNING, "poolmon.cannot_reg",
                                    mre.getMessage() );
                                getPoolManager().disableMonitoring(
                                    pool.getPoolName());
                            } catch (Exception ex) {
                                //FIXME: ignore?
                            }
                        }
                    }       
                }
                return null;
            }
        });
    
private voidtransitionToLow()

        final ResourcesUtil resUtil = ResourcesUtil.createInstance();
        AccessController.doPrivileged( new PrivilegedAction() {    
            public Object run() {
                //we should create a new pool object everytime since
                //the stats have to be collected afresh
                Map<ConnectorConnectionPool, MonitorableResourcePool> poolMap
                    = resUtil.getPoolMap();
                if (poolMap == null) {
                    return null;
                }
        
                for (Map.Entry<ConnectorConnectionPool, MonitorableResourcePool> entry :
                        poolMap.entrySet() ) {
                    ConnectorConnectionPool ccp = entry.getKey();
                    MonitorableResourcePool pool = entry.getValue();
                    if ( pool != null ) {
                        try {
                            ConnectorConnectionPoolStatsImpl stats = new 
                                ConnectorConnectionPoolStatsImpl(pool);
                            getPoolManager().setMonitoringEnabledLow(
                                pool.getPoolName());
                            registry_.registerConnectorConnectionPoolStats(
                                stats, pool.getPoolName(), 
                                resUtil.getAppName(ccp), 
                                resUtil.getRAName(ccp), null);
                        } catch (Exception mre) {
                            try {
                                _logger.log( Level.WARNING, "poolmon.cannot_reg",
                                    mre.getMessage() );
                                getPoolManager().disableMonitoring(
                                    pool.getPoolName());
                            } catch (Exception ex) {
                                //FIXME: ignore?
                            }
                        }
                    }       
                }
                return null;
            }
        });