FileDocCategorySizeDatePackage
FlushConfigHook.javaAPI DocGlassfish v2 API15715Fri May 04 22:33:48 BST 2007com.sun.enterprise.admin.server.core.jmx

FlushConfigHook

public class FlushConfigHook extends Object implements com.sun.enterprise.interceptor.DynamicInterceptorHook
Checks for certain invocations that require flusing the config, and does so if needed.

Fields Summary
private static final Logger
sLogger
private MBeanServer
mSuppliedMBeanServer
private MBeanServer
mDelegateMBeanServer
private com.sun.enterprise.admin.AdminContext
mAdminContext
private com.sun.enterprise.admin.server.core.AdminNotificationHelper
mAdminNotificationHelper
private com.sun.appserv.management.helper.AMXDebugHelper
mDebug
static final boolean
USE_OLD_CONFIG_INTERCEPTOR
static final boolean
EVENT_STACK_ISNT_POINTLESS
private static final boolean
ENABLED
private static InheritableThreadLocal
sDepth
private static final Integer
INTEGER_0
private static final Integer
INTEGER_1
private static boolean
LOG_CONFIG_CHANGES
Constructors Summary
public FlushConfigHook(com.sun.enterprise.admin.AdminContext adminContext)

    
        
        
    
        mDebug  = new AMXDebugHelper( "__FlushConfigHook__" );
        mSuppliedMBeanServer    = null;
        mDelegateMBeanServer    = null;
        
        mAdminContext   = adminContext;
        mAdminNotificationHelper = new AdminNotificationHelper( mAdminContext );
        //mLogger = LogDomains.getLogger(AdminConstants.kLoggerName);
        
        mDebug.setEchoToStdOut( false );
        debug( "FlushConfigHook created OK" );
    
Methods Summary
private voidcheckDepth(java.lang.Integer startDepthInteger, com.sun.enterprise.admin.event.EventStack eventStack, boolean success)

        setDepth( startDepthInteger );
        if ( startDepthInteger.intValue() == 0 && success )
        {
            final ConfigContext configContext = getAdminContext().getAdminConfigContext();
            final boolean   needFlush   = configContext.isChanged();
            if ( needFlush )
            {
                debug( "FlushConfigHook.checkDepth(): CHANGED, need flush"); 
                dumpEventStack( eventStack );
                
                debug( "FlushConfigHook.checkDepth: Config has changed, flushing..." );
                try
                {
                    configContext.flush();
                }
                catch( ConfigException e )
                {
                    throw new ReflectionException( e );
                }
                debug( "FlushConfigHook.checkDepth: done flushing changed config, sending Notification" );
                
                // NOTE: this uses the ThreadLocal EventStack from the EventContext set set earlie
                if ( EVENT_STACK_ISNT_POINTLESS )
                {
                    getAdminNotificationHelper().sendNotification();
                    debug( "FlushConfigHook.checkDepth: sending Notification of changed config" );
                }
            }
            else
            {
                debug( "FlushConfigHook.checkDepth(): unchanged, no flush needed"); 
            }
        }
    
private voiddebug(java.lang.Object args)

        if ( mDebug.getDebug() )
        {
            mDebug.println( args );
        }
    
private voiddumpEventStack(com.sun.enterprise.admin.event.EventStack eventStack)

    
         
        
    
        if ( LOG_CONFIG_CHANGES )
        {
            final List<ConfigChange> changes = TypeCast.asList( eventStack.getConfigChangeList() );
            String msg  = "CONFIG CHANGES: " + changes.size() + ": \n{";
            
            for ( final com.sun.enterprise.config.ConfigChange configChange : changes )
            {
                msg += configChange.getConfigChangeType() + "=" + configChange.getName() + ": " +
                        configChange.getXPath();
            }
            msg = msg + "}";
            debug( msg );
        }
    
public com.sun.enterprise.admin.AdminContextgetAdminContext()

        return mAdminContext;
    
private com.sun.enterprise.admin.server.core.AdminNotificationHelpergetAdminNotificationHelper()

        return mAdminNotificationHelper;
    
public java.lang.ObjectgetAttribute(javax.management.ObjectName objectName, java.lang.String attrName)

        final Object result = mDelegateMBeanServer.getAttribute( objectName, attrName );
        
        return result; 
    
public javax.management.AttributeListgetAttributes(javax.management.ObjectName objectName, java.lang.String[] attrNames)

        final AttributeList result = mDelegateMBeanServer.getAttributes( objectName, attrNames );
        
        return result;
    
public java.lang.ClassLoadergetClassLoader(javax.management.ObjectName objectName)

        return mDelegateMBeanServer.getClassLoader( objectName );
    
public java.lang.ClassLoadergetClassLoaderFor(javax.management.ObjectName objectName)

        return mDelegateMBeanServer.getClassLoaderFor( objectName );
    
private static java.lang.IntegergetDepth()

           return (Integer)sDepth.get(); 
public javax.management.MBeanInfogetMBeanInfo(javax.management.ObjectName objectName)

        return mDelegateMBeanServer.getMBeanInfo( objectName );
    
public java.lang.Objectinvoke(javax.management.ObjectName objectName, java.lang.String operationName, java.lang.Object[] params, java.lang.String[] signature)

        Object  result  = null;
        
        debug( "FlushConfigHook.invoke(): ", objectName, ".", operationName, "{", params, "}", "{", signature, "}" );
        
        if ( USE_OLD_CONFIG_INTERCEPTOR )
        {
            result = mDelegateMBeanServer.invoke( objectName, operationName, params, signature );
        }
        else
        {
            if ( isRelevantInvoke( objectName,  operationName ) )
            {
                debug( "FlushConfigHook.invoke: ", operationName, "() START" );
                            
                final Integer startDepthInteger   = getDepth();
                final int startDepth = startDepthInteger.intValue();
                setDepth( startDepth == 0 ? INTEGER_1 : new Integer( startDepth + 1 ) );
                final EventStack eventStack    = setupEventStack( startDepthInteger );
                
                boolean success = false;
                try
                {
                    debug( "FlushConfigHook.invoke: ", operationName, "(): NEW EventStack");
                    result = mDelegateMBeanServer.invoke( objectName, operationName, params, signature );
                    success = true;
                }
                finally
                {
                    checkDepth( startDepthInteger, eventStack, success );
                }
            }
            else
            {
                result = mSuppliedMBeanServer.invoke( objectName, operationName, params, signature );
            }
        }
        
        debug( "FlushConfigHook.invoke: ", objectName, operationName, "() DONE" );

        return result;
    
private final booleanisRelevantInvoke(javax.management.ObjectName objectName, java.lang.String operationName)

    
          
           
    
        boolean   relevant    = false;
        
        final String domain = objectName.getDomain();
        if ( ENABLED && domain.equals( "com.sun.appserv" ) )
        {
            if ( "config".equals( objectName.getKeyProperty( "category" ) ) ||
                "server-instance".equals( objectName.getKeyProperty( "type" ) ) )
            {
                relevant    = true;
                
                // common cases, covers probably 90%
                if (    operationName.startsWith( "get " ) ||
                        operationName.startsWith( "is " ) ||
                        operationName.startsWith( "list" ) )
                {
                    relevant    = false;
                }
            }
        }
        return relevant;
    
public voidsetAttribute(javax.management.ObjectName objectName, javax.management.Attribute attribute)

        debug( "FlushConfigHook.setAttribute(): ", objectName, ", ", attribute.getName(), "=", attribute.getValue() );
        
        if ( USE_OLD_CONFIG_INTERCEPTOR )
        {
            mDelegateMBeanServer.setAttribute( objectName, attribute );
        }
        else
        {
            final Integer startDepthInteger   = getDepth();
            final int startDepth = startDepthInteger.intValue();
            setDepth( startDepth == 0 ? INTEGER_1 : new Integer( startDepth + 1 ) );
            final EventStack eventStack    = setupEventStack( startDepthInteger );
            boolean success = false;
            try
            {
                mDelegateMBeanServer.setAttribute( objectName, attribute );
                success = true;
            }
            finally
            {
                checkDepth( startDepthInteger, eventStack, success );
            }
        }
    
public javax.management.AttributeListsetAttributes(javax.management.ObjectName objectName, javax.management.AttributeList attributeList)

        debug( "FlushConfigHook.setAttributes(): ", objectName, ", ", attributeList);
        
         AttributeList result    = null;
            
        if ( USE_OLD_CONFIG_INTERCEPTOR )
        {
            result  = mDelegateMBeanServer.setAttributes( objectName, attributeList );
        }
        else
        {
            final Integer startDepthInteger   = getDepth();
            final int startDepth = startDepthInteger.intValue();
            setDepth( startDepth == 0 ? INTEGER_1 : new Integer( startDepth + 1 ) );
            final EventStack eventStack    = setupEventStack( startDepthInteger );
            boolean success = false;
            try
            {
                result  = mDelegateMBeanServer.setAttributes( objectName, attributeList );
                success = true;
            }
            finally
            {
                checkDepth( startDepthInteger, eventStack, success );
            }
        }
        return result;
    
public voidsetDelegateMBeanServer(javax.management.MBeanServer mbs)

        if ( mbs == null )
        {
            throw new IllegalArgumentException();
        }
        if ( mSuppliedMBeanServer != null )
        {
            throw new IllegalArgumentException( "already have an MBeanServer" );
        }
        
        mSuppliedMBeanServer    = mbs;
        
        if ( USE_OLD_CONFIG_INTERCEPTOR )
        {
            debug( "FlushConfigHook.setDelegateMBeanServer(): instantiating ConfigInterceptor" );
            final ConfigInterceptor configInterceptor = new ConfigInterceptor( mAdminContext );
            mDelegateMBeanServer = (MBeanServer)com.sun.enterprise.admin.util.proxy.ProxyFactory.createProxy(
                        MBeanServer.class, mSuppliedMBeanServer,
                        configInterceptor );
            debug( "FlushConfigHook.setDelegateMBeanServer(): instantiated ConfigInterceptor" );
        }
        else
        {
            mDelegateMBeanServer    = mbs;
        }
    
private static voidsetDepth(java.lang.Integer i)

 sDepth.set(i); 
private com.sun.enterprise.admin.event.EventStacksetupEventStack(java.lang.Integer startDepthInteger)

        EventStack eventStack    = null;
        if ( EVENT_STACK_ISNT_POINTLESS )
        {
            if ( startDepthInteger.intValue() == 0 )
            {
                debug( "FlushConfigHook.setupEventStack(): startDepth = 0");
                eventStack = new EventStack();
                eventStack.setConfigContext( getAdminContext().getAdminConfigContext() );
                EventContext.setEventStackToThreadLocal(eventStack);
            }
            else
            {
                debug( "FlushConfigHook.setupEventStack(): startDepth = ", startDepthInteger);
            }
        }
        return eventStack;