ConnectorPoolMonitoringLevelListenerpublic class ConnectorPoolMonitoringLevelListener extends Object implements com.sun.enterprise.admin.monitor.registry.MonitoringLevelListenerProvides 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 |
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 void | changeLevel(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
| public void | changeLevel(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.PoolManager | getPoolManager()
return Switch.getSwitch().getPoolManager();
| private void | logFine(java.lang.String msg)
if ( msg != null && _logger.isLoggable( Level.FINE ) ) {
_logger.fine( msg );
}
| public void | setLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel level)
| private void | switchOffMonitoring()
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 void | transitionToHigh()
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 void | transitionToLow()
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;
}
});
|
|