View Javadoc
1   //
2   // $Id$
3   //
4   // jupload - A file upload applet.
5   //
6   // Copyright 2010 The JUpload Team
7   //
8   // Created: 3 fevr. 2010
9   // Creator: etienne_sf
10  // Last modified: $Date$
11  //
12  // This program is free software; you can redistribute it and/or modify
13  // it under the terms of the GNU General Public License as published by
14  // the Free Software Foundation; either version 2 of the License, or
15  // (at your option) any later version.
16  //
17  // This program is distributed in the hope that it will be useful,
18  // but WITHOUT ANY WARRANTY; without even the implied warranty of
19  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  // GNU General Public License for more details.
21  //
22  // You should have received a copy of the GNU General Public License
23  // along with this program; if not, write to the Free Software
24  // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  
26  package wjhk.jupload2.upload;
27  
28  import wjhk.jupload2.exception.JUploadException;
29  
30  /**
31   * @author etienne_sf
32   * 
33   */
34  public interface FileUploadManagerThread {
35  
36  	/** Indicates that nothings has begun */
37  	public static final int UPLOAD_STATUS_NOT_STARTED = 1;
38  
39  	/**
40  	 * We're sending data to the server, for the file identified by
41  	 * numOfFileInCurrentUpload.
42  	 */
43  	public static final int UPLOAD_STATUS_UPLOADING = 2;
44  
45  	/**
46  	 * A chunk (a part) of the file identified by numOfFileInCurrentUpload has
47  	 * been sent. But the server response has not been received yet.
48  	 */
49  	public static final int UPLOAD_STATUS_CHUNK_UPLOADED_WAITING_FOR_RESPONSE = 3;
50  
51  	/**
52  	 * All data for the file identified by numOfFileInCurrentUpload has been
53  	 * sent. But the server response has not been received yet.
54  	 */
55  	public static final int UPLOAD_STATUS_FILE_UPLOADED_WAITING_FOR_RESPONSE = 4;
56  
57  	/**
58  	 * The upload for the file identified by numOfFileInCurrentUpload is
59  	 * finished
60  	 */
61  	public static final int UPLOAD_STATUS_UPLOADED = 5;
62  
63  	/**
64  	 * The heart of the program. This method prepare the upload, then calls
65  	 * doUpload for each HTTP request.
66  	 * 
67  	 * @throws InterruptedException
68  	 * @see java.lang.Thread#join()
69  	 */
70  	public void join() throws InterruptedException;
71  
72  	/**
73  	 * The heart of the program. This method prepare the upload, then calls
74  	 * doUpload for each HTTP request.
75  	 * 
76  	 * @see java.lang.Thread#run()
77  	 */
78  	public void run();
79  
80  	/**
81  	 * The heart of the program. This method prepare the upload, then calls
82  	 * doUpload for each HTTP request.
83  	 * 
84  	 * @see java.lang.Thread#start()
85  	 */
86  	public void start();
87  
88  	/**
89  	 * Check if the thread is running...
90  	 * 
91  	 * @see java.lang.Thread#interrupt()
92  	 */
93  	public void interrupt();
94  
95  	/**
96  	 * Check if the thread is running...
97  	 * 
98  	 * @return True if it's running
99  	 * @see java.lang.Thread#isAlive()
100 	 */
101 	public boolean isAlive();
102 
103 	/**
104 	 * Stores the last upload exception that occurs. This method won't write to
105 	 * the log file.
106 	 * 
107 	 * @param uploadException
108 	 */
109 	public void setUploadException(JUploadException uploadException);
110 
111 	/**
112 	 * Get the last upload exception that occurs.
113 	 * 
114 	 * @return The last upload exception, or null if no exception occurs.
115 	 */
116 	public JUploadException getUploadException();
117 
118 	/**
119 	 * Indicates whether the upload is finished or not. As several conditions
120 	 * can make the upload being finished (all files uploaded, an error occured,
121 	 * the user stops the upload), a specific boolean is built. It's managed by
122 	 * the {@link #run()} method.
123 	 * 
124 	 * @return true if the upload is finished. False otherwise.
125 	 */
126 	public boolean isUploadFinished();
127 
128 	/**
129 	 * Indicates if the upload has been stopped by the user, or by any upload
130 	 * error. This method should not be used to know if it's the end of the
131 	 * upload. To do this, see {@link #isUploadFinished()}
132 	 * 
133 	 * @return true if the current upload has been asked to stop by the user,
134 	 *         false otherwise.
135 	 */
136 	public boolean isUploadStopped();
137 
138 	/**
139 	 * Used by the UploadFileData#uploadFile(java.io.OutputStream, long) for
140 	 * each uploaded buffer
141 	 * 
142 	 * @param nbBytes
143 	 *            Number of additional bytes that where uploaded.
144 	 * @param uploadFileData
145 	 *            The file that is currently being uploade (or null if no file
146 	 *            is being uploaded)
147 	 * @throws JUploadException
148 	 */
149 	public void nbBytesUploaded(long nbBytes, UploadFileData uploadFileData)
150 			throws JUploadException;
151 
152 	/**
153 	 * Indicate the current state of the upload, to allow a correct display of
154 	 * UPLOAD_STATUS_UPLOADED status. the upload progress bar.
155 	 * 
156 	 * @param uploadFilePacket
157 	 *            The current packet. This parameter is mandatory only for the
158 	 * @param uploadFileData
159 	 *            The file whose upload begins, is going on or is finished.
160 	 * @param uploadStatus
161 	 * @throws JUploadException
162 	 */
163 	public void setUploadStatus(UploadFilePacket uploadFilePacket,
164 			UploadFileData uploadFileData, int uploadStatus)
165 			throws JUploadException;
166 
167 	/**
168 	 * Reaction to the user click on the 'Stop' button, or any action from the
169 	 * user asking to stop the upload. The upload should go on for the current
170 	 * file, and stop before starting the next upload request to the server, to
171 	 * avoid strange problems on the server.
172 	 */
173 	public void stopUpload();
174 
175 	/**
176 	 * This method is called each time a new file is sent to the server. It's
177 	 * main aim is to allow a proper display of the progress bar. It is public,
178 	 * as upload is done in another thread, whose class maybe in another
179 	 * package.
180 	 * 
181 	 * @param uploadFilePacket
182 	 * @param newlyUploadedFileData
183 	 * @throws JUploadException
184 	 */
185 	public void anotherFileHasBeenSent(UploadFilePacket uploadFilePacket,
186 			UploadFileData newlyUploadedFileData) throws JUploadException;
187 
188 	/**
189 	 * This method is called when the server response for the upload indicates a
190 	 * success. It is public, as upload is done in another thread, whose class
191 	 * maybe in another package.
192 	 * 
193 	 * @param packet
194 	 *            The packet of files that was successfully uploaded.
195 	 * @throws JUploadException
196 	 */
197 	public void currentRequestIsFinished(UploadFilePacket packet)
198 			throws JUploadException;
199 
200 }