Revision 568
Added by berkley about 24 years ago
src/edu/ucsb/nceas/metacat/MetacatReplication.java | ||
---|---|---|
136 | 136 |
{ |
137 | 137 |
handleGetDocumentInfoRequest(out, params, response); |
138 | 138 |
} |
139 |
else if(((String[])params.get("action"))[0].equals("gettime")) |
|
140 |
{ |
|
141 |
handleGetTimeRequest(out, params, response); |
|
142 |
} |
|
139 | 143 |
} |
140 | 144 |
} |
141 | 145 |
|
... | ... | |
155 | 159 |
{ |
156 | 160 |
Connection conn = util.openDBConnection(); |
157 | 161 |
String docid = ((String[])params.get("docid"))[0]; |
162 |
System.out.println("docid: " + docid); |
|
158 | 163 |
String remoteDateStr = ((String[])params.get("updatedate"))[0]; |
159 | 164 |
DocumentImpl requestDoc = new DocumentImpl(conn, docid); |
160 |
|
|
165 |
|
|
161 | 166 |
String localDateStr = requestDoc.getUpdateDate(); |
162 | 167 |
SimpleDateFormat formatter = new SimpleDateFormat ("yy-MM-dd HH:mm:ss"); |
163 | 168 |
ParsePosition pos = new ParsePosition(0); |
164 | 169 |
remoteDate = formatter.parse(remoteDateStr, pos); |
170 |
pos = new ParsePosition(0); |
|
165 | 171 |
localDate = formatter.parse(localDateStr, pos); |
172 |
System.out.println("remotedate: " + remoteDate.toString()); |
|
173 |
System.out.println("localdate: " + localDate.toString()); |
|
166 | 174 |
if(remoteDate.compareTo(localDate) >= 0) |
167 | 175 |
{ |
168 | 176 |
if(!fileLocks.contains(docid)) |
... | ... | |
188 | 196 |
catch(Exception e) |
189 | 197 |
{ |
190 | 198 |
System.out.println("error requesting file lock: " + e.getMessage()); |
199 |
e.printStackTrace(System.out); |
|
191 | 200 |
} |
192 | 201 |
} |
193 | 202 |
|
... | ... | |
346 | 355 |
} |
347 | 356 |
|
348 | 357 |
/** |
358 |
* Sends the current system date to the remote server. Using this action |
|
359 |
* for replication gets rid of any problems with syncronizing clocks |
|
360 |
* because a time specific to a document is always kept on its home server. |
|
361 |
*/ |
|
362 |
private void handleGetTimeRequest(PrintWriter out, Hashtable params, |
|
363 |
HttpServletResponse response) |
|
364 |
{ |
|
365 |
SimpleDateFormat formatter = new SimpleDateFormat ("yy-MM-dd HH:mm:ss"); |
|
366 |
java.util.Date localtime = new java.util.Date(); |
|
367 |
String dateString = formatter.format(localtime); |
|
368 |
response.setContentType("text/xml"); |
|
369 |
|
|
370 |
out.println("<timestamp>" + dateString + "</timestamp>"); |
|
371 |
} |
|
372 |
|
|
373 |
/** |
|
349 | 374 |
* This method is what is run when a seperate thread is broken off to handle |
350 | 375 |
* inserting a document from a remote replicated server. |
351 | 376 |
*/ |
... | ... | |
353 | 378 |
{ |
354 | 379 |
try |
355 | 380 |
{ |
381 |
System.out.println("thread started for docid: " + |
|
382 |
(String)fileLocks.elementAt(0)); |
|
356 | 383 |
Thread.sleep(30000); //the lock will expire in 30 seconds |
384 |
System.out.println("thread for docid: " + |
|
385 |
(String)fileLocks.elementAt(fileLocks.size() - 1) + |
|
386 |
" exiting."); |
|
357 | 387 |
fileLocks.remove(fileLocks.size() - 1); |
358 |
//the vector is treated as a FIFO queue. If there are more than one lock
|
|
388 |
//fileLocks is treated as a FIFO queue. If there are more than one lock
|
|
359 | 389 |
//in the vector, the first one inserted will be removed. |
360 | 390 |
} |
361 | 391 |
catch(Exception e) |
Also available in: Unified diff
updated insert handling and added an action to request the time from a remote server.