FileDocCategorySizeDatePackage
MBeanImplBase.javaAPI DocGlassfish v2 API15523Fri May 04 22:23:42 BST 2007com.sun.enterprise.management.support

MBeanImplBase

public abstract class MBeanImplBase extends Object implements com.sun.appserv.management.util.jmx.NotificationSender, com.sun.appserv.management.base.AMXMBeanLogging, MBeanRegistration
Absolute base impl class. Should contain only core functionality, nothing to do with appserver specifics.

Fields Summary
protected static final String[]
EMPTY_STRING_ARRAY
protected MBeanServer
mServer
The MBeanServer in which this object is registered (if any)
protected ObjectName
mSelfObjectName
The ObjectName by which this object is registered (if registered). Multiple registrations, which are possible, overwrite this; the last registration wins. If the MBean has not been registered, this name will be null.
private com.sun.appserv.management.util.jmx.NotificationEmitterSupport
mNotificationEmitter
protected final Logger
mLogger
private Map
mNotificationBuilders
private final com.sun.appserv.management.util.misc.Output
mDebug
We need debugging before the MBean is registered, so our only choice is to use an ID based on something other than the as-yet-unknown ObjectName, namely the classname.
private static final Level[]
LOG_LEVELS
Constructors Summary
public MBeanImplBase()

	
		
	
	
		mLogger	= Logger.getLogger( LogDomains.ADMIN_LOGGER );
		mNotificationEmitter	= null;
	
Methods Summary
public synchronized voidaddNotificationListener(javax.management.NotificationListener listener)

		getNotificationEmitter().addNotificationListener( listener, null, null );
	
public synchronized voidaddNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)

		getNotificationEmitter().addNotificationListener( listener, filter, handback );
	
protected com.sun.appserv.management.util.jmx.NotificationBuildercreateNotificationBuilder(java.lang.String notificationType)

		NotificationBuilder	builder	= null;
		
		if ( notificationType.equals( AttributeChangeNotification.ATTRIBUTE_CHANGE ) )
		{
			builder	= new AttributeChangeNotificationBuilder( getObjectName() );
		}
		else
		{
			builder	= new NotificationBuilder( notificationType, getObjectName() );
		}
		
		return( builder );
	
protected final voiddebug(java.lang.Object o)

	    if ( getAMXDebug() && mDebug != null)
	    {
	        final String    newline = System.getProperty( "line.separator" );
	        
	        if ( shouldOmitObjectNameForDebug() )
	        {
	            mDebug.println( o );
	        }
	        else
	        {
	            mDebug.println( mSelfObjectName.toString() );
	            mDebug.println( "===> " + o );
	        }
	        mDebug.println( newline );
	    }
	
protected voiddebug(java.lang.Object args)

	    if ( getAMXDebug() )
	    {
	        debug( StringUtil.toString( "", args) );
	    }
	
protected voiddebugMethod(java.lang.String methodName, java.lang.Object args)

	    if ( getAMXDebug() )
	    {
	        debug( AMXDebug.methodString( methodName, args ) );
	    }
	
protected voiddebugMethod(java.lang.String msg, java.lang.String methodName, java.lang.Object args)

	    if ( getAMXDebug() )
	    {
	        debug( AMXDebug.methodString( methodName, args ) + ": " + msg );
	    }
	
public booleanenableAMXDebug(boolean enabled)

        final boolean formerValue   = getAMXDebug();
        if ( formerValue != enabled )
        {
            setAMXDebug( enabled );
        }
        return formerValue;
    
public final booleangetAMXDebug()
Although unusual, a subclass may override the debug state. Generally it is faster to NOT call getAMXDebug() before calling debug( x ) if 'x' is just a string. If it is expensive to construct 'x', then preflighting with getAMXDebug() may be worthwhile.

        return AMXDebug.getInstance().getDebug( getDebugID() );
    
protected java.lang.StringgetDebugID()

        return this.getClass().getName();
    
protected com.sun.appserv.management.util.misc.OutputgetDebugOutput()

        return AMXDebug.getInstance().getOutput( getDebugID() );
    
public java.lang.StringgetJMXDomain()

		return( getObjectName().getDomain() );
	
public final intgetListenerCount()

		return( getNotificationEmitter().getListenerCount() );
	
public final java.util.logging.LevelgetMBeanLogLevel()

		Logger	logger	= getMBeanLogger();
		assert( logger != null );
		
		Level	level	= logger.getLevel();
		while ( level == null )
		{
			logger	= logger.getParent();
			level	= logger.getLevel();
		}
		
		return( level );
	
protected final intgetMBeanLogLevelInt()

		return( getMBeanLogLevel().intValue() );
	
protected final java.util.logging.LoggergetMBeanLogger()

	    return mLogger;
	
public final java.lang.StringgetMBeanLoggerName()

		return( getMBeanLogger().getName() );
	
public final javax.management.MBeanServergetMBeanServer()

		return( mServer );
	
protected synchronized com.sun.appserv.management.util.jmx.NotificationBuildergetNotificationBuilder(java.lang.String notificationType)
Get a NotificationBuilder for the specified type of Notification whose source is this object.

		if ( mNotificationBuilders == null )
		{
			mNotificationBuilders	= new HashMap<String,NotificationBuilder>();
		}
		
		NotificationBuilder	builder	=
			(NotificationBuilder)mNotificationBuilders.get( notificationType );
		
		if ( builder == null )
		{
			builder	= createNotificationBuilder( notificationType );
			mNotificationBuilders.put( notificationType, builder );
		}
		
		return( builder );
	
protected final synchronized com.sun.appserv.management.util.jmx.NotificationEmitterSupportgetNotificationEmitter()

return
an empty array Subclass may wish to override this.

		if ( mNotificationEmitter == null )
		{
			mNotificationEmitter	= new NotificationEmitterSupport( true );
		}
		
		return( mNotificationEmitter );
	
public final intgetNotificationTypeListenerCount(java.lang.String type)

		return( getNotificationEmitter().getNotificationTypeListenerCount( type ) );
	
public final javax.management.ObjectNamegetObjectName()

		return( mSelfObjectName );
	
protected final voidlogFine(java.lang.Object o)

	    final String msg    = toString( o );
		debug( msg );
		
		if ( getMBeanLogLevelInt() <= Level.FINE.intValue() )
		{
			getMBeanLogger().fine( msg );
		}
	
protected final voidlogFiner(java.lang.Object o)

	    final String msg    = toString( o );
		debug( msg );
		
		if ( getMBeanLogLevelInt() <= Level.FINER.intValue() )
		{
			getMBeanLogger().finer( msg );
		}
	
protected final voidlogFinest(java.lang.Object o)

	    final String msg    = toString( o );
		debug( msg );
		
		if ( getMBeanLogLevelInt() <= Level.FINEST.intValue() )
		{
			getMBeanLogger().finest( msg );
		}
	
protected final voidlogInfo(java.lang.Object o)

	    final String msg    = toString( o );
		debug( msg );
		
		if ( getMBeanLogLevelInt() <= Level.INFO.intValue() )
		{
			getMBeanLogger().info( msg );
		}
	
protected final voidlogSevere(java.lang.Object o)

	    final String msg    = toString( o );
		debug( msg );
		
		if ( getMBeanLogLevelInt() <= Level.SEVERE.intValue() )
		{
			getMBeanLogger().severe( msg );
		}
	
protected final voidlogWarning(java.lang.Object o)

	    final String msg    = toString( o );
		debug( msg );
		
		if ( getMBeanLogLevelInt() <= Level.WARNING.intValue() )
		{
			getMBeanLogger().warning( msg );
		}
	
public voidpostDeregister()

		getMBeanLogger().finest( "postDeregister: " + getObjectName() );
		
		if ( mNotificationEmitter != null )
		{
			mNotificationEmitter.cleanup();
			mNotificationEmitter	= null;
		}
		
		if ( mNotificationBuilders != null )
		{
			mNotificationBuilders.clear();
			mNotificationBuilders	= null;
		}
		
		
		mServer					= null;
		mSelfObjectName			= null;
		
	
public voidpostRegister(java.lang.Boolean registrationDone)

	
		if ( registrationDone.booleanValue() )
		{
			getMBeanLogger().finest( "postRegister: " + getObjectName());
		}
		else
		{
			getMBeanLogger().finest( "postRegister: FAILURE: " + getObjectName());
		}
	
public voidpreDeregister()

		getMBeanLogger().finest( "preDeregister: " + getObjectName() );
	
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName nameIn)

		assert( nameIn != null );
		mServer			= server;
		mSelfObjectName	= nameIn;
		
		// ObjectName could still be modified by subclass
		return( mSelfObjectName );
	
protected static java.lang.Stringquote(java.lang.Object o)

		return( StringUtil.quote( "" + o ) );
	
public synchronized voidremoveNotificationListener(javax.management.NotificationListener listener)

 		getNotificationEmitter().removeNotificationListener( listener );
	
public synchronized voidremoveNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)

		getNotificationEmitter().removeNotificationListener( listener, filter, handback );
	
protected voidsendNotification(java.lang.String notificationType)
Send a Notification of the specified type containing no data.

		sendNotification( notificationType, notificationType, null, null );
	
protected voidsendNotification(java.lang.String notificationType, java.lang.String key, java.io.Serializable value)
Send a Notification of the specified type containing a single key/value pair for data.

	    final String    message = "no message specified";
	    
	    sendNotification( notificationType, message, key, value );
	
protected voidsendNotification(java.lang.String notificationType, java.lang.String message, java.lang.String key, java.io.Serializable value)
Send a Notification of the specified type containing a single key/value pair for data.

		final NotificationBuilder	builder	=
			getNotificationBuilder( notificationType );
			
		final Notification	notif	= builder.buildNew( message );
		NotificationBuilder.putMapData( notif, key, value );
			
		sendNotification( notif );
	
public voidsendNotification(javax.management.Notification notification)

 		getNotificationEmitter().sendNotification( notification );
 	
public final voidsetAMXDebug(boolean debug)

        AMXDebug.getInstance().setDebug( getDebugID(), debug);
    
public final voidsetMBeanLogLevel(java.util.logging.Level level)

		getMBeanLogger().setLevel( level );
	
public final voidsetMBeanLogLevelString(java.lang.String levelString)

	
		  
	    
	
		Level	level	= null;
		for( int i = 0; i < LOG_LEVELS.length; ++i )
		{
			if ( levelString.equals( LOG_LEVELS[ i ].getName() ) )
			{
				level	= LOG_LEVELS[ i ];
				break;
			}
		}
		
		if ( level == null )
		{
			throw new IllegalArgumentException( levelString );
		}

		setMBeanLogLevel( level );
	
protected booleanshouldOmitObjectNameForDebug()

        return mSelfObjectName == null;
    
protected booleansleepMillis(long millis)

		boolean	interrupted	= false;
		
		try
		{
			Thread.sleep( millis );
		}
		catch( InterruptedException e )
		{
			Thread.interrupted();
			interrupted	= true;
		}
		
		return interrupted;
	
protected static java.lang.StringtoString(java.lang.Object o)

	    if ( o == null )
	    {
	        return( "" + o );
	    }
	    
		return( SmartStringifier.toString( o ) );
	
protected final voidtrace(java.lang.Object o)

	    debug( o );