Project

General

Profile

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
 *    Release: @release@
12
 *
13
 *   '$Author: berkley $'
14
 *     '$Date: 2001-01-18 15:15:21 -0800 (Thu, 18 Jan 2001) $'
15
 * '$Revision: 675 $'
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
 */
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
/**
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
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
  private boolean dbactionFlag = true;
56
  
57
  /**
58
   * @param docid the docid to force replicate
59
   * @param the action that is being performed on the document (either 
60
   *        INSERT or UPDATE)
61
   */
62
  public ForceReplicationHandler(String docid, String action)
63
  {
64
    this.docid = docid;
65
    this.action = action;
66
    if(this.action.equals(""))
67
    {
68
      dbactionFlag = false;
69
    }
70
    
71
    btThread = new Thread(this);
72
    btThread.setPriority(Thread.MIN_PRIORITY);
73
    btThread.start();
74
  }
75
  
76
  /**
77
   * Use this constructor when the action is implied.
78
   */
79
  public ForceReplicationHandler(String docid)
80
  {
81
    this.docid = docid;
82
    dbactionFlag = false;
83
    btThread = new Thread(this);
84
    btThread.setPriority(Thread.MIN_PRIORITY);
85
    btThread.start();
86
  }
87
  
88
  public void run()
89
  {
90
    //System.out.println("in ForceReplicationHandler Thread");
91
    try
92
    {
93
      URL comeAndGetIt;
94
      conn = util.openDBConnection();
95
      Enumeration keys = (ReplicationHandler.buildServerList(conn)).keys();
96
      //get the list of servers
97
      while(keys.hasMoreElements())
98
      {
99
        String server = (String)(keys.nextElement());
100
        if(dbactionFlag)
101
        {
102
          MetacatReplication.replLog("force replicating to " + server);
103
          comeAndGetIt = new URL("http://" + server + 
104
                                 "?action=forcereplicate&server=" + 
105
                                 util.getOption("server") + 
106
                                 util.getOption("replicationpath") +
107
                                 "&docid=" + docid + "&dbaction=" +
108
                                  action);
109
        }
110
        else
111
        {
112
          MetacatReplication.replLog("force replicating (default action) to )" + 
113
                                      server);
114
          comeAndGetIt = new URL("http://" + server + 
115
                                 "?action=forcereplicate&server=" + 
116
                                 util.getOption("server") + 
117
                                 util.getOption("replicationpath") +
118
                                 "&docid=" + docid);
119
        }
120
        MetaCatUtil.debugMessage("sending message: " + comeAndGetIt.toString());
121
        String message = MetacatReplication.getURLContent(comeAndGetIt);
122
        //send out the url.  message is a dummy variable as the target of
123
        //the URL never directly replies to the request.  this simply
124
        //invoces a read request from the server to this local machine.
125
      }
126
      conn.close();
127
    }
128
    catch(Exception e)
129
    {
130
      System.out.println("error in ForceReplicationHandler.run: " + 
131
                          e.getMessage());
132
      e.printStackTrace(System.out);
133
    }
134
    MetaCatUtil.debugMessage("exiting ForceReplicationHandler Thread");
135
  }
136
}
(28-28/43)