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

LoaderRegThread

public final class LoaderRegThread extends Thread

Fields Summary
private volatile boolean
mQuit
private final ArrayBlockingQueue
mQueue
private final Logger
mLogger
private final LoaderRegHandler
mRegHandler
private volatile QueueItem
mInProgress
to support waitAll()--a best effort indicator
Constructors Summary
public LoaderRegThread(LoaderRegHandler regHandler, Logger logger)

		mRegHandler	= regHandler;
		mLogger	= logger;
		mQuit	= false;

        final int maxElements = 512;
		mQueue		= new ArrayBlockingQueue<QueueItem>( maxElements );
	
Methods Summary
public voidenqueue(boolean register, java.util.List candidates)

        for( final ObjectName objectName : candidates )
		{
			enqueue( register, objectName );
		}
	
public voidenqueue(boolean register, javax.management.ObjectName theObject)

        //debug( "ENQUEUE: " + (register? "register" : "unregister") + " : " + JMXUtil.toString(theObject) );
        try
        {
            mQueue.put( new QueueItem( theObject, register ) );
        }
        catch( InterruptedException e )
        {
            mQuit   = true;
        }
	
private final java.util.logging.LoggergetLogger()

		return( mLogger );
	
public booleanisQueueEmpty()

        return mQueue.size() == 0;
    
protected booleanmySleep(long millis)

		boolean	interrupted	= false;
		
		try
		{
			Thread.sleep( millis );
		}
		catch( InterruptedException e )
		{
			Thread.interrupted();
			interrupted	= true;
		}
		
		return interrupted;
	
private voidprocess()

		while ( ! mQuit  )
		{
            mInProgress = mQueue.take();
            if ( mInProgress == null )
            {
                mQuit   = true; // a null item signals that we should quit
            }
            
            //debug( "PROCESS: " + (item.mRegister? "register" : "unregister") + " : " + JMXUtil.toString(item.mObjectName) );
            
            if ( mInProgress.mRegister )
            {
                processRegistration( mInProgress.mObjectName );
            }
            else
            {
                processUnregistration( mInProgress.mObjectName );
            }
            mInProgress = null;
		}
	
private voidprocessRegistration(javax.management.ObjectName objectName)

		try
		{
			mRegHandler.handleMBeanRegistered( objectName );
			getLogger().finer( "LoaderRegThread.processRegistration: processed mbean: " + objectName );
		}
		catch( Throwable t )
		{
			getLogger().warning( "LoaderRegThread.processRegistration: " +
				"registration of MBean failed for: " + 
				objectName + " = " + t.toString() + ", " + t.getMessage() + "\n" +
				ExceptionUtil.getStackTrace( t ) );
		}
	
private voidprocessUnregistration(javax.management.ObjectName objectName)

		try
		{
			mRegHandler.handleMBeanUnregistered( objectName );
		}
		catch( Throwable t )
		{
			getLogger().warning( "LoaderRegThread.processUnregistration: " +
				"unregistration of MBean failed for: " + 
				objectName + " = " + t.toString() );
		}
	
public voidquit()

		mQuit	= true;
		synchronized( this )
		{
			this.notify();
		}
	
public voidrun()

		mQuit	= false;
		
		while ( ! mQuit )
		{
			try
            {
                process();
            }
            catch( InterruptedException e )
            {
                mQuit   = true;
            }
		}
	
private final voidtrace(java.lang.Object o)

		if ( mLogger != null )
		{
			mLogger.finer( o.toString() );
		}
	
public voidwaitAll()
Wait for all outstanding requests to be finished. A best-effort method; not a 100% guarantee, but that's also true if something is queued right after the call!

    
                                                         
		 
	
	
        while ( mQueue.size() != 0 || mInProgress != null )
        {
			mySleep( 100 );
        }