View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.plugin.limewire;
21  
22  import java.util.Hashtable;
23  import java.util.Iterator;
24  
25  import org.xnap.transfer.DownloadManager;
26  import org.xnap.transfer.UploadManager;
27  
28  import com.limegroup.gnutella.Downloader;
29  import com.limegroup.gnutella.Uploader;
30  
31  public class LimeWireTransferManager {
32      
33      //--- Constant(s) ---
34  
35      //--- Data field(s) ---
36  
37      //private static Logger logger = Logger.getLogger(LimeWireTransferManager.class);
38  
39  	private Hashtable downloadByResponse = new Hashtable();
40  	private Hashtable uploadByResponse = new java.util.Hashtable();
41  
42      //--- Constructor(s) ---
43      
44      public LimeWireTransferManager()
45      {
46      }
47  
48      //--- Method(s) ---
49  
50  	public void add(Downloader response)
51  	{
52  		LimeWireDownload download = new LimeWireDownload(response);
53  		downloadByResponse.put(response, download);
54  		DownloadManager.getInstance().add(download);
55  	}
56  
57  	public void add(Uploader response)
58  	{
59  		LimeWireUpload upload = new LimeWireUpload(response);
60  		uploadByResponse.put(response, upload);
61  		UploadManager.getInstance().add(upload);
62  	}
63  
64  	public void remove(Downloader response)
65  	{
66  		LimeWireDownload download 
67  			= (LimeWireDownload)downloadByResponse.get(response);
68  		if (download != null) {
69  			DownloadManager.getInstance().remove(download);
70  		}
71  	}
72  
73  	public void remove(Uploader response)
74  	{
75  		LimeWireUpload upload 
76  			= (LimeWireUpload)uploadByResponse.get(response);
77  		if (upload != null) {
78  			UploadManager.getInstance().remove(upload);
79  		}
80  	}
81  	
82  	public void removeAll()
83  	{
84  		for (Iterator i = downloadByResponse.keySet().iterator(); 
85  			 i.hasNext();) {
86  			remove((Downloader)i.next());
87  		}
88  		for (Iterator i = uploadByResponse.keySet().iterator(); 
89  			 i.hasNext();) {
90  			remove((Uploader)i.next());
91  		}
92  	}
93      
94  }