FileDocCategorySizeDatePackage
LoadBalancerSupport.javaAPI DocGlassfish v2 API10908Thu Jun 21 08:33:00 BST 2007com.sun.enterprise.management.support

LoadBalancerSupport

public class LoadBalancerSupport extends Object
This class is complicated by out-of-order registration of MBeans. Because LoadBalancerImpl depends on LBConfig, and they might be registered out of order, special care must be taken at startup.

Fields Summary
private final MBeanServer
mMBeanServer
private final com.sun.appserv.management.DomainRoot
mDomainRoot
private final Map
mConfigToLoadBalancers
private final LoadBalancerConfigListener
mConfigListener
private static volatile LoadBalancerSupport
INSTANCE
Constructors Summary
private LoadBalancerSupport(com.sun.appserv.management.DomainRoot domainRoot, MBeanServer mbeanServer)

       // mDomainRoot  = domainRoot;
        mMBeanServer = mbeanServer;
        mDomainRoot = domainRoot;
        mConfigToLoadBalancers =
            Collections.synchronizedMap(new HashMap<ObjectName,ObjectName>());
        
        mConfigListener = new LoadBalancerConfigListener( mMBeanServer );
    
Methods Summary
protected TgetProxy(javax.management.ObjectName objectName, java.lang.Class theClass)

        return getProxyFactory().getProxy( objectName, theClass );
    
protected com.sun.appserv.management.client.ProxyFactorygetProxyFactory()

        return ProxyFactory.getInstance( mMBeanServer );
    
protected voidlogWarning(java.lang.String prefix, java.lang.Exception ex)

        AMXRootLogger.getInstance().warning(prefix + " : " + ex.getMessage());
    
synchronized com.sun.appserv.management.ext.lb.LoadBalancerregisterNewLoadBalancer(javax.management.ObjectName loadBalancerConfigObjectName)
Register a {@link LoadBalancer} MBean corresponding to a newly-registered LoadBalancerConfig MBean. See {@link #unregisterLoadBalancer}.

        //create load balancer runtime mbean
        final ObjectName domainRootObjName = Util.getObjectName( mDomainRoot );
        
        final ObjectNames objectNames = ObjectNames.getInstance(JMX_DOMAIN);
        final String name = loadBalancerConfigObjectName.getKeyProperty( AMX.NAME_KEY );
        final ObjectName loadBalancerObjName = 
            objectNames.buildContaineeObjectName( domainRootObjName, 
                mDomainRoot.getFullType(), LOAD_BALANCER, name);

        final LoadBalancerConfig loadBalancerConfig =
            getProxy( loadBalancerConfigObjectName, LoadBalancerConfig.class);
            
        final LoadBalancerImpl loadBalancerImpl =
            new LoadBalancerImpl(mMBeanServer, loadBalancerConfig);
        LoadBalancer loadBalancerProxy = null;
        try
        {
            final ObjectName actualObjectName = mMBeanServer.registerMBean(
                loadBalancerImpl, loadBalancerObjName).getObjectName();
                
            loadBalancerProxy = getProxy( actualObjectName, LoadBalancer.class);
            mConfigToLoadBalancers.put( loadBalancerConfigObjectName, actualObjectName );
        }
        catch( JMException ex )
        {
            logWarning(
                "LoadBalancerRegistrationListener registerLoadBalancer " +
                "failed. Exception = ", ex);	
        }
        return loadBalancerProxy;
    
public static synchronized com.sun.enterprise.management.support.LoadBalancerSupportstart(javax.management.ObjectName domainRootObjectName, javax.management.MBeanServer server)
Call once and only once.

    
                     
           
    
             
                
    
        if ( INSTANCE != null )
        {
            throw new IllegalStateException();
        }
        
        final DomainRoot domainRoot =
            ProxyFactory.getInstance( server ).getProxy( domainRootObjectName, DomainRoot.class );
        
        INSTANCE = new LoadBalancerSupport( domainRoot, server );
        INSTANCE.mConfigListener.startListening();
        
        //final InitialRegistrationListener initial = new InitialRegistrationListener();
        //initial.startListening();
        
        return INSTANCE;
    
synchronized voidunregisterLoadBalancer(javax.management.ObjectName unregisteredLoadBalancerConfig)
'synchronized' to avoid any register/unregister conditions with rapid registration/unregistration using the same name.

        final ObjectName correspondingLoadBalancerObjectName =
            mConfigToLoadBalancers.remove( unregisteredLoadBalancerConfig );
        
        if ( correspondingLoadBalancerObjectName != null )
        {
            try
            {
            mMBeanServer.unregisterMBean( correspondingLoadBalancerObjectName );
            }
            catch( JMException e )
            {
                // shouldn't happen, but not a problem
            }
        }