1 |
581
|
berkley
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
669
|
jones
|
* Purpose: A class to asyncronously force the replication of each server
|
4 |
|
|
* that has an entry in the xml_replication table. When run,
|
5 |
|
|
* this thread communicates with each server in the list and
|
6 |
|
|
* solicites a read of an updated or newly inserted document
|
7 |
|
|
* with a certain docid.
|
8 |
581
|
berkley
|
* Copyright: 2000 Regents of the University of California and the
|
9 |
|
|
* National Center for Ecological Analysis and Synthesis
|
10 |
669
|
jones
|
* Authors: Chad Berkley
|
11 |
|
|
* Release: @release@
|
12 |
581
|
berkley
|
*
|
13 |
669
|
jones
|
* '$Author$'
|
14 |
|
|
* '$Date$'
|
15 |
|
|
* '$Revision$'
|
16 |
|
|
*
|
17 |
|
|
* This program is free software; you can redistribute it and/or modify
|
18 |
|
|
* it under the terms of the GNU General Public License as published by
|
19 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
20 |
|
|
* (at your option) any later version.
|
21 |
|
|
*
|
22 |
|
|
* This program is distributed in the hope that it will be useful,
|
23 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
24 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
25 |
|
|
* GNU General Public License for more details.
|
26 |
|
|
*
|
27 |
|
|
* You should have received a copy of the GNU General Public License
|
28 |
|
|
* along with this program; if not, write to the Free Software
|
29 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
30 |
581
|
berkley
|
*/
|
31 |
|
|
|
32 |
|
|
package edu.ucsb.nceas.metacat;
|
33 |
|
|
|
34 |
|
|
import java.util.*;
|
35 |
|
|
import java.io.*;
|
36 |
|
|
import java.sql.*;
|
37 |
|
|
import java.net.*;
|
38 |
|
|
import java.lang.*;
|
39 |
|
|
import java.text.*;
|
40 |
|
|
|
41 |
669
|
jones
|
/**
|
42 |
|
|
* A class to asyncronously force the replication of each server
|
43 |
|
|
* that has an entry in the xml_replication table. When run,
|
44 |
|
|
* this thread communicates with each server in the list and
|
45 |
|
|
* solicites a read of an updated or newly inserted document
|
46 |
|
|
* with a certain docid.
|
47 |
|
|
*/
|
48 |
581
|
berkley
|
public class ForceReplicationHandler implements Runnable
|
49 |
|
|
{
|
50 |
|
|
private Thread btThread;
|
51 |
|
|
private Connection conn;
|
52 |
|
|
private MetaCatUtil util = new MetaCatUtil();
|
53 |
|
|
private String docid;
|
54 |
|
|
private String action;
|
55 |
1022
|
tao
|
private boolean xmlDocument;
|
56 |
581
|
berkley
|
private boolean dbactionFlag = true;
|
57 |
1040
|
tao
|
private Hashtable serverList;
|
58 |
581
|
berkley
|
|
59 |
1022
|
tao
|
|
60 |
581
|
berkley
|
/**
|
61 |
|
|
* @param docid the docid to force replicate
|
62 |
|
|
* @param the action that is being performed on the document (either
|
63 |
|
|
* INSERT or UPDATE)
|
64 |
|
|
*/
|
65 |
1040
|
tao
|
public ForceReplicationHandler(String docid, String action, boolean xml,
|
66 |
|
|
Hashtable server )
|
67 |
581
|
berkley
|
{
|
68 |
|
|
this.docid = docid;
|
69 |
|
|
this.action = action;
|
70 |
1022
|
tao
|
this.xmlDocument =xml;
|
71 |
1040
|
tao
|
this.serverList = server;
|
72 |
1022
|
tao
|
|
73 |
581
|
berkley
|
if(this.action.equals(""))
|
74 |
|
|
{
|
75 |
|
|
dbactionFlag = false;
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
btThread = new Thread(this);
|
79 |
|
|
btThread.setPriority(Thread.MIN_PRIORITY);
|
80 |
|
|
btThread.start();
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
/**
|
84 |
|
|
* Use this constructor when the action is implied.
|
85 |
|
|
*/
|
86 |
1040
|
tao
|
public ForceReplicationHandler(String docid, boolean xml, Hashtable server)
|
87 |
581
|
berkley
|
{
|
88 |
|
|
this.docid = docid;
|
89 |
1022
|
tao
|
this.xmlDocument = xml;
|
90 |
581
|
berkley
|
dbactionFlag = false;
|
91 |
1040
|
tao
|
this.serverList = server;
|
92 |
581
|
berkley
|
btThread = new Thread(this);
|
93 |
|
|
btThread.setPriority(Thread.MIN_PRIORITY);
|
94 |
|
|
btThread.start();
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
public void run()
|
98 |
|
|
{
|
99 |
|
|
//System.out.println("in ForceReplicationHandler Thread");
|
100 |
|
|
try
|
101 |
|
|
{
|
102 |
1022
|
tao
|
//check if the metacat was configured to hanldle replication
|
103 |
|
|
if (!(util.getOption("replication")).equals("on"))
|
104 |
|
|
{
|
105 |
|
|
return;
|
106 |
|
|
}
|
107 |
|
|
URL comeAndGetIt = null;
|
108 |
1030
|
tao
|
conn = util.getConnection();
|
109 |
|
|
// If no server in xml_replication table, metacat don't need do anything
|
110 |
|
|
if (ReplicationHandler.buildServerList(conn)==null)
|
111 |
|
|
{
|
112 |
|
|
return;
|
113 |
|
|
}
|
114 |
1040
|
tao
|
//Enumeration keys = (ReplicationHandler.buildServerList(conn)).keys();
|
115 |
|
|
//Make sure that server list is not empty
|
116 |
|
|
if (serverList==null || serverList.isEmpty())
|
117 |
|
|
{
|
118 |
|
|
return;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
Enumeration keys = serverList.keys();
|
122 |
581
|
berkley
|
//get the list of servers
|
123 |
|
|
while(keys.hasMoreElements())
|
124 |
|
|
{
|
125 |
|
|
String server = (String)(keys.nextElement());
|
126 |
|
|
if(dbactionFlag)
|
127 |
|
|
{
|
128 |
1022
|
tao
|
if (xmlDocument)// xml documents
|
129 |
|
|
{
|
130 |
|
|
MetacatReplication.replLog("force xml replicating to " + server);
|
131 |
|
|
comeAndGetIt = new URL("https://" + server +
|
132 |
581
|
berkley
|
"?action=forcereplicate&server=" +
|
133 |
|
|
util.getOption("server") +
|
134 |
|
|
util.getOption("replicationpath") +
|
135 |
|
|
"&docid=" + docid + "&dbaction=" +
|
136 |
|
|
action);
|
137 |
1022
|
tao
|
}
|
138 |
|
|
//It is data file and configured to handle data replication
|
139 |
1075
|
tao
|
else if ((util.getOption("replicationsenddata")).equals("on"))
|
140 |
1022
|
tao
|
{
|
141 |
|
|
MetacatReplication.replLog("force data replicating to " + server);
|
142 |
|
|
comeAndGetIt = new URL("https://" + server +
|
143 |
|
|
"?action=forcereplicatedatafile&server=" +
|
144 |
|
|
util.getOption("server") +
|
145 |
|
|
util.getOption("replicationpath") +
|
146 |
|
|
"&docid=" + docid + "&dbaction=" +
|
147 |
|
|
action);
|
148 |
|
|
|
149 |
|
|
}//else if
|
150 |
|
|
|
151 |
|
|
}//if
|
152 |
581
|
berkley
|
else
|
153 |
|
|
{
|
154 |
584
|
berkley
|
MetacatReplication.replLog("force replicating (default action) to )" +
|
155 |
|
|
server);
|
156 |
1022
|
tao
|
if (xmlDocument)
|
157 |
|
|
{
|
158 |
|
|
comeAndGetIt = new URL("https://" + server +
|
159 |
581
|
berkley
|
"?action=forcereplicate&server=" +
|
160 |
|
|
util.getOption("server") +
|
161 |
|
|
util.getOption("replicationpath") +
|
162 |
|
|
"&docid=" + docid);
|
163 |
1022
|
tao
|
}
|
164 |
|
|
//It is datafile and metacat is configured to handle data file
|
165 |
1075
|
tao
|
else if ((util.getOption("replicationsenddata")).equals("on"))
|
166 |
1022
|
tao
|
{
|
167 |
|
|
comeAndGetIt = new URL("https://" + server +
|
168 |
|
|
"?action=forcereplicatedatafile&server=" +
|
169 |
|
|
util.getOption("server") +
|
170 |
|
|
util.getOption("replicationpath") +
|
171 |
|
|
"&docid=" + docid);
|
172 |
|
|
}//else if
|
173 |
|
|
}//else
|
174 |
590
|
berkley
|
MetaCatUtil.debugMessage("sending message: " + comeAndGetIt.toString());
|
175 |
581
|
berkley
|
String message = MetacatReplication.getURLContent(comeAndGetIt);
|
176 |
|
|
//send out the url. message is a dummy variable as the target of
|
177 |
|
|
//the URL never directly replies to the request. this simply
|
178 |
|
|
//invoces a read request from the server to this local machine.
|
179 |
1022
|
tao
|
}//while
|
180 |
1030
|
tao
|
util.returnConnection(conn);
|
181 |
1022
|
tao
|
}//try
|
182 |
581
|
berkley
|
catch(Exception e)
|
183 |
|
|
{
|
184 |
675
|
berkley
|
System.out.println("error in ForceReplicationHandler.run: " +
|
185 |
|
|
e.getMessage());
|
186 |
581
|
berkley
|
e.printStackTrace(System.out);
|
187 |
|
|
}
|
188 |
590
|
berkley
|
MetaCatUtil.debugMessage("exiting ForceReplicationHandler Thread");
|
189 |
581
|
berkley
|
}
|
190 |
|
|
}
|