FileDocCategorySizeDatePackage
AsyncDispatcher.javaAPI DocAzureus 3.0.3.42253Thu Aug 10 11:23:00 BST 2006org.gudy.azureus2.core3.util

AsyncDispatcher

public class AsyncDispatcher extends Object

Fields Summary
private AEThread
thread
private LinkedList
queue
private AESemaphore
queue_sem
private int
quiesce_after_millis
Constructors Summary
public AsyncDispatcher()

	
	
	
	
		this( 10000 );
	
public AsyncDispatcher(int _quiesce_after_millis)

		quiesce_after_millis	= _quiesce_after_millis;
	
Methods Summary
public voiddispatch(AERunnable target)

		synchronized( this ){
			
			queue.add( target );
			
			if ( thread == null ){
				
				thread = 
					new AEThread( "AsyncDispatcher", true )
					{
						public void
						runSupport()
						{
							while( true ){
								
								queue_sem.reserve( quiesce_after_millis );
								
								AERunnable	to_run = null;
								
								synchronized( AsyncDispatcher.this ){
									
									if ( queue.isEmpty()){
										
										thread = null;
										
										break;
									}
									
									to_run = (AERunnable)queue.removeFirst();
								}
								
								try{
									to_run.runSupport();
									
								}catch( Throwable e ){
									
									Debug.printStackTrace(e);
								}
							}
						}
					};
					
				thread.start();
			}
		}
		
		queue_sem.release();