FileDocCategorySizeDatePackage
PeerImpl.javaAPI DocAzureus 3.0.3.411471Fri Aug 31 16:09:44 BST 2007org.gudy.azureus2.pluginsimpl.local.peers

PeerImpl

public class PeerImpl extends org.gudy.azureus2.core3.logging.LogRelation implements Peer
author
parg

Fields Summary
protected PeerManagerImpl
manager
protected PEPeer
delegate
protected org.gudy.azureus2.core3.util.AEMonitor
this_mon
private Map
user_data
private HashMap
peer_listeners
Constructors Summary
protected PeerImpl(PEPeer _delegate)
don't use me, use PeerManagerImpl.getPeerForPEPeer

param
_delegate

  	

		       		 
	
	
	
			 
	
		delegate	= _delegate;
		
		manager = PeerManagerImpl.getPeerManager( delegate.getManager());
	
Methods Summary
public voidaddListener(PeerListener l)

		PEPeerListener core_listener = 
			new PEPeerListener() 
			{
				public void 
				stateChanged(
					final PEPeer peer,	// seems don't need this here
					int new_state ) 
				{
					try{
						l.stateChanged( new_state );
						
					}catch( Throwable e ){
						Debug.printStackTrace(e);
					}
				}
      
				public void 
				sentBadChunk( 
					final PEPeer peer,	// seems don't need this here
					int piece_num, 
					int total_bad_chunks )
				{
					try{
						l.sentBadChunk( piece_num, total_bad_chunks );
					
					}catch( Throwable e ){
						Debug.printStackTrace(e);
					}
				}
				
				public void addAvailability(final PEPeer peer, BitFlags peerHavePieces)
				{
				}

				public void removeAvailability(final PEPeer peer, BitFlags peerHavePieces)
				{
				}
			};
    
		delegate.addListener( core_listener );
    
		if( peer_listeners == null ){
			
			peer_listeners = new HashMap();
		}
		
		peer_listeners.put( l, core_listener );
	
public voidaddListener(PeerListener2 l)

		PEPeerListener core_listener = 
			new PEPeerListener() 
			{
				public void 
				stateChanged(
					final PEPeer peer,	// seems don't need this here
					int new_state ) 
				{
					fireEvent( PeerEvent.ET_STATE_CHANGED, new Integer( new_state ));
				}
      
				public void 
				sentBadChunk( 
					final PEPeer peer,	// seems don't need this here
					int piece_num, 
					int total_bad_chunks )
				{
					fireEvent( PeerEvent.ET_BAD_CHUNK, new Integer[]{ new Integer(piece_num), new Integer(total_bad_chunks)});
				}
				
				public void addAvailability(final PEPeer peer, BitFlags peerHavePieces)
				{
					fireEvent( PeerEvent.ET_ADD_AVAILABILITY,peerHavePieces.flags );
				}

				public void removeAvailability(final PEPeer peer, BitFlags peerHavePieces)
				{
					fireEvent( PeerEvent.ET_REMOVE_AVAILABILITY,peerHavePieces.flags );
				}
				protected void
				fireEvent(
					final int		type,
					final Object	data )
				{
					try{
						l.eventOccurred(
							new PeerEvent()
							{
								public int getType(){ return( type );}
								public Object getData(){ return( data );}
							});
					}catch( Throwable e ){
						
						Debug.printStackTrace(e);
					}
				}
			};
    
		delegate.addListener( core_listener );
    
		if( peer_listeners == null ){
			
			peer_listeners = new HashMap();
		}
		
		peer_listeners.put( l, core_listener );
	
public booleanaddRequest(PeerReadRequest request)

		throw( new RuntimeException( "not supported"));
	
public voidcancelRequest(PeerReadRequest request)

		throw( new RuntimeException( "not supported"));
	
public voidclose(java.lang.String reason, boolean closedOnError, boolean attemptReconnect)

		manager.removePeer( this, reason );
	
protected voidclosed()

		if ( delegate instanceof PeerForeignDelegate ){
			
			((PeerForeignDelegate)delegate).stop();
		}
	
public booleanequals(java.lang.Object other)

		if ( other instanceof PeerImpl ){
			
			return( delegate == ((PeerImpl)other).delegate );
		}
		
		return( false );
	
public final boolean[]getAvailable()

		return( delegate.getAvailable().flags );
	
public java.lang.StringgetClient()

		return( delegate.getClient());
	
public org.gudy.azureus2.plugins.network.ConnectiongetConnection()

    return delegate.getPluginConnection();
  
protected PEPeergetDelegate()

		return( delegate );
	
public java.util.ListgetExpiredRequests()

		throw( new RuntimeException( "not supported"));
	
public byte[]getHandshakeReservedBytes()

		return delegate.getHandshakeReservedBytes();
	
public byte[]getId()

			// we *really* don't want a plugin to accidentally change our peerid (e.g. the Stuffer plugin did this)
			// as this screws stuff up bigtime
		
		byte[]	id = delegate.getId();
		
		if ( id == null ){
			return( null );
		}
		
		byte[]	copy = new byte[id.length];
		
		System.arraycopy( id, 0, copy, 0, copy.length );
		
		return( copy );
	
public java.lang.StringgetIp()

		return( delegate.getIp());
	
public PeerManagergetManager()

		return( manager );
	
public intgetMaximumNumberOfRequests()

		throw( new RuntimeException( "not supported"));
	
public intgetNumberOfRequests()

		throw( new RuntimeException( "not supported"));
	
public PEPeergetPEPeer()
Core use only. This is not propogated to the plugin interface

return
PEPeer object associated with the plugin Peer object

		return delegate;
	
public intgetPercentDone()

		return( delegate.getPercentDoneInThousandNotation());
	
public intgetPercentDoneInThousandNotation()

		return( delegate.getPercentDoneInThousandNotation());
	
public intgetPercentDoneOfCurrentIncomingRequest()

		return( delegate.getPercentDoneOfCurrentIncomingRequest());
	
public intgetPercentDoneOfCurrentOutgoingRequest()

		return( delegate.getPercentDoneOfCurrentOutgoingRequest());
	
public intgetPort()

		return( delegate.getPort());
	
public int[]getPriorityOffsets()

		throw( new RuntimeException( "not supported"));
	
public java.util.MapgetProperties()

		return( new HashMap());
	
public java.lang.Object[]getQueryableInterfaces()

		return new Object[] { delegate };
	
public java.lang.StringgetRelationText()

		return propogatedRelationText(delegate);
	
public java.util.ListgetRequests()

		throw( new RuntimeException( "not supported"));
	
public longgetSnubbedTime()

		return delegate.getSnubbedTime();
	
public intgetState()

		int	state = delegate.getPeerState();
		
		switch( state ){
			
			case PEPeer.CONNECTING:
			{
				return( Peer.CONNECTING );
			}
			case PEPeer.DISCONNECTED:
			{
				return( Peer.DISCONNECTED );
			}
			case PEPeer.HANDSHAKING:
			{
				return( Peer.HANDSHAKING );
			}
			case PEPeer.TRANSFERING:
			{
				return( Peer.TRANSFERING );
			}
		}
		
		return( -1 );
	
public PeerStatsgetStats()

		return( new PeerStatsImpl(manager, this, delegate.getStats()));
	
public org.gudy.azureus2.plugins.messaging.Message[]getSupportedMessages()

    com.aelitis.azureus.core.peermanager.messaging.Message[] core_msgs = delegate.getSupportedMessages();
    
    Message[] plug_msgs = new Message[ core_msgs.length ];
    
    for( int i=0; i < core_msgs.length; i++ ) {
      plug_msgs[i] = new MessageAdapter( core_msgs[i] );
    }
    
    return plug_msgs;
  
public intgetTCPListenPort()

  return delegate.getTCPListenPort();  
public intgetUDPListenPort()

  return delegate.getUDPListenPort();  
public intgetUDPNonDataListenPort()

 return delegate.getUDPNonDataListenPort(); 
public java.lang.ObjectgetUserData(java.lang.Object key)

		if ( user_data == null ){
			
			return( null );
		}
		
		return( user_data.get( key ));
	
public inthashCode()

		return( delegate.hashCode());
	
public voidinitialize()

		throw( new RuntimeException( "not supported"));
	
public booleanisChoked()

		return( delegate.isChokingMe());
	
public booleanisChoking()

		return( delegate.isChokedByMe());
	
public booleanisDownloadPossible()

		return delegate.isDownloadPossible();
	
public booleanisIncoming()

		return( delegate.isIncoming());
	
public booleanisInterested()

		return( delegate.isInteresting());
	
public booleanisInteresting()

		return( delegate.isInterested());
	
public booleanisOptimisticUnchoke()

		return( delegate.isOptimisticUnchoke());
	
public booleanisPieceAvailable(int pieceNumber)

		return delegate.isPieceAvailable(pieceNumber);
	
public booleanisSeed()

		return( delegate.isSeed());
	
public booleanisSnubbed()

		return( delegate.isSnubbed());
	
public booleanisTransferAvailable()

		return( delegate.transferAvailable());
	
public intreadBytes(int max)

		throw( new RuntimeException( "not supported"));
	
public voidremoveListener(PeerListener l)

		if ( peer_listeners != null ){
			
			PEPeerListener core_listener = (PEPeerListener)peer_listeners.remove( l );
    
			if( core_listener != null ) {
      
				delegate.removeListener( core_listener );
			}
		}
	
public voidremoveListener(PeerListener2 l)

		if ( peer_listeners != null ){
			
			PEPeerListener core_listener = (PEPeerListener)peer_listeners.remove( l );
    
			if( core_listener != null ) {
      
				delegate.removeListener( core_listener );
			}
		}
	
public voidrequestAllocationComplete()

		throw( new RuntimeException( "not supported"));		
	
public booleanrequestAllocationStarts(int[] base_priorities)

		throw( new RuntimeException( "not supported"));
	
public voidsetOptimisticUnchoke(boolean is_optimistic)

    delegate.setOptimisticUnchoke( is_optimistic );
  
public voidsetSnubbed(boolean b)

		delegate.setSnubbed(b);
	
public voidsetUserData(java.lang.Object key, java.lang.Object value)

		if ( user_data == null ){
			
			user_data	= new HashMap();
		}
		
		user_data.put( key, value );
	
public booleansupportsMessaging()

    return delegate.supportsMessaging();
  
public intwriteBytes(int max)

		throw( new RuntimeException( "not supported"));