FileDocCategorySizeDatePackage
ShareTester.javaAPI DocAzureus 3.0.3.46777Thu Sep 23 07:24:48 BST 2004org.gudy.azureus2.pluginsimpl.local.sharing.test

ShareTester

public class ShareTester extends Object implements ShareManagerListener, Plugin, PluginListener

Fields Summary
protected static AESemaphore
init_sem
private static AEMonitor
class_mon
protected static ShareTester
singleton
protected Map
seed_transport_map
protected PluginInterface
plugin_interface
Constructors Summary
Methods Summary
public voidclosedownComplete()

	
public voidclosedownInitiated()

	
public static org.gudy.azureus2.pluginsimpl.local.sharing.test.ShareTestergetSingleton()

	
	
	  
	
	
		try{
			class_mon.enter();
		
			if ( singleton == null ){
				
				new AEThread( "plugin initialiser ")
				{
					public void
					runSupport()
					{
						PluginManager.registerPlugin( ShareTester.class );
		
						Properties props = new Properties();
						
						props.put( PluginManager.PR_MULTI_INSTANCE, "true" );
						
						PluginManager.startAzureus( PluginManager.UI_SWT, props );
					}
				}.start();
			
				init_sem.reserve();
			}
			
			return( singleton );
			
		}finally{
			
			class_mon.exit();
		}
	
public voidinitializationComplete()

		try{
			DownloadManager	dm = plugin_interface.getDownloadManager();
			
			dm.addListener(
					new DownloadManagerListener()
					{
						public void
						downloadAdded(
							final Download	download )
						{
							System.out.println("downloadAdded: " + download );
							
							download.addListener(
								new DownloadListener()
								{
									public void
									stateChanged(
										Download	dl,
										int			old,
										int			cur )
									{
										System.out.println( "statechange:" + old + "-> " + cur + "  (" + download + ")");
									}
					                public void
					                positionChanged(
					                    Download	download, 
					                    int old,
					                    int cur)
									{
										System.out.println( "statechange:" + old + "-> " + cur + "  (" + download + ")");
									}
								});
							
							download.addTrackerListener(
								new DownloadTrackerListener()
								{
									public void
									scrapeResult(
										DownloadScrapeResult result )
									{
										System.out.println( "scrapeResult:" + result.getSeedCount() + "/" + result.getNonSeedCount());
									}
									
									public void
									announceResult(
										DownloadAnnounceResult	result )
									{
										if ( result.getResponseType() == DownloadAnnounceResult.RT_SUCCESS ){
										
											System.out.println( "announceResult:" + result.getReportedPeerCount() + "/" + result.getSeedCount() + "/" + result.getNonSeedCount());
											
										}else{
											
											System.out.println( "announceResult:" + result.getError());
										}
									}								
								});
							
							download.addPeerListener(
								new DownloadPeerListener()
								{
									public void
									peerManagerAdded(
										Download		download,
										PeerManager		peer_manager )
									{
										peer_manager.addListener(
											new PeerManagerListener()
											{											
												public void
												peerAdded(
													PeerManager	manager,
													Peer		peer )
												{
													System.out.println( "peerAdded:" + peer.getIp());
												}
												
												public void
												peerRemoved(
													PeerManager	manager,
													Peer		peer )
												{
													System.out.println( "peerRemoved:" + peer.getIp());
												}
											});
									}
									
									public void
									peerManagerRemoved(
										Download		download,
										PeerManager		peer_manager )
									{
									}
								});
						}
						public void
						downloadRemoved(
							Download	download )
						{
							System.out.println("downloadRemoved" + download );
						}
					});
			
			ShareManager	sm = plugin_interface.getShareManager();
		
			sm.addListener( this );
			
			sm.initialise();
			
			// ShareResourceFile res = sm.addFile( new File("c:\\temp\\shares\\test.wmf"));
			// ShareResourceDirContents res = sm.addDirContents( new File("D:\\music\\cd1"), false);
			
			//Torrent t = res.getItem().getTorrent();
			
			//System.out.println( t.getHash());
			
		}catch( ShareException e ){
			
			Debug.printStackTrace( e );
		}catch( Throwable e ){
			
			Debug.printStackTrace( e );
		}
	
	
public voidinitialize(PluginInterface _pi)

	
		plugin_interface = _pi;
		
		singleton = this;
		
		init_sem.release();
		
		LoggerChannel log = plugin_interface.getLogger().getChannel("Plugin Test");
		
		log.log(LoggerChannel.LT_INFORMATION, "Plugin Initialised");
		
		plugin_interface.addListener( this );
	
public static voidmain(java.lang.String[] args)

		getSingleton();
	
public voidreportCurrentTask(java.lang.String task_description)

		System.out.println( task_description );
	
public voidreportProgress(int percent_complete)

	
public voidresourceAdded(ShareResource resource)

		System.out.println( "resource added:" + resource.getName());
		
		if ( resource.getType() == ShareResource.ST_DIR_CONTENTS ){
			
			ShareResourceDirContents c = (ShareResourceDirContents)resource;
			
			ShareResource[]	kids = c.getChildren();
			
			for (int i=0;i<kids.length;i++){
				
				System.out.println( "\t" + kids[i].getName());
			}
		}
	
public voidresourceDeleted(ShareResource resource)

		System.out.println( "resource deleted:" + resource.getName());
	
public voidresourceModified(ShareResource resource)

		System.out.println( "resource modified:" + resource.getName());