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,
|
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
|
* Copyright: 2000 Regents of the University of California and the
|
9
|
* National Center for Ecological Analysis and Synthesis
|
10
|
* Authors: Chad Berkley
|
11
|
*
|
12
|
* '$Author: daigle $'
|
13
|
* '$Date: 2009-08-24 13:34:17 -0800 (Mon, 24 Aug 2009) $'
|
14
|
* '$Revision: 5030 $'
|
15
|
*
|
16
|
* This program is free software; you can redistribute it and/or modify
|
17
|
* it under the terms of the GNU General Public License as published by
|
18
|
* the Free Software Foundation; either version 2 of the License, or
|
19
|
* (at your option) any later version.
|
20
|
*
|
21
|
* This program is distributed in the hope that it will be useful,
|
22
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
23
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
24
|
* GNU General Public License for more details.
|
25
|
*
|
26
|
* You should have received a copy of the GNU General Public License
|
27
|
* along with this program; if not, write to the Free Software
|
28
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
29
|
*/
|
30
|
|
31
|
package edu.ucsb.nceas.metacat.replication;
|
32
|
|
33
|
import java.net.URL;
|
34
|
|
35
|
import org.apache.log4j.Logger;
|
36
|
|
37
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
38
|
import edu.ucsb.nceas.metacat.util.MetacatUtil;
|
39
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
40
|
|
41
|
/**
|
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
|
* forces replication of system metadata
|
46
|
*/
|
47
|
public class ForceReplicationSystemMetadataHandler implements Runnable
|
48
|
{
|
49
|
private Thread btThread;
|
50
|
private String guid;
|
51
|
|
52
|
private ReplicationServerList serverLists = null;
|
53
|
|
54
|
private String notificationServer = null;
|
55
|
private static Logger logReplication = Logger.getLogger("ReplicationLogging");
|
56
|
private static Logger logMetacat = Logger.getLogger(ForceReplicationSystemMetadataHandler.class);
|
57
|
|
58
|
/**
|
59
|
* Use this constructor when the action is implied.
|
60
|
*/
|
61
|
public ForceReplicationSystemMetadataHandler(String guid, String myNotificationServer )
|
62
|
{
|
63
|
this.guid = guid;
|
64
|
// Build a severLists from xml_replication table
|
65
|
this.serverLists = new ReplicationServerList();
|
66
|
|
67
|
// Get notification server
|
68
|
this.notificationServer = myNotificationServer;
|
69
|
btThread = new Thread(this);
|
70
|
btThread.setPriority(Thread.MIN_PRIORITY);
|
71
|
btThread.start();
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* Method to send force replication command to other server to get
|
76
|
* a new or updated docid
|
77
|
*/
|
78
|
public void run()
|
79
|
{
|
80
|
|
81
|
|
82
|
// URL for notification
|
83
|
URL comeAndGetIt = null;
|
84
|
// If no server in xml_replication table we are done
|
85
|
if (serverLists.isEmpty()) {
|
86
|
return;
|
87
|
}
|
88
|
|
89
|
// Thread sleeping for some seconds to make sure the document was insert
|
90
|
// into the database before we send force replication request
|
91
|
int sleepTime;
|
92
|
try {
|
93
|
sleepTime = Integer.parseInt(PropertyService.getProperty("replication.forcereplicationwaitingtime"));
|
94
|
Thread.sleep(sleepTime);
|
95
|
} catch (PropertyNotFoundException pnfe) {
|
96
|
logMetacat.error(ReplicationService.METACAT_REPL_ERROR_MSG);
|
97
|
logReplication.error("Property error: " + pnfe.getMessage());
|
98
|
} catch (InterruptedException ie) {
|
99
|
logMetacat.error(ReplicationService.METACAT_REPL_ERROR_MSG);
|
100
|
logReplication.error("Thread sleep error: " + ie.getMessage());
|
101
|
}
|
102
|
logReplication.info("Notification server:" + notificationServer);
|
103
|
// Check every server in the serverlists
|
104
|
for (int i = 0; i < serverLists.size(); i++) {
|
105
|
//Set comeAndGetIt null
|
106
|
comeAndGetIt = null;
|
107
|
// Get ReplicationServer object in index i
|
108
|
ReplicationServer replicationServer = serverLists.serverAt(i);
|
109
|
// Get this ReplicationServer 's name
|
110
|
String server = replicationServer.getServerName();
|
111
|
try {
|
112
|
|
113
|
// If the server is the notification server, we don't notify it back
|
114
|
// again, if server is null we don't replicate to
|
115
|
if (server != null && !server.equals(notificationServer)) {
|
116
|
if (replicationServer.isSystemMetadataReplication()) {
|
117
|
comeAndGetIt = new URL("https://" + server
|
118
|
+ "?action=forcereplicatesystemmetadata"
|
119
|
+ "&guid=" + guid + "&server="
|
120
|
+ MetacatUtil.getLocalReplicationServerName());
|
121
|
|
122
|
logReplication.warn("Sending message: " + comeAndGetIt.toString());
|
123
|
String message = ReplicationService.getURLContent(comeAndGetIt);
|
124
|
}
|
125
|
}
|
126
|
} catch (Exception e) {
|
127
|
logMetacat.error(ReplicationService.METACAT_REPL_ERROR_MSG, e);
|
128
|
logReplication.error("Error forcing System Metadata replication");
|
129
|
}
|
130
|
|
131
|
}
|
132
|
|
133
|
logReplication.warn("Exiting Forced System Metadata Thread");
|
134
|
}
|
135
|
}
|