FileDocCategorySizeDatePackage
TrackerTorrentImpl.javaAPI DocAzureus 3.0.3.48095Fri Jun 30 04:16:04 BST 2006org.gudy.azureus2.pluginsimpl.local.tracker

TrackerTorrentImpl

public class TrackerTorrentImpl extends Object implements TrackerTorrent, TRHostTorrentListener, TRHostTorrentWillBeRemovedListener
author
parg

Fields Summary
protected TRHostTorrent
host_torrent
protected List
listeners_cow
protected List
removal_listeners
protected org.gudy.azureus2.core3.util.AEMonitor
this_mon
Constructors Summary
public TrackerTorrentImpl(TRHostTorrent _host_torrent)


	
	
			 
	
		host_torrent	= _host_torrent;
	
Methods Summary
public voidaddListener(TrackerTorrentListener listener)

		try{
			this_mon.enter();
		
			List	new_listeners = new ArrayList( listeners_cow );
			
			new_listeners.add( listener );
			
			if ( new_listeners.size() == 1 ){
				
				host_torrent.addListener( this );
			}
			
			listeners_cow = new_listeners;
			
		}finally{
			
			this_mon.exit();
		}
	
public voidaddRemovalListener(TrackerTorrentWillBeRemovedListener listener)

		try{
			this_mon.enter();
		
			removal_listeners.add( listener );
			
			if ( removal_listeners.size() == 1 ){
				
				host_torrent.addRemovalListener( this );
			}
		}finally{
			
			this_mon.exit();
		}
	
public booleancanBeRemoved()

		try{
			host_torrent.canBeRemoved();
			
		}catch( TRHostTorrentRemovalVetoException e ){
			
			throw( new TrackerTorrentRemovalVetoException(e.getMessage()));
		}
		
		return( true );
	
public voiddisableReplyCaching()

		host_torrent.disableReplyCaching();
	
public booleanequals(java.lang.Object other)

			// as we're lazy and create new instances of this on demand we need to
			// do something sensible about equivalence
		
		if ( other instanceof TrackerTorrentImpl ){
			
			return( host_torrent == ((TrackerTorrentImpl)other).host_torrent );
		}
		
		return( false );
	
public longgetAnnounceCount()

		return( host_torrent.getAnnounceCount());
	
public longgetAverageAnnounceCount()

		return( host_torrent.getAverageAnnounceCount());
	
public longgetAverageBytesIn()

		return( host_torrent.getAverageBytesIn());
	
public longgetAverageBytesOut()

		return( host_torrent.getAverageBytesOut());
	
public longgetAverageDownloaded()

		return( host_torrent.getAverageDownloaded());
	
public longgetAverageScrapeCount()

		return( host_torrent.getAverageScrapeCount());
	
public longgetAverageUploaded()

		return( host_torrent.getAverageUploaded());
	
public intgetBadNATCount()

		return( host_torrent.getBadNATCount());
	
public longgetCompletedCount()

		return( host_torrent.getCompletedCount());
	
public longgetDateAdded()

		return( host_torrent.getDateAdded());
	
protected TRHostTorrentgetHostTorrent()

		return( host_torrent );
	
public intgetLeecherCount()

		return( host_torrent.getLeecherCount());
	
public TrackerPeer[]getPeers()

		TRHostPeer[]	peers = host_torrent.getPeers();
		
		TrackerPeer[]	res = new TrackerPeer[peers.length];
		
		for (int i=0;i<peers.length;i++){
			
			res[i] = new TrackerPeerImpl( peers[i]);
		}
		
		return( res );
	
public longgetScrapeCount()

		return( host_torrent.getScrapeCount());
	
public intgetSeedCount()

		return( host_torrent.getSeedCount());
	
public intgetStatus()

		int	status = host_torrent.getStatus();
		
		switch(status){
			case TRHostTorrent.TS_STARTED:
				return( TS_STARTED );
			case TRHostTorrent.TS_STOPPED:
				return( TS_STOPPED );
			case TRHostTorrent.TS_PUBLISHED:
				return( TS_PUBLISHED );
			default:
				throw( new RuntimeException( "TrackerTorrent: status invalid"));
		}
	
public TorrentgetTorrent()

		return( new TorrentImpl( host_torrent.getTorrent()));
	
public longgetTotalBytesIn()

		return( host_torrent.getTotalBytesIn());
	
public longgetTotalBytesOut()

		return( host_torrent.getTotalBytesOut());
	
public longgetTotalDownloaded()

		return( host_torrent.getTotalDownloaded());
	
public longgetTotalLeft()

		return( host_torrent.getTotalLeft());
	
public longgetTotalUploaded()

		return( host_torrent.getTotalUploaded());
	
public inthashCode()

		return( host_torrent.hashCode());
	
public booleanisPassive()

		return( host_torrent.isPassive());
	
public voidpostProcess(TRHostTorrentRequest request)

		List	listeners_ref = listeners_cow;
		
		for (int i=0;i<listeners_ref.size();i++){
			
			try{
				((TrackerTorrentListener)listeners_ref.get(i)).postProcess(new TrackerTorrentRequestImpl(request));
				
			}catch( TrackerException e ){
				
				throw( new TRHostException( e.getMessage(), e ));
				
			}catch( Throwable e ){
			
				throw( new TRHostException( "Post-process fails", e ));
			}
		}
	
public voidpreProcess(TRHostTorrentRequest request)

		List	listeners_ref = listeners_cow;
		
		for (int i=0;i<listeners_ref.size();i++){
			
			try{
				((TrackerTorrentListener)listeners_ref.get(i)).preProcess(new TrackerTorrentRequestImpl(request));
				
			}catch( TrackerException e ){
				
				throw( new TRHostException( e.getMessage(), e ));
				
			}catch( Throwable e ){
			
				throw( new TRHostException( "Pre-process fails", e ));
			}
		}
	
public voidremove()

		try{
			host_torrent.remove();
			
		}catch( TRHostTorrentRemovalVetoException e ){
			
			throw( new TrackerTorrentRemovalVetoException(e.getMessage()));
		}
	
public voidremoveListener(TrackerTorrentListener listener)

		try{
			this_mon.enter();
		
			List	new_listeners = new ArrayList( listeners_cow );
			
			new_listeners.remove( listener );
				
			if ( new_listeners.size() == 0 ){
				
				host_torrent.removeListener(this);
			}
			
			listeners_cow = new_listeners;

		}finally{
			
			this_mon.exit();
		}
	
public voidremoveRemovalListener(TrackerTorrentWillBeRemovedListener listener)

		try{
			this_mon.enter();
		
			removal_listeners.remove( listener );
			
			if ( removal_listeners.size() == 0 ){
				
				host_torrent.removeRemovalListener(this);
			}	
		}finally{
			
			this_mon.exit();
		}
	
public voidstart()

		try{
			host_torrent.start();
			
		}catch( Throwable e ){
			
			throw( new TrackerException("Start failed", e ));
		}
	
public voidstop()

		try{
			host_torrent.stop();
			
		}catch( Throwable e ){
			
			throw( new TrackerException("Start failed", e ));
		}
	
public voidtorrentWillBeRemoved(TRHostTorrent t)

		for (int i=0;i<removal_listeners.size();i++){
			
			try{
				((TrackerTorrentWillBeRemovedListener)removal_listeners.get(i)).torrentWillBeRemoved( this );
				
			}catch( TrackerTorrentRemovalVetoException e ){
				
				throw( new TRHostTorrentRemovalVetoException( e.getMessage()));
			}
		}