FileDocCategorySizeDatePackage
ConcurrentHasherRequest.javaAPI DocAzureus 3.0.3.43372Thu Feb 09 19:42:44 GMT 2006org.gudy.azureus2.core3.util

ConcurrentHasherRequest

public class ConcurrentHasherRequest extends Object
author
parg

Fields Summary
private static AEMonitor
class_mon
private ConcurrentHasher
concurrent_hasher
private ByteBuffer
buffer
private ConcurrentHasherRequestListener
listener
private int
size
private byte[]
result
private boolean
cancelled
private boolean
low_priority
private AESemaphore
sem
Constructors Summary
protected ConcurrentHasherRequest(ConcurrentHasher _concurrent_hasher, ByteBuffer _buffer, ConcurrentHasherRequestListener _listener, boolean _low_priorty)

	
	
	
							
									
				
										 
	
		concurrent_hasher	= _concurrent_hasher;
		buffer				= _buffer;
		listener			= _listener;
		low_priority		= _low_priorty;
		
		size				= buffer.limit() - buffer.position();
	
Methods Summary
public voidcancel()
cancel the hash request. If it is cancelled before it is completed then a subsequent call to getResult will return null

	
		if ( !cancelled ){
			
			cancelled	= true;
			
			sem.releaseForever();
			
			ConcurrentHasherRequestListener	listener_copy;
			
			try{
				class_mon.enter();
			
				listener_copy	= listener;
				
				listener	= null;
				
			}finally{
				
				class_mon.exit();
			}
			
			if ( listener_copy != null ){
				
				listener_copy.complete( this );
			}
		}
	
public booleangetCancelled()

		return( cancelled );
	
public byte[]getResult()
synchronously get the result of the hash - null returned if it is cancelled

return

		sem.reserve();
		
		return( result );
	
public intgetSize()

		return( size );
	
public booleanisLowPriority()

		return( low_priority );
	
protected voidrun(SHA1Hasher hasher)

		if ( !cancelled ){
			
			if ( AEDiagnostics.ALWAYS_PASS_HASH_CHECKS ){
			
				result = new byte[0];
				
			}else{
				
				result = hasher.calculateHash( buffer );
			}
			
			sem.releaseForever();

			if ( !cancelled ){
				
				ConcurrentHasherRequestListener	listener_copy;
				
				try{
					class_mon.enter();
				
					listener_copy	= listener;
					
					listener	= null;
					
				}finally{
					
					class_mon.exit();
				}
				
				if ( listener_copy != null ){
					
					listener_copy.complete( this );
				}	
			}
		}