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: berkley $'
|
13
|
* '$Date: 2000-12-06 13:26:52 -0800 (Wed, 06 Dec 2000) $'
|
14
|
* '$Revision: 584 $'
|
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
|
MetacatReplication.replLog("force replicating to " + server);
|
81
|
comeAndGetIt = new URL("http://" + server +
|
82
|
"?action=forcereplicate&server=" +
|
83
|
util.getOption("server") +
|
84
|
util.getOption("replicationpath") +
|
85
|
"&docid=" + docid + "&dbaction=" +
|
86
|
action);
|
87
|
}
|
88
|
else
|
89
|
{
|
90
|
MetacatReplication.replLog("force replicating (default action) to )" +
|
91
|
server);
|
92
|
comeAndGetIt = new URL("http://" + server +
|
93
|
"?action=forcereplicate&server=" +
|
94
|
util.getOption("server") +
|
95
|
util.getOption("replicationpath") +
|
96
|
"&docid=" + docid);
|
97
|
}
|
98
|
//System.out.println("sending message: " + comeAndGetIt.toString());
|
99
|
String message = MetacatReplication.getURLContent(comeAndGetIt);
|
100
|
//send out the url. message is a dummy variable as the target of
|
101
|
//the URL never directly replies to the request. this simply
|
102
|
//invoces a read request from the server to this local machine.
|
103
|
}
|
104
|
conn.close();
|
105
|
}
|
106
|
catch(Exception e)
|
107
|
{
|
108
|
System.out.println("error in ForceReplicationHandler: " + e.getMessage());
|
109
|
e.printStackTrace(System.out);
|
110
|
}
|
111
|
//System.out.println("exiting ForceReplicationHandler Thread");
|
112
|
}
|
113
|
}
|