Revision 581
Added by berkley about 24 years ago
src/edu/ucsb/nceas/metacat/ForceReplicationHandler.java | ||
---|---|---|
1 |
/** |
|
2 |
* '$RCSfile$' |
|
3 |
* Purpose: A class to asyncronously force the replication of each server |
|
4 |
* that has an entry in the xml_replication table. When run, this thread |
|
5 |
* communicates with each server in the list and solicites a read of an |
|
6 |
* updated or newly inserted document with a certain docid. |
|
7 |
* Copyright: 2000 Regents of the University of California and the |
|
8 |
* National Center for Ecological Analysis and Synthesis |
|
9 |
* Authors: Chad Berkley |
|
10 |
* Release: @release@ |
|
11 |
* |
|
12 |
* '$Author$' |
|
13 |
* '$Date$' |
|
14 |
* '$Revision$' |
|
15 |
*/ |
|
16 |
|
|
17 |
package edu.ucsb.nceas.metacat; |
|
18 |
|
|
19 |
import java.util.*; |
|
20 |
import java.io.*; |
|
21 |
import java.sql.*; |
|
22 |
import java.net.*; |
|
23 |
import java.lang.*; |
|
24 |
import java.text.*; |
|
25 |
|
|
26 |
public class ForceReplicationHandler implements Runnable |
|
27 |
{ |
|
28 |
private Thread btThread; |
|
29 |
private Connection conn; |
|
30 |
private MetaCatUtil util = new MetaCatUtil(); |
|
31 |
private String docid; |
|
32 |
private String action; |
|
33 |
private boolean dbactionFlag = true; |
|
34 |
|
|
35 |
/** |
|
36 |
* @param docid the docid to force replicate |
|
37 |
* @param the action that is being performed on the document (either |
|
38 |
* INSERT or UPDATE) |
|
39 |
*/ |
|
40 |
public ForceReplicationHandler(String docid, String action) |
|
41 |
{ |
|
42 |
this.docid = docid; |
|
43 |
this.action = action; |
|
44 |
if(this.action.equals("")) |
|
45 |
{ |
|
46 |
dbactionFlag = false; |
|
47 |
} |
|
48 |
|
|
49 |
btThread = new Thread(this); |
|
50 |
btThread.setPriority(Thread.MIN_PRIORITY); |
|
51 |
btThread.start(); |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Use this constructor when the action is implied. |
|
56 |
*/ |
|
57 |
public ForceReplicationHandler(String docid) |
|
58 |
{ |
|
59 |
this.docid = docid; |
|
60 |
dbactionFlag = false; |
|
61 |
btThread = new Thread(this); |
|
62 |
btThread.setPriority(Thread.MIN_PRIORITY); |
|
63 |
btThread.start(); |
|
64 |
} |
|
65 |
|
|
66 |
public void run() |
|
67 |
{ |
|
68 |
//System.out.println("in ForceReplicationHandler Thread"); |
|
69 |
try |
|
70 |
{ |
|
71 |
URL comeAndGetIt; |
|
72 |
conn = util.openDBConnection(); |
|
73 |
Enumeration keys = (ReplicationHandler.buildServerList(conn)).keys(); |
|
74 |
//get the list of servers |
|
75 |
while(keys.hasMoreElements()) |
|
76 |
{ |
|
77 |
String server = (String)(keys.nextElement()); |
|
78 |
if(dbactionFlag) |
|
79 |
{ |
|
80 |
comeAndGetIt = new URL("http://" + server + |
|
81 |
"?action=forcereplicate&server=" + |
|
82 |
util.getOption("server") + |
|
83 |
util.getOption("replicationpath") + |
|
84 |
"&docid=" + docid + "&dbaction=" + |
|
85 |
action); |
|
86 |
} |
|
87 |
else |
|
88 |
{ |
|
89 |
comeAndGetIt = new URL("http://" + server + |
|
90 |
"?action=forcereplicate&server=" + |
|
91 |
util.getOption("server") + |
|
92 |
util.getOption("replicationpath") + |
|
93 |
"&docid=" + docid); |
|
94 |
} |
|
95 |
//System.out.println("sending message: " + comeAndGetIt.toString()); |
|
96 |
String message = MetacatReplication.getURLContent(comeAndGetIt); |
|
97 |
//send out the url. message is a dummy variable as the target of |
|
98 |
//the URL never directly replies to the request. this simply |
|
99 |
//invoces a read request from the server to this local machine. |
|
100 |
} |
|
101 |
conn.close(); |
|
102 |
} |
|
103 |
catch(Exception e) |
|
104 |
{ |
|
105 |
System.out.println("error in ForceReplicationHandler: " + e.getMessage()); |
|
106 |
e.printStackTrace(System.out); |
|
107 |
} |
|
108 |
//System.out.println("exiting ForceReplicationHandler Thread"); |
|
109 |
} |
|
110 |
} |
|
0 | 111 |
Also available in: Unified diff
An asynchronous replication handler. This class creates a new thread to handle replication so that the user does not have to wait for replication to take place before he/she sees the result of an insert or update.