source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/com/gs3/testGXT/server/ProgressBarHandshakeServiceImpl.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 3.0 KB
Line 
1package com.gs3.testGXT.server;
2
3import java.util.LinkedList;
4
5import com.google.gwt.user.server.rpc.RemoteServiceServlet;
6import com.gs3.testGXT.client.services.ProgressBarHandshakeService;
7import com.gs3.testGXT.server.Greenstone.GWTFileQueue;
8
9@SuppressWarnings("serial")
10public class ProgressBarHandshakeServiceImpl extends RemoteServiceServlet implements ProgressBarHandshakeService {
11
12 private static String DONE = "Completed";
13 private static String STOP = "Cancelled";
14 private static String WAITING = "Non-Completed";
15 private static String PROGRESS_TOKEN = "Token";
16
17 private final int CHUNK_SIZE = 150;
18 private final int SLIDING_WINDOW = 450;
19
20 //the synchronized object to be used for keeping track of job progress/long polling
21 private Object monitor = GWTFileQueue.monitor;
22
23 @Override
24 public LinkedList<String[]> shakeHands() {
25 // TODO Auto-generated method stub
26 synchronized (monitor) {
27 /** check that either the queue itself has contents,
28 * or that there is a currently active job in progress.
29 * The two part check is needed because items get culled
30 * from the queue before the job actually starts,
31 * rather than when the job is completed.
32 */
33 if(GWTFileQueue.files_in_queue != 0 || GWTFileQueue.isQueueBusy()) { //file hasn't finished copying
34 //System.err.println("Files in queue!);
35 GWTFileQueue.setAllowance(CHUNK_SIZE);
36 monitor.notify();
37 try {
38 monitor.wait(); //I think I have some sync issues: this should hopefully fix it
39 } catch (InterruptedException e) {
40 e.printStackTrace();
41 }
42 } else {
43 monitor.notify();
44 }
45
46 int full_count = GWTFileQueue.job_size;
47 int done_count = GWTFileQueue.done_size;
48
49 //ternary needed to account for the case where we get f(0)/f(0) => NaN - ie, empty files
50 double progress = full_count == 0 ? 0 : (float)done_count/(float)full_count;
51
52 LinkedList<String[]> str = new LinkedList<String[]>();
53
54 if(GWTFileQueue.files_in_queue == 0 && !GWTFileQueue.isQueueBusy()) {
55 System.err.println("Zero files in queue!");
56 GWTFileQueue.job_size = GWTFileQueue.done_size = 0;
57 /*if(GWTFileQueue.wasCancelled()) {
58 System.err.println("Cancelled!");
59 str.add(new String[] {STOP, "" + 0});
60 }
61 else {*/
62 //TODO: fix
63 str.add(new String[] {DONE, "1.0"});
64 System.err.println("Done with files (Completed)");
65 //}
66 return str;
67 }
68 else {
69 str.add(new String[] {WAITING, "" + progress});
70 }
71
72 //str -> [action] [source] (target)
73 //ie: copying myfile to mylocation
74 //ie: deleting myfile from myfolder
75 //ie: moving myfolder to myotherfolder
76 String token;
77 if((token = GWTFileQueue.currentJob) != null) {
78 token = "{0}%: " + token;
79 }
80 else
81 token = "Transfer in progress - {0}% Complete";
82
83 str.add(new String[] {PROGRESS_TOKEN, token});
84
85 System.err.println("Progress: " + progress);
86
87 if(GWTFileQueue.files_in_queue != 0) {
88 GWTFileQueue.setAllowance(SLIDING_WINDOW);
89 }
90
91 return str;
92 }
93 }
94}
Note: See TracBrowser for help on using the repository browser.