FileDocCategorySizeDatePackage
DHTRouterContactImpl.javaAPI DocAzureus 3.0.3.44417Thu Sep 14 19:19:16 BST 2006com.aelitis.azureus.core.dht.router.impl

DHTRouterContactImpl

public class DHTRouterContactImpl extends Object implements com.aelitis.azureus.core.dht.router.DHTRouterContact
author
parg

Fields Summary
private byte[]
node_id
private com.aelitis.azureus.core.dht.router.DHTRouterContactAttachment
attachment
private boolean
has_been_alive
private boolean
ping_outstanding
private int
fail_count
private long
first_alive_time
private long
first_fail_or_last_alive_time
private long
last_added_time
private boolean
is_bucket_entry
Constructors Summary
protected DHTRouterContactImpl(byte[] _node_id, com.aelitis.azureus.core.dht.router.DHTRouterContactAttachment _attachment, boolean _has_been_alive)

		node_id			= _node_id;
		attachment		= _attachment;
		has_been_alive	= _has_been_alive;
		
		if ( attachment != null ){
			
			attachment.setRouterContact( this );
		}
		
		is_bucket_entry = false;
	
Methods Summary
public com.aelitis.azureus.core.dht.router.DHTRouterContactAttachmentgetAttachment()

		return( attachment );
	
protected longgetFirstAliveTime()

		return( first_alive_time );
	
protected longgetFirstFailOrLastAliveTime()

		return( first_fail_or_last_alive_time );
	
protected longgetFirstFailTime()

		return( fail_count==0?0:first_fail_or_last_alive_time );
	
public byte[]getID()

		return(node_id );
	
protected longgetLastAddedTime()

		return( last_added_time );
	
protected longgetLastAliveTime()

		return( fail_count==0?first_fail_or_last_alive_time:0 );
	
protected booleangetPingOutstanding()

		return( ping_outstanding );
	
public java.lang.StringgetString()

		return( DHTLog.getString2(node_id) + "[hba=" + (has_been_alive?"Y":"N" ) + 
				",bad=" + fail_count +
				",OK=" + getTimeAlive() + "]");
	
public longgetTimeAlive()

		if ( fail_count > 0 || first_alive_time == 0 ){
			
			return( 0 );
		}
		
		return( SystemTime.getCurrentTime() - first_alive_time );
	
public booleanhasBeenAlive()

		return( has_been_alive );
	
protected booleanhasFailed()

		if ( has_been_alive ){
			
			return( fail_count >= attachment.getMaxFailForLiveCount());
			
		}else{
			
			return( fail_count >= attachment.getMaxFailForUnknownCount());
		}
	
public booleanisAlive()

		return( has_been_alive && fail_count == 0 );
	
public booleanisBucketEntry()

		return is_bucket_entry;
	
public booleanisFailing()

		return( fail_count > 0 );
	
public booleanisReplacement()

		return !is_bucket_entry;
	
public voidsetAlive()

		fail_count							= 0;
		first_fail_or_last_alive_time		= SystemTime.getCurrentTime();
		has_been_alive						= true;
		
		if ( first_alive_time == 0 ){
			
			first_alive_time = first_fail_or_last_alive_time;
		}
	
protected voidsetAttachment(com.aelitis.azureus.core.dht.router.DHTRouterContactAttachment _attachment)

		attachment	= _attachment;
	
public voidsetBucketEntry()

		is_bucket_entry = true;
	
protected booleansetFailed()

		fail_count++;
		
		if ( fail_count == 1 ){
			
			first_fail_or_last_alive_time = SystemTime.getCurrentTime();
		}
		
		return( hasFailed());
	
protected voidsetLastAddedTime(long l)

		last_added_time	= l;
	
protected voidsetPingOutstanding(boolean b)

		ping_outstanding = b;
	
public voidsetReplacement()

		is_bucket_entry = false;