FileDocCategorySizeDatePackage
GrizzlyConfig.javaAPI DocGlassfish v2 API8725Fri May 04 22:36:04 BST 2007com.sun.enterprise.web.connector.extension

GrizzlyConfig

public class GrizzlyConfig extends Object implements com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener
This class track monitoring or Grizzly, using JMX to invoke Grizzly main classes.
author
Jeanfrancois Arcand

Fields Summary
private static final Logger
logger
private MBeanServer
mBeanServer
The mbean server used to lookup Grizzly.
private boolean
isMonitoringEnabled
Is monitoring already started.
private String
domain
The JMX domain
private int
port
The port used to lookup Grizzly's Selector
private static ArrayList
grizzlyConfigList
The list of instance created. This list is not thread-safe.
Constructors Summary
public GrizzlyConfig(String domain, int port)
Creates the monitoring helper.

    

    // --------------------------------------------------------------- //
   
    
             
        
        this.domain = domain;
        this.port = port;
        
        // get an instance of the MBeanServer
        ArrayList servers = MBeanServerFactory.findMBeanServer(null);
        if(!servers.isEmpty())
            mBeanServer = (MBeanServer)servers.get(0);
        else
            mBeanServer = MBeanServerFactory.createMBeanServer();
        
        grizzlyConfigList.add(this);
    
Methods Summary
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 (MonitoredObjectType.HTTP_LISTENER.equals(type)) {
            if(MonitoringLevel.OFF.equals(to)) {
                isMonitoringEnabled = false;
            } else {
                isMonitoringEnabled = true;
            }
        }            
        String methodToInvoke = isMonitoringEnabled ? "enableMonitoring" :
            "disabledMonitoring";
        invokeGrizzly(methodToInvoke);        
    
public voidchangeLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel from, com.sun.enterprise.admin.monitor.registry.MonitoringLevel to, javax.management.j2ee.statistics.Stats handback)

        // deprecated, ignore
    
public static java.util.ArrayListgetGrizzlyConfigInstances()
Return the list of all instance of this class.

        return grizzlyConfigList;
    
public intgetPort()
Return the port this configuration belongs.

        return port;
    
public voidinitConfig()

        initMonitoringLevel();
    
private voidinitMonitoringLevel()

        try{
            Config cfg = ServerBeansFactory
                .getConfigBean(
                    WebContainer.getInstance().getServerContext().getConfigContext());

            MonitoringLevel monitoringLevel = MonitoringLevel.OFF; // default per DTD

            if (cfg.getMonitoringService() != null) {
                ModuleMonitoringLevels levels =
                    cfg.getMonitoringService().getModuleMonitoringLevels();
                if (levels != null) {
                    monitoringLevel = MonitoringLevel.instance(
                                                    levels.getHttpService());
                }
            }
        
            if(MonitoringLevel.OFF.equals(monitoringLevel)) {
                isMonitoringEnabled = false;
            } else {
                isMonitoringEnabled = true;
            } 
            
            String methodToInvoke = isMonitoringEnabled ? "enableMonitoring" :
                "disableMonitoring";
            invokeGrizzly(methodToInvoke);
        } catch (Exception ex) {
            logger.log(Level.WARNING,
                "selectorThread.initMonitoringException",
                 new Object[]{new Integer(port),ex});
        }
    
protected final voidinvokeGrizzly(java.lang.String methodToInvoke, java.lang.Object[] objects, java.lang.String[] signature)

  
        try{
            String onStr = domain + ":type=Selector,name=http" + port;
            ObjectName objectName = new ObjectName(onStr);
            mBeanServer.invoke(objectName,methodToInvoke,objects,signature);
        } catch ( Exception ex ){
            throw new RuntimeException(ex);
        }
    
protected final voidinvokeGrizzly(java.lang.String methodToInvoke)

  
        invokeGrizzly(methodToInvoke,null,null);
    
public voidregisterMonitoringLevelEvents()

        MonitoringRegistry monitoringRegistry = 
            WebContainer.getInstance().getServerContext().getMonitoringRegistry();
        monitoringRegistry.registerMonitoringLevelListener(
            this, MonitoredObjectType.HTTP_LISTENER);
    
public final voidsetEnableCallFlow(boolean enableCallFlow)
Enable CallFlow gathering mechanism.

        String methodToInvoke = enableCallFlow ? "enableMonitoring" :
            "disabledMonitoring";
        invokeGrizzly(methodToInvoke);        
    
public voidsetLevel(com.sun.enterprise.admin.monitor.registry.MonitoringLevel level)

        // deprecated, ignore
    
public voidunregisterMonitoringLevelEvents()

        MonitoringRegistry monitoringRegistry =
            WebContainer.getInstance().getServerContext().getMonitoringRegistry();
        monitoringRegistry.unregisterMonitoringLevelListener(this);