FileDocCategorySizeDatePackage
LoadBalancerImpl.javaAPI DocGlassfish v2 API11533Thu Jun 21 08:33:00 BST 2007com.sun.enterprise.management.ext.lb

LoadBalancerImpl

public final class LoadBalancerImpl extends com.sun.enterprise.management.support.AMXImplBase implements com.sun.appserv.management.ext.lb.LoadBalancer
Implmentation class for LoadBalancer AMX MBean
author
Harsha R A
since
Appserver 9.0

Fields Summary
private static final String
COMMA
private static final String
COLON
private static final String
EQUAL
public static final String
NAME_PROP_VALUE
public static final String
LAST_APPLIED_PROPERTY
public static final String
LAST_APPLIED_HASH_PROPERTY
public static final String
LAST_EXPORTED_PROPERTY
public static final String
LOADBALANCER_CONFIG_OBJECT_NAME
public static final String
LBCONFIG_OBJECT_NAME
public static final String
LOADBALANCER_OBJECT_NAME
private static final String
XML_COMMENT_START
private static final String
MD5
private final com.sun.enterprise.server.pluggable.LBFeatureFactory
lbFactory
private final com.sun.appserv.management.config.LoadBalancerConfig
loadBalancerConfig
private final MBeanServerConnection
mServer
Constructors Summary
public LoadBalancerImpl(MBeanServerConnection server, com.sun.appserv.management.config.LoadBalancerConfig loadBalancerConfigIn)


     
          
            
        super( );
        if ( loadBalancerConfigIn == null ) {
            throw new IllegalArgumentException();
        }
        
        mServer            = server;
        loadBalancerConfig = loadBalancerConfigIn;
        
        final PluggableFeatureFactory featureFactory =
                ApplicationServer.getServerContext().getPluggableFeatureFactory();
        
        lbFactory = featureFactory.getLBFeatureFactory();
        if ( lbFactory == null ) {
            throw new IllegalStateException();
        }
    
Methods Summary
public voidapplyLBChanges()
Applies changes in the corresponding configuration to this LB

        final String lbConfigName = loadBalancerConfig.getLbConfigName();

        lbFactory.applyChanges(lbConfigName, getName());
        if(!loadBalancerConfig.existsProperty(LAST_APPLIED_PROPERTY))
            loadBalancerConfig.createProperty(LAST_APPLIED_PROPERTY,String.valueOf(new Date().getTime()));
        else
            loadBalancerConfig.setPropertyValue(LAST_APPLIED_PROPERTY,String.valueOf(new Date().getTime()));
        String digest = getMessageDigest();
        if(!loadBalancerConfig.existsProperty(LAST_APPLIED_HASH_PROPERTY))
            loadBalancerConfig.createProperty(LAST_APPLIED_HASH_PROPERTY,digest);
        else
            loadBalancerConfig.setPropertyValue(LAST_APPLIED_HASH_PROPERTY,digest);
    
private com.sun.appserv.management.config.LBConfiggetLBConfig(java.lang.String lbConfigName)

        ObjectName lbConfigObjName = null;
        try{
            lbConfigObjName =
                    new ObjectName(LBCONFIG_OBJECT_NAME+lbConfigName);
        } catch ( MalformedObjectNameException e ){
            e.printStackTrace();
        }
        LBConfig lbConfig = getProxy(lbConfigObjName, LBConfig.class);
        return lbConfig;
    
public java.util.DategetLastApplied()
Returns the timestamp of the most recent application of referenced LBConfig

return
Date the timestamp when the changes were applied to the load balancer

        final String lbName = getName();
        if(loadBalancerConfig.existsProperty(LAST_APPLIED_PROPERTY))
            return new Date(Long.valueOf(loadBalancerConfig.getPropertyValue(LAST_APPLIED_PROPERTY)));
        return null;
    
public java.lang.StringgetLastAppliedMessageDigest()
method to return the message digest of the load balaner.xml that was last applied

return
String last-applied-digest property of the load balancer from domain.xml

        final String lbName = getName();
        if(loadBalancerConfig.existsProperty(LAST_APPLIED_HASH_PROPERTY))
            return loadBalancerConfig.getPropertyValue(LAST_APPLIED_HASH_PROPERTY);
        return null;
    
public java.util.DategetLastExported()
Returns the timestamp of the most recent export of referenced LBConfig

return
Date timestamp

        final String lbName = getName();
        final String lbConfigName = loadBalancerConfig.getLbConfigName();
        LBConfig lbConfig = getLBConfig(lbConfigName);
        if(lbConfig.existsProperty(LAST_EXPORTED_PROPERTY))
            return new Date(Long.valueOf(lbConfig.getPropertyValue(LAST_EXPORTED_PROPERTY)));
        return null;
    
public java.util.DategetLastResetTime()
Returns the timestamp of the last time the stats on this loadbalancer were reset

        return null;
    
public java.lang.StringgetLoadBalancerXML()
Exports the corresponding LBConfig information and returns the contents as a string.

see
com.sun.appserv.management.config.LBConfig
return
String the loadbalancer.xml as a string

        return getLoadBalancerXML(true);
    
private java.lang.StringgetLoadBalancerXML(boolean updateTimeStamp)

        final String lbName = getName();
        final String lbConfigName = loadBalancerConfig.getLbConfigName();
        final LBConfig lbConfig = getLBConfig(lbConfigName);
        if(updateTimeStamp) {
            if(!lbConfig.existsProperty(LAST_EXPORTED_PROPERTY))
                lbConfig.createProperty(LAST_EXPORTED_PROPERTY,String.valueOf(new Date().getTime()));
            else
                lbConfig.setPropertyValue(LAST_EXPORTED_PROPERTY,String.valueOf(new Date().getTime()));
        }

        return lbFactory.getLoadBalancerXML(lbConfigName,lbName);
                
    
private java.lang.StringgetMessageDigest()

        try {
            String lbxml = getLoadBalancerXML(false).split(XML_COMMENT_START)[0];
            MessageDigest md = MessageDigest.getInstance(MD5);
            md.update(lbxml.getBytes());
            String hash = new BigInteger(md.digest()).toString(16);        
            return hash;
        }catch(NoSuchAlgorithmException e){
            getMBeanLogger().warning(e.getMessage());
            if(getMBeanLogger().isLoggable(Level.FINE))
                e.printStackTrace();            
        }
        return "";
    
public java.lang.StringgetStatus(java.lang.String instanceName)
Returns the uhealthy/healthy/quiesced status for an insatnce load balanced by this load balancer.

        return null;
    
public booleanisApplyChangeRequired()
checks if apply change is required

return
true if there are pending changes for this LB

        boolean isRequired = true;
        try{
        String digest = getMessageDigest();
        String lastDigest = getLastAppliedMessageDigest();
        if(lastDigest!=null)
            isRequired = !digest.equals(lastDigest);
        }catch (Throwable t){
            getMBeanLogger().warning(t.getMessage());
            if(getMBeanLogger().isLoggable(Level.FINE))
                t.printStackTrace();
        }
        return isRequired;
                
    
public voidresetStats()
Reset the monitoring stats on this loadbalancer.

        final String lbName = getName();
        final String lbConfigName = loadBalancerConfig.getLbConfigName();
        lbFactory.resetStats(lbConfigName,lbName);        
    
public booleantestConnection()
Test the LB and Domain Application Server setup

        final String lbName = getName();
        final String lbConfigName = loadBalancerConfig.getLbConfigName();
        return lbFactory.testConnection(lbConfigName,lbName);