Revision 5269 branches/MULTITHREADING_DEVELOPMENT/libraries/libRemoteServices/src/org/gvsig/remoteClient/taskplanning/retrieving/URLRequest.java
URLRequest.java | ||
---|---|---|
24 | 24 |
private String file; |
25 | 25 |
private String fileName; |
26 | 26 |
private boolean locked; |
27 |
private int status; |
|
28 | 27 |
private Vector listeners = new Vector(); |
29 | 28 |
private RetrieveEvent event = new RetrieveEvent(); |
30 | 29 |
private URLRetrieveTask worker; |
... | ... | |
37 | 36 |
u += (file.charAt(0) == '/') ? file : "/"+file; |
38 | 37 |
return new URL(u); |
39 | 38 |
} |
39 |
|
|
40 | 40 |
/** |
41 | 41 |
* @return Returns the fileName. |
42 | 42 |
*/ |
43 | 43 |
public String getFileName() { |
44 | 44 |
return fileName; |
45 | 45 |
} |
46 |
|
|
46 | 47 |
/** |
47 | 48 |
* @param fileName The fileName to set. |
48 | 49 |
*/ |
49 | 50 |
public void setFileName(String fileName) { |
50 | 51 |
this.fileName = fileName; |
51 | 52 |
} |
53 |
|
|
52 | 54 |
/** |
53 | 55 |
* @return Returns the host. |
54 | 56 |
*/ |
55 | 57 |
public String getHost() { |
56 | 58 |
return host; |
57 | 59 |
} |
60 |
|
|
58 | 61 |
/** |
59 | 62 |
* @param host The host to set. |
60 | 63 |
*/ |
61 | 64 |
public void setHost(String host) { |
62 | 65 |
this.host = host; |
63 | 66 |
} |
67 |
|
|
64 | 68 |
/** |
65 | 69 |
* @return Returns the file. |
66 | 70 |
*/ |
67 | 71 |
public String getFile() { |
68 | 72 |
return file; |
69 | 73 |
} |
74 |
|
|
70 | 75 |
/** |
71 | 76 |
* @param page The file to set. |
72 | 77 |
*/ |
73 | 78 |
public void setFile(String page) { |
74 | 79 |
this.file = page; |
75 | 80 |
} |
81 |
|
|
76 | 82 |
/** |
77 | 83 |
* @return Returns the protocol. |
78 | 84 |
*/ |
79 | 85 |
public String getProtocol() { |
80 | 86 |
return protocol; |
81 | 87 |
} |
88 |
|
|
82 | 89 |
/** |
83 | 90 |
* @param protocol The protocol to set. |
84 | 91 |
*/ |
85 | 92 |
public void setProtocol(String protocol) { |
86 | 93 |
this.protocol = protocol; |
87 | 94 |
} |
95 |
|
|
88 | 96 |
/** |
89 | 97 |
* @return Returns the requestType. |
90 | 98 |
*/ |
91 | 99 |
public int getRequestType() { |
92 | 100 |
return requestType; |
93 | 101 |
} |
102 |
|
|
94 | 103 |
/** |
95 | 104 |
* @param requestType The requestType to set. |
96 | 105 |
*/ |
97 | 106 |
public void setRequestType(int requestType) { |
98 | 107 |
this.requestType = requestType; |
99 | 108 |
} |
109 |
|
|
100 | 110 |
/** |
101 | 111 |
* @return Returns the port. |
102 | 112 |
*/ |
103 | 113 |
public int getPort() { |
104 | 114 |
return port; |
105 | 115 |
} |
116 |
|
|
106 | 117 |
/** |
107 | 118 |
* @param port The port to set. |
108 | 119 |
*/ |
... | ... | |
110 | 121 |
this.port = port; |
111 | 122 |
} |
112 | 123 |
|
124 |
protected void lock() { |
|
125 |
locked = true; |
|
126 |
} |
|
127 |
|
|
128 |
protected void unlock() { |
|
129 |
locked = false; |
|
130 |
} |
|
131 |
|
|
132 |
protected synchronized void setStatus(int status) { |
|
133 |
event.setType(status); |
|
134 |
fireEvent(); |
|
135 |
} |
|
136 |
|
|
137 |
protected synchronized int getStatus() { |
|
138 |
return event.getType(); |
|
139 |
} |
|
140 |
|
|
141 |
public void addRetrieveListener(RetrieveListener l) { |
|
142 |
if (l!=null) |
|
143 |
listeners.add(l); |
|
144 |
} |
|
145 |
|
|
146 |
public void removeRetrieveListener(RetrieveListener l) { |
|
147 |
listeners.remove(l); |
|
148 |
if (listeners.size()==0) { |
|
149 |
// If no body listens at, then no body cares about the result; |
|
150 |
// cancel the job |
|
151 |
worker.cancel(); |
|
152 |
worker = null; |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
156 |
private void fireEvent() { |
|
157 |
while (locked) { /* wait*/System.out.println("I'm locked"); } |
|
158 |
|
|
159 |
Iterator it = listeners.iterator(); |
|
160 |
while (it.hasNext()) { |
|
161 |
RetrieveListener listener = (RetrieveListener) it.next(); |
|
162 |
listener.transferEventReceived(event); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
protected void setWorker(URLRetrieveTask worker) { |
|
167 |
this.worker = worker; |
|
168 |
} |
|
169 |
|
|
113 | 170 |
public int hashCode() { |
114 | 171 |
if (hashCode == 0) { |
115 | 172 |
int result = 17; |
... | ... | |
162 | 219 |
if (this.requestType != other.requestType) return false; |
163 | 220 |
return true; |
164 | 221 |
} |
165 |
|
|
166 |
protected void lock() { |
|
167 |
locked = true; |
|
168 |
} |
|
169 |
|
|
170 |
protected void unlock() { |
|
171 |
locked = false; |
|
172 |
} |
|
173 |
|
|
174 |
protected synchronized void setStatus(int status) { |
|
175 |
event.setType(status); |
|
176 |
fireEvent(); |
|
177 |
} |
|
178 |
|
|
179 |
protected synchronized int getStatus() { |
|
180 |
return event.getType(); |
|
181 |
} |
|
182 |
|
|
183 |
public void addRetrieveListener(RetrieveListener l) { |
|
184 |
if (l!=null) |
|
185 |
listeners.add(l); |
|
186 |
} |
|
187 |
|
|
188 |
public void removeRetrieveListener(RetrieveListener l) { |
|
189 |
listeners.remove(l); |
|
190 |
if (listeners.size()==0) |
|
191 |
// If no body listens then no body cares about the result; |
|
192 |
// cancel the job |
|
193 |
worker.cancel(); |
|
194 |
} |
|
195 |
|
|
196 |
private void fireEvent() { |
|
197 |
while (locked) { /* wait*/System.out.println("I'm locked"); } |
|
198 |
|
|
199 |
Iterator it = listeners.iterator(); |
|
200 |
while (it.hasNext()) { |
|
201 |
RetrieveListener listener = (RetrieveListener) it.next(); |
|
202 |
listener.transferEventReceived(event); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
protected void setWorker(URLRetrieveTask worker) { |
|
207 |
this.worker = worker; |
|
208 |
} |
|
209 |
} |
|
222 |
} |
Also available in: Unified diff