Revision 1022
Added by Jing Tao over 22 years ago
src/edu/ucsb/nceas/metacat/ForceReplicationHandler.java | ||
---|---|---|
52 | 52 |
private MetaCatUtil util = new MetaCatUtil(); |
53 | 53 |
private String docid; |
54 | 54 |
private String action; |
55 |
private boolean xmlDocument; |
|
55 | 56 |
private boolean dbactionFlag = true; |
56 | 57 |
|
58 |
|
|
57 | 59 |
/** |
58 | 60 |
* @param docid the docid to force replicate |
59 | 61 |
* @param the action that is being performed on the document (either |
60 | 62 |
* INSERT or UPDATE) |
61 | 63 |
*/ |
62 |
public ForceReplicationHandler(String docid, String action) |
|
64 |
public ForceReplicationHandler(String docid, String action, boolean xml )
|
|
63 | 65 |
{ |
64 | 66 |
this.docid = docid; |
65 | 67 |
this.action = action; |
68 |
this.xmlDocument =xml; |
|
69 |
|
|
66 | 70 |
if(this.action.equals("")) |
67 | 71 |
{ |
68 | 72 |
dbactionFlag = false; |
... | ... | |
76 | 80 |
/** |
77 | 81 |
* Use this constructor when the action is implied. |
78 | 82 |
*/ |
79 |
public ForceReplicationHandler(String docid) |
|
83 |
public ForceReplicationHandler(String docid, boolean xml)
|
|
80 | 84 |
{ |
81 | 85 |
this.docid = docid; |
86 |
this.xmlDocument = xml; |
|
82 | 87 |
dbactionFlag = false; |
83 | 88 |
btThread = new Thread(this); |
84 | 89 |
btThread.setPriority(Thread.MIN_PRIORITY); |
... | ... | |
90 | 95 |
//System.out.println("in ForceReplicationHandler Thread"); |
91 | 96 |
try |
92 | 97 |
{ |
93 |
URL comeAndGetIt; |
|
98 |
//check if the metacat was configured to hanldle replication |
|
99 |
if (!(util.getOption("replication")).equals("on")) |
|
100 |
{ |
|
101 |
return; |
|
102 |
} |
|
103 |
URL comeAndGetIt = null; |
|
94 | 104 |
conn = util.openDBConnection(); |
95 | 105 |
Enumeration keys = (ReplicationHandler.buildServerList(conn)).keys(); |
96 | 106 |
//get the list of servers |
... | ... | |
99 | 109 |
String server = (String)(keys.nextElement()); |
100 | 110 |
if(dbactionFlag) |
101 | 111 |
{ |
102 |
MetacatReplication.replLog("force replicating to " + server); |
|
103 |
comeAndGetIt = new URL("https://" + server + |
|
112 |
if (xmlDocument)// xml documents |
|
113 |
{ |
|
114 |
MetacatReplication.replLog("force xml replicating to " + server); |
|
115 |
comeAndGetIt = new URL("https://" + server + |
|
104 | 116 |
"?action=forcereplicate&server=" + |
105 | 117 |
util.getOption("server") + |
106 | 118 |
util.getOption("replicationpath") + |
107 | 119 |
"&docid=" + docid + "&dbaction=" + |
108 | 120 |
action); |
109 |
} |
|
121 |
} |
|
122 |
//It is data file and configured to handle data replication |
|
123 |
else if ((util.getOption("replication")).equals("on")) |
|
124 |
{ |
|
125 |
MetacatReplication.replLog("force data replicating to " + server); |
|
126 |
comeAndGetIt = new URL("https://" + server + |
|
127 |
"?action=forcereplicatedatafile&server=" + |
|
128 |
util.getOption("server") + |
|
129 |
util.getOption("replicationpath") + |
|
130 |
"&docid=" + docid + "&dbaction=" + |
|
131 |
action); |
|
132 |
|
|
133 |
}//else if |
|
134 |
|
|
135 |
}//if |
|
110 | 136 |
else |
111 | 137 |
{ |
112 | 138 |
MetacatReplication.replLog("force replicating (default action) to )" + |
113 | 139 |
server); |
114 |
comeAndGetIt = new URL("https://" + server + |
|
140 |
if (xmlDocument) |
|
141 |
{ |
|
142 |
comeAndGetIt = new URL("https://" + server + |
|
115 | 143 |
"?action=forcereplicate&server=" + |
116 | 144 |
util.getOption("server") + |
117 | 145 |
util.getOption("replicationpath") + |
118 | 146 |
"&docid=" + docid); |
119 |
} |
|
147 |
} |
|
148 |
//It is datafile and metacat is configured to handle data file |
|
149 |
else if ((util.getOption("replication")).equals("on")) |
|
150 |
{ |
|
151 |
comeAndGetIt = new URL("https://" + server + |
|
152 |
"?action=forcereplicatedatafile&server=" + |
|
153 |
util.getOption("server") + |
|
154 |
util.getOption("replicationpath") + |
|
155 |
"&docid=" + docid); |
|
156 |
}//else if |
|
157 |
}//else |
|
120 | 158 |
MetaCatUtil.debugMessage("sending message: " + comeAndGetIt.toString()); |
121 | 159 |
String message = MetacatReplication.getURLContent(comeAndGetIt); |
122 | 160 |
//send out the url. message is a dummy variable as the target of |
123 | 161 |
//the URL never directly replies to the request. this simply |
124 | 162 |
//invoces a read request from the server to this local machine. |
125 |
} |
|
163 |
}//while
|
|
126 | 164 |
conn.close(); |
127 |
} |
|
165 |
}//try
|
|
128 | 166 |
catch(Exception e) |
129 | 167 |
{ |
130 | 168 |
System.out.println("error in ForceReplicationHandler.run: " + |
Also available in: Unified diff
Adding handle force replication data file part.