LoadBalancerSupportpublic 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 T | getProxy(javax.management.ObjectName objectName, java.lang.Class theClass)
return getProxyFactory().getProxy( objectName, theClass );
| protected com.sun.appserv.management.client.ProxyFactory | getProxyFactory()
return ProxyFactory.getInstance( mMBeanServer );
| protected void | logWarning(java.lang.String prefix, java.lang.Exception ex)
AMXRootLogger.getInstance().warning(prefix + " : " + ex.getMessage());
| synchronized com.sun.appserv.management.ext.lb.LoadBalancer | registerNewLoadBalancer(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.LoadBalancerSupport | start(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 void | unregisterLoadBalancer(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
}
}
|
|