FileDocCategorySizeDatePackage
AMXLoggingHook.javaAPI DocGlassfish v2 API9344Fri May 04 22:35:44 BST 2007com.sun.enterprise.server.logging

AMXLoggingHook

public final class AMXLoggingHook extends Object
Hook used for AMX logging by FileandSysLogHandler. This class assumes that the caller is holding a lock that will prevent more than one thread from calling {@link #publish}.

Fields Summary
private ObjectName
mLoggingObjectName
private MBeanServer
mMBeanServer
private LoggingImplHook
mLoggingImplHook
private Level
mMinimumLogLevel
The minimum log level for which LogRecords will be passed to the AMX Logging MBean. Generally speaking, all LogRecords should be passed along, letting the AMX Logging MBean decide their disposition.
private final com.sun.appserv.management.helper.AMXDebugHelper
mDebug
private final String
mServerName
private static final AMXLoggingHook
INSTANCE
private static final String
LOGGING_IMPL_CLASSNAME
Constructors Summary
AMXLoggingHook()

        mServerName = System.getProperty( com.sun.enterprise.util.SystemPropertyConstants.SERVER_NAME);
        final String  instanceRoot  = System.getProperty(
            com.sun.enterprise.util.SystemPropertyConstants.INSTANCE_ROOT_PROPERTY );
            
        mDebug = new AMXDebugHelper( instanceRoot + "/AMXLoggingHook-" + mServerName + ".debug" );

        // debug( "\n_______________________________________________________________________________");
        // debug( "AMXLoggingHook: REV = 1");
        // debug( "AMXLoggingHook: started at " + new java.util.Date() + " for server " + mServerName);
        
        // dumpSystemProps( mDebug );

        mLoggingObjectName  = null;
        mMinimumLogLevel    = Level.FINEST;
        mLoggingImplHook    = null;
        
        //mDebug.println( com.sun.appserv.management.util.misc.ExceptionUtil.toString( new Exception("HELLO") ) );
        
        // can't initialize now; FileandSysLogHandler is called even before main()
        mMBeanServer = null;
    
Methods Summary
private synchronized javax.management.ObjectName_enableLoggingHook()

        debug( "_enableLoggingHook" );
        if ( mLoggingImplHook != null )
        {
            throw new IllegalStateException();
        }
        
        mMBeanServer = FeatureAvailability.getInstance().waitForMBeanServer();
        
        LoggingImplHook hook = null;
        try
        {
            final Class  loggingClass = Class.forName( LOGGING_IMPL_CLASSNAME );
            
            final Constructor constructor = loggingClass.getConstructor( String.class );
            hook = (LoggingImplHook)constructor.newInstance( mServerName );
            
            final Method   getObjectNameMethod =
                loggingClass.getMethod( "getObjectName", String.class );
            final ObjectName proposedObjectName = (ObjectName)getObjectNameMethod.invoke( hook, mServerName );
            debug( "registering Logging as: " + proposedObjectName );
            mLoggingObjectName  = mMBeanServer.registerMBean( hook, proposedObjectName ).getObjectName();
            mLoggingImplHook   = hook;
         }
         catch ( Exception e )
         {
            hook    = null;
            final String msg = "Can't load " + LOGGING_IMPL_CLASSNAME + ", caught: " + e;
            debug( msg );
            throw new Error( msg, e);
         }
         
    debug( "_enableLoggingHook DONE" );
         return mLoggingObjectName;
    
private final voiddebug(java.lang.Object o)

 mDebug.println( o ); 
private voiddumpSystemProps(com.sun.appserv.management.helper.AMXDebugHelper output)

        final java.util.Properties    props   = System.getProperties();
        
        final String[]  keys    = (String[])props.keySet().toArray( new String[0] );
        java.util.Arrays.sort( keys );
        for( final String key : keys )
        {
            debug( key + "=" + props.getProperty( key ) );
        }
        
    
public static javax.management.ObjectNameenableLoggingHook()
Called exactly once to install the Logging MBean and turn on AMX support for logging.

return
ObjectName of AMX Logging MBean

    
    
                                            
          
    
    
        return getInstance()._enableLoggingHook();
    
public static com.sun.enterprise.server.logging.AMXLoggingHookgetInstance()

    
          
    
    
        return INSTANCE;
    
public java.util.logging.LevelgetMinimumLogLevel()

        return mMinimumLogLevel;
    
voidpublish(java.util.logging.LogRecord record, java.util.logging.Formatter theFormatter)

        if ( record.getLevel().intValue() < mMinimumLogLevel.intValue() )
        {
            return;
        }

        debug( "publish: " + theFormatter.format( record ) );
        if ( mLoggingImplHook != null )
        {
            try
            {
                mLoggingImplHook.privateLoggingHook( record, theFormatter );
            }
            catch( Throwable t )
            {
                mDebug.println( "AMXLoggingHook.publish: Exception calling privateLoggingHook: ", t );
                // squelch--we can't log it or we'll have a recursive call
            }
        }
    
public voidsetMinimumLogLevel(java.util.logging.Level level)

        mMinimumLogLevel    = level;