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.transfer;
21  
22  import java.io.File;
23  
24  import javax.swing.Action;
25  import javax.swing.Icon;
26  
27  import org.xnap.event.StateListener;
28  import org.xnap.peer.Peer;
29  import org.xnap.plugin.Plugin;
30  
31  /***
32   * Defines the requirements for classes that transfer data to or from a peer.
33   */
34  public interface Transfer {
35  
36      //--- Constant(s) ---
37  
38      /***
39       * Transfers should be stopped, if stalled for this long.
40       */
41      int TRANSFER_TIMEOUT = 2 * 60 * 1000;
42  
43      //--- Method(s) ---
44  
45      /***
46       * Adds a status listener.
47       */
48      void addStateListener(StateListener l);
49  
50  	/***
51  	 * Invoked after the transfer was removed from the transfer manager
52  	 * because isDone == true.
53  	 */
54  	void cleared();
55  
56      /***
57       * Returns the actions that can performed by the transfer.
58       */
59      Action[] getActions();
60  
61      /***
62       * Returns the averate transfer rate.
63       *
64       * @return byte / s
65       */
66      long getAverageRate();
67  
68      /***
69       * Returns the current transfer rate.
70       *
71       * @return byte / s
72       */
73      long getCurrentRate();
74  
75      /***
76       * Returns html formatted meta information that is displayed as a
77       * tooltip.
78       * 
79       * @return null, if no meta information is available
80       */
81      String getDescription();
82      
83      /***
84       * Returns the file the transfer is using.
85       *
86       * @return null, if file is unknown; the file, otherwise
87       */
88      File getFile();
89  
90      /***
91       * Returns the filename that should be presented to the user.
92       */
93      String getFilename();
94  
95      /***
96       * Returns the final filesize.
97       */
98      long getFilesize();
99  
100     /***
101      * Returns a 16x16 icon.
102      */
103     Icon getIcon();
104 
105     /***
106      * Returns the peer.
107      */
108     Peer getPeer(); 
109 
110     /***
111      * Returns the plugin.
112      */
113     Plugin getPlugin();
114 
115 	/***
116 	 * Returns the queue position.
117 	 *
118 	 * @return -1, if the transfer is not queued, the position otherwise.
119 	 */
120 	int getQueuePosition();
121 
122     /***
123      * Returns the remaining time until the download is finished.
124      *
125      * @return the remaining time in s or -1 if unknown
126      */
127     int getRemainingTime();
128 
129     /***
130      * Returns the segments for segmented downloads.
131      *
132      * @return null, if segments are not supported (which means that there
133      *         is only one segment that represents the whole file)
134      */
135     Segment[] getSegments();
136 
137     /***
138      * Returns the current status that should be presented to the user.
139      */
140     String getStatus();
141 
142     /***
143      * Returns how many bytes have been transferred.
144      * 
145      * @return number of transferred bytes
146      */
147     long getTotalBytesTransferred();
148 
149     /***
150      * Returns true if the transfer is finished.
151      *
152      * @return true, if thread has ended and the transfer can be cleared; 
153      *         false if, not yet started or still running
154      */
155     boolean isDone();
156 
157 //      /***
158 //       * Returns true if the transfer has failed.
159 //       *
160 //       * @return true, if done and failed; false, if not done or successful
161 //       */
162 //      boolean isFailed();
163 
164     /***
165      * Returns true if the transfer is running. 
166      *
167      * @return true, if data is transferred or a connect is in progress;
168      *         false, if queued, not yet started or done
169      */
170     boolean isRunning();
171 
172     /***
173      * Remove a state listener.
174      */
175     void removeStateListener(StateListener l);
176 
177 }