FileDocCategorySizeDatePackage
TRHostTorrentPublishImpl.javaAPI DocAzureus 3.0.3.46930Mon Jun 27 14:22:18 BST 2005org.gudy.azureus2.core3.tracker.host.impl

TRHostTorrentPublishImpl

public class TRHostTorrentPublishImpl extends Object implements TRHostTorrent
author
parg

Fields Summary
private TRHostImpl
host
private TOTorrent
torrent
private long
date_added
private int
status
private boolean
persistent
private int
seed_count
private int
peer_count
private TRHostPeer[]
peers
private List
listeners_cow
private List
removal_listeners
private HashMap
data
protected org.gudy.azureus2.core3.util.AEMonitor
this_mon
Constructors Summary
protected TRHostTorrentPublishImpl(TRHostImpl _host, TOTorrent _torrent, long _date_added)


	
	
				
				
					 
	
		host		= _host;
		torrent		= _torrent;
		date_added	= _date_added;
	
Methods Summary
public voidaddListener(TRHostTorrentListener l)

		try{
			this_mon.enter();
	
			List	new_listeners = new ArrayList( listeners_cow );
			
			new_listeners.add(l);
			
			listeners_cow	= new_listeners;
			
		}finally{
			
			this_mon.exit();
		}
		
		host.torrentListenerRegistered();
	
public voidaddRemovalListener(TRHostTorrentWillBeRemovedListener l)

		try{
			this_mon.enter();
			
			removal_listeners.add(l);
			
		}finally{
			
			this_mon.exit();
		}
	
public booleancanBeRemoved()

		for (int i=0;i<removal_listeners.size();i++){
			
			((TRHostTorrentWillBeRemovedListener)removal_listeners.get(i)).torrentWillBeRemoved( this );
		}
		
		return( true );
	
public voiddisableReplyCaching()

	
public longgetAnnounceCount()

		return( 0 );
	
public longgetAverageAnnounceCount()

		return( 0 );
	
public longgetAverageBytesIn()

		return( 0 );
	
public longgetAverageBytesOut()

		return( 0 );
	
public longgetAverageDownloaded()

		return( 0 );
	
public longgetAverageScrapeCount()

		return( 0 );
	
public longgetAverageUploaded()

		return( 0 );
	
public intgetBadNATCount()

		return( 0 );
	
public longgetCompletedCount()

		return( 0 );
	
public java.lang.ObjectgetData(java.lang.String key)
To retreive arbitrary objects against this object.

  	if (data == null) return null;
    return data.get(key);
  
public longgetDateAdded()

		return( date_added );
	
public intgetLeecherCount()

		return( peer_count );
	
public TRHostPeer[]getPeers()

		try{
			this_mon.enter();
		
			return( peers );
		}finally{
			
			this_mon.exit();
		}
	
public intgetPort()

		return( -1 );
	
public longgetScrapeCount()

		return( 0 );
	
public intgetSeedCount()

		return( seed_count );
	
public intgetStatus()

		return( status );
	
public TOTorrentgetTorrent()

		return( torrent );
	
public longgetTotalBytesIn()

		return( 0 );
	
public longgetTotalBytesOut()

		return( 0 );
	
public longgetTotalDownloaded()

		return( 0 );
	
public longgetTotalLeft()

		return( 0 );
	
public longgetTotalUploaded()

		return( 0 );
	
public booleanisPassive()

		return( false );
	
public booleanisPersistent()

		return( persistent );
	
protected voidpostProcess(TRHostTorrentRequest req)

		List	listeners_ref = listeners_cow;
	
		for (int i=0;i<listeners_ref.size();i++){
		
			try{
				((TRHostTorrentListener)listeners_ref.get(i)).postProcess(req);
				
			}catch( Throwable e ){
				
				Debug.printStackTrace(e);
			}
		}
	
protected voidpreProcess(TRHostTorrentRequest req)

		List	listeners_ref = listeners_cow;
	
		for (int i=0;i<listeners_ref.size();i++){
		
			try{
				((TRHostTorrentListener)listeners_ref.get(i)).preProcess(req);
				
			}catch( Throwable e ){
				
				Debug.printStackTrace(e);
			}
		}
	
public voidremove()

		try{
			this_mon.enter();
			
			canBeRemoved();
		
			host.remove( this );
			
		}finally{
			
			this_mon.exit();
		}
	
public voidremoveListener(TRHostTorrentListener l)

		try{
			this_mon.enter();
		
			List	new_listeners = new ArrayList( listeners_cow );
			
			new_listeners.remove(l);
			
			listeners_cow	= new_listeners;
			
		}finally{
			
			this_mon.exit();
		}
	
public voidremoveRemovalListener(TRHostTorrentWillBeRemovedListener l)

		try{
			this_mon.enter();
			
			removal_listeners.remove(l);
		}finally{
			
			this_mon.exit();
		}
	
public voidsetData(java.lang.String key, java.lang.Object value)
To store arbitrary objects against this object.

	try{
		this_mon.enter();

	  	if (data == null) {
	  	  data = new HashMap();
	  	}
	    if (value == null) {
	      if (data.containsKey(key))
	        data.remove(key);
	    } else {
	      data.put(key, value);
	    }
	}finally{
		
		this_mon.exit();
	}
  
public voidsetPassive(boolean passive)

	
public voidsetPersistent(boolean _persistent)

		persistent	= _persistent;
	
public voidstart()

	
public voidstop()

	
protected voidupdateStats()

		
		TRTrackerScraperResponse resp = null;
		
		TRTrackerAnnouncer tc = host.getTrackerClient( this );
		
		if ( tc != null ){
			
			resp = TRTrackerScraperFactory.getSingleton().scrape( tc );
		}
		
		if ( resp == null ){
			
			resp = TRTrackerScraperFactory.getSingleton().scrape( torrent );
		}
				
		try{
			this_mon.enter();
		
			if ( resp != null && resp.isValid()){
						
				peer_count 	= resp.getPeers();
				seed_count	= resp.getSeeds();
				
				peers = new TRHostPeer[ peer_count + seed_count ];
				
				for (int i=0;i<peers.length;i++){
					
					peers[i] = new TRHostPeerPublishImpl( i<seed_count );
				}
			}else{
				
				peers = new TRHostPeer[0];
			}
		}finally{
			
			this_mon.exit();
		}