FileDocCategorySizeDatePackage
PRUDPPacketHandlerRequestImpl.javaAPI DocAzureus 3.0.3.43573Thu Mar 16 13:50:34 GMT 2006com.aelitis.net.udp.uc.impl

PRUDPPacketHandlerRequestImpl

public class PRUDPPacketHandlerRequestImpl extends Object implements com.aelitis.net.udp.uc.PRUDPPacketHandlerRequest
author
parg

Fields Summary
private AESemaphore
sem
private long
timeout
private com.aelitis.net.udp.uc.PRUDPPacketReceiver
receiver
private com.aelitis.net.udp.uc.PRUDPPacketHandlerException
exception
private com.aelitis.net.udp.uc.PRUDPPacket
reply
private long
send_time
private long
reply_time
Constructors Summary
protected PRUDPPacketHandlerRequestImpl(com.aelitis.net.udp.uc.PRUDPPacketReceiver _receiver, long _timeout)

	
	
	
			
						 
	
		receiver	= _receiver;
		timeout		= _timeout;
	
Methods Summary
public longgetElapsedTime()

		if ( send_time == 0 || reply_time == 0 ){
			
			return( -1 );
		}
		
		long	res = reply_time - send_time;
		
		if ( res < 0 ){
			
			res	= 0;
		}
		
			// do something sensible with 0 time!
		
		if ( res == 0 ){
			
			res = SystemTime.TIME_GRANULARITY_MILLIS / 2;
		}
		
		return( res );
	
protected com.aelitis.net.udp.uc.PRUDPPacketgetReply()

		sem.reserve();
		
		if ( exception != null ){
			
			throw( exception );
		}
			
		return( reply );
	
protected longgetSendTime()

		return( send_time );
	
protected longgetTimeout()

		return( timeout );
	
protected voidsent()

		send_time	= SystemTime.getCurrentTime();
	
protected voidsetException(com.aelitis.net.udp.uc.PRUDPPacketHandlerException e)

			// don't override existing reply for synchronous callers as they can
			// do what they want with it
		
		if ( reply == null ){
			
			reply_time	= SystemTime.getCurrentTime();

			exception	= e;
		}
		
		sem.release();
			
			// still report errors to asyn clients (even when a reply has been received)
			// as they need something to indicate that a continuation packet wasn't received
			// and that the request has timed-out. ie. a multi-packet reply must terminate
			// either with the reception of a non-continuation (i.e. last) packet *or* a
			// timeout/error
		
		if ( receiver != null ){
				
			receiver.error( e );
		}
	
protected voidsetReply(com.aelitis.net.udp.uc.PRUDPPacket packet, java.net.InetSocketAddress originator, long receive_time)

		if ( reply == null ){
	
			reply_time	= receive_time;
			
			reply	= packet;
			
		}else{
			
			packet.setPreviousPacket( reply );
			
			reply	= packet;
		}
		
		if( !packet.hasContinuation()){
			
			sem.release();
		}
		
		if ( receiver != null ){
			
			receiver.packetReceived( this, packet, originator );
		}