⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trtrackerannouncerfactoryimpl.java

📁 这是一个基于java编写的torrent的P2P源码
💻 JAVA
字号:
/*
 * File    : TRTrackerClientFactoryImpl.java
 * Created : 04-Nov-2003
 * By      : parg
 * 
 * Azureus - a Java Bittorrent client
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details ( see the LICENSE file ).
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.gudy.azureus2.core3.tracker.client.impl;

/**
 * @author parg
 *
 */

import java.util.*;


import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.tracker.client.*;
import org.gudy.azureus2.core3.tracker.client.impl.bt.TRTrackerBTAnnouncerImpl;
import org.gudy.azureus2.core3.tracker.client.impl.dht.TRTrackerDHTAnnouncerImpl;
import org.gudy.azureus2.core3.util.*;

public class 
TRTrackerAnnouncerFactoryImpl 
{
	protected static List	listeners 	= new ArrayList();
	protected static List	clients		= new ArrayList();
	
	protected static AEMonitor 		class_mon 	= new AEMonitor( "TRTrackerClientFactory" );

	public static TRTrackerAnnouncer
	create(
		TOTorrent		torrent,
		String[]		networks,
		boolean			manual )
		
		throws TRTrackerAnnouncerException
	{
		TRTrackerAnnouncer	client;
		
		if ( TorrentUtils.isDecentralised( torrent )){
			
			client	= new TRTrackerDHTAnnouncerImpl( torrent, networks );
			
		}else{
			
			client = new TRTrackerBTAnnouncerImpl( torrent, networks, manual );
		}
		
		List	listeners_copy	= new ArrayList();
		
		try{
			class_mon.enter();
			
			clients.add( client );
		
			listeners_copy = new ArrayList( listeners );
	
		}finally{
			
			class_mon.exit();
		}
		
		for (int i=0;i<listeners_copy.size();i++){
			
			try{
				((TRTrackerAnnouncerFactoryListener)listeners_copy.get(i)).clientCreated( client );
				
			}catch( Throwable e ){
				
				Debug.printStackTrace(e);
			}
		}
		
		return( client );
	}
	
		/*
		 * At least once semantics for this one
		 */
	
	public static void
	addListener(
		 TRTrackerAnnouncerFactoryListener	l )
	{
		List	clients_copy;
		
		try{
			class_mon.enter();
		
			listeners.add(l);
			
			clients_copy = new ArrayList( clients );
	
		}finally{
			
			class_mon.exit();
		}
		
		for (int i=0;i<clients_copy.size();i++){
			
			try{
				l.clientCreated((TRTrackerAnnouncer)clients_copy.get(i));
				
			}catch( Throwable e ){
				
				Debug.printStackTrace(e);
			}
		}
	}
	
	public static void
	removeListener(
		 TRTrackerAnnouncerFactoryListener	l )
	{
		try{
			class_mon.enter();
		
			listeners.remove(l);
			
		}finally{
			
			class_mon.exit();
		}
	}

	public static void
	destroy(
		TRTrackerAnnouncer	client )
	{
		List	listeners_copy	= new ArrayList();
		
		try{
			class_mon.enter();
		
			clients.remove( client );
			
			listeners_copy	= new ArrayList( listeners );

		}finally{
			
			class_mon.exit();
		}
		
		for (int i=0;i<listeners_copy.size();i++){
			
			try{
				((TRTrackerAnnouncerFactoryListener)listeners_copy.get(i)).clientDestroyed( client );
				
			}catch( Throwable e ){
				
				Debug.printStackTrace(e);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -