FileDocCategorySizeDatePackage
TrackerImpl.javaAPI DocAzureus 3.0.3.47180Thu Sep 06 21:11:00 BST 2007org.gudy.azureus2.pluginsimpl.local.tracker

TrackerImpl

public class TrackerImpl extends TrackerWCHelper implements Tracker, TRHostAuthenticationListener, TRHostListener
author
parg

Fields Summary
private static TrackerImpl
singleton
private static org.gudy.azureus2.core3.util.AEMonitor
class_mon
private List
listeners
private TRHost
host
private List
auth_listeners
Constructors Summary
protected TrackerImpl(TRHost _host)

		setTracker( this );
		
		host		= _host;
				
		host.addListener( this );
	
Methods Summary
public voidaddAuthenticationListener(TrackerAuthenticationListener l)

	
		try{
			this_mon.enter();
				
			auth_listeners.add(l);
			
			if ( auth_listeners.size() == 1 ){
				
				host.addAuthenticationListener( this );
			}
		}finally{
			
			this_mon.exit();
		}
	
public voidaddListener(TrackerListener listener)

		try{
			this_mon.enter();
		
			listeners.add( listener );
		
			TrackerTorrent[] torrents = getTorrents();
		
			for (int i=0;i<torrents.length;i++){
			
				listener.torrentAdded( torrents[i]);
			}
		}finally{
			
			this_mon.exit();
		}
	
public booleanauthenticate(java.net.URL resource, java.lang.String user, java.lang.String password)

		for (int i=0;i<auth_listeners.size();i++){
			
			try{
				boolean res = ((TrackerAuthenticationListener)auth_listeners.get(i)).authenticate( resource, user, password );
				
				if ( res ){
					
					return(true );
				}
			}catch( Throwable e ){
				
				Debug.printStackTrace( e );
			}
		}
		
		return( false );
	
public byte[]authenticate(java.net.URL resource, java.lang.String user)

		for (int i=0;i<auth_listeners.size();i++){
			
			try{
				byte[] res = ((TrackerAuthenticationListener)auth_listeners.get(i)).authenticate( resource, user );
				
				if ( res != null ){
					
					return( res );
				}
			}catch( Throwable e ){
				
				Debug.printStackTrace( e );
			}
		}
		
		return( null );
	
public TrackerWebContextcreateWebContext(int port, int protocol)

		return( new TrackerWebContextImpl( this, null, port, protocol, null ));
	
public TrackerWebContextcreateWebContext(java.lang.String name, int port, int protocol)

		return( new TrackerWebContextImpl( this, name, port, protocol, null ));
	
public TrackerWebContextcreateWebContext(java.lang.String name, int port, int protocol, java.net.InetAddress bind_ip)

		return( new TrackerWebContextImpl( this, name, port, protocol, bind_ip ));
    
public voiddestroy()

		super.destroy();
		
		auth_listeners.clear();

		host.removeAuthenticationListener( this );
		
		listeners.clear();
		
		host.close();
	
public java.lang.StringgetName()

		return( host.getName());
	
public static TrackergetSingleton()

	
	
	  
	
	
		try{
			class_mon.enter();
		
			if ( singleton == null ){
							
				singleton	= new TrackerImpl( TRHostFactory.getSingleton());
			}		
			
			return( singleton );
			
		}finally{
			
			class_mon.exit();
		}
	
public TrackerTorrentgetTorrent(Torrent torrent)

		TRHostTorrent	ht = host.getHostTorrent(((TorrentImpl)torrent).getTorrent());
		
		if ( ht == null ){
			
			return( null );
		}
		
		return( new TrackerTorrentImpl( ht ));
	
public TrackerTorrent[]getTorrents()

		TRHostTorrent[]	hts = host.getTorrents();
		
		TrackerTorrent[]	res = new TrackerTorrent[hts.length];
		
		for (int i=0;i<hts.length;i++){
			
			res[i] = new TrackerTorrentImpl(hts[i]);
		}
		
		return( res );
	
public java.net.URL[]getURLs()

		URL[][]	url_sets = TRTrackerUtils.getAnnounceURLs();
		
		URL[]	res = new URL[url_sets.length];
		     	          
		for (int i=0;i<res.length;i++){
			
			res[i] = url_sets[i][0];
		}
		
		return( res );
	
public TrackerTorrenthost(Torrent _torrent, boolean _persistent)

		return( host( _torrent, _persistent, false ));
	
public TrackerTorrenthost(Torrent _torrent, boolean _persistent, boolean _passive)

		TorrentImpl	torrent = (TorrentImpl)_torrent;
		
		try{
			return( new TrackerTorrentImpl( host.hostTorrent( torrent.getTorrent(), _persistent, _passive )));
			
		}catch( Throwable e ){
			
			throw( new TrackerException( "Tracker: host operation fails", e ));
		}
	
public TrackerTorrentpublish(Torrent _torrent)

		TorrentImpl	torrent = (TorrentImpl)_torrent;
		
		try{
			return( new TrackerTorrentImpl( host.publishTorrent( torrent.getTorrent() )));
			
		}catch( Throwable e ){
			
			throw( new TrackerException( "Tracker: publish operation fails", e ));
		}
	
public voidremoveAuthenticationListener(TrackerAuthenticationListener l)

	
		try{
			this_mon.enter();
		
			auth_listeners.remove(l);
			
			if ( auth_listeners.size() == 0 ){
					
				host.removeAuthenticationListener( this );
			}
		}finally{
			
			this_mon.exit();
		}
	
public voidremoveListener(TrackerListener listener)

		try{
			this_mon.enter();
		
			listeners.remove( listener );
			
		}finally{
			
			this_mon.exit();
		}
	
public voidtorrentAdded(TRHostTorrent t)

		try{
			this_mon.enter();
		
			for (int i=0;i<listeners.size();i++){
				
				((TrackerListener)listeners.get(i)).torrentAdded(new TrackerTorrentImpl(t));
			}
		}finally{
			
			this_mon.exit();
		}
	
public voidtorrentChanged(TRHostTorrent t)

		for (int i=0;i<listeners.size();i++){
			
			((TrackerListener)listeners.get(i)).torrentChanged(new TrackerTorrentImpl(t));
		}
	
public voidtorrentRemoved(TRHostTorrent t)

	
		try{
			this_mon.enter();
		
			for (int i=0;i<listeners.size();i++){
			
				((TrackerListener)listeners.get(i)).torrentRemoved(new TrackerTorrentImpl(t));
			}
		}finally{
			
			this_mon.exit();
		}