Project

General

Profile

« Previous | Next » 

Revision 573

Added by berkley about 24 years ago

added more replication/file locking functionality.

View differences:

src/edu/ucsb/nceas/metacat/MetacatReplication.java
73 73
                               HttpServletResponse response) 
74 74
                               throws ServletException, IOException 
75 75
  {
76
System.out.println("in metacatreplication");
76 77
    PrintWriter out = response.getWriter();
77
    
78 78
    Hashtable params = new Hashtable();
79 79
    Enumeration paramlist = request.getParameterNames();
80 80
    
......
121 121
      }
122 122
      else if(((String[])params.get("action"))[0].equals("forcereplicate"))
123 123
      {
124
        replicationDaemon.schedule(new ReplicationHandler(out), 0);
124
        String server = ((String[])params.get("server"))[0];
125
        int serverCheckCode = 0;
126
        try
127
        {
128
          serverCheckCode = MetacatReplication.getServerCode(server);
129
        }
130
        catch(Exception e)
131
        {
132
          System.out.println("error in metacatReplication.handleUpdateRequest"+
133
                             ": could not get server code");
134
        }
135
        replicationDaemon.schedule(new ReplicationHandler(out, serverCheckCode),
136
                                   2000);
125 137
      }
126 138
      else if(((String[])params.get("action"))[0].equals("update"))
127 139
      { //request an update list from the server
128
        handleUpdateRequest(out, params, response);
140
        if(params.contains("servercheckcode"))
141
        {
142
          System.out.println("metacatreplication: servercheckcode: " + 
143
                               ((int[])params.get("servercheckcode"))[0]);
144
          handleUpdateRequest(out, params, response, 
145
                              ((int[])params.get("servercheckcode"))[0]);
146
        }
147
        else
148
        {
149
          handleUpdateRequest(out, params, response);
150
        }
129 151
      }
130 152
      else if(((String[])params.get("action"))[0].equals("read"))
131 153
      { //request a specific document from the server
......
258 280
    }
259 281
    
260 282
  }
283
  
284
  /**
285
   * Does default handling for update requests
286
   */
287
  private void handleUpdateRequest(PrintWriter out, Hashtable params, 
288
                                   HttpServletResponse response)
289
  {
290
    handleUpdateRequest(out, params, response, 1);
291
  }
261 292

  
262 293
  /**
263 294
   * Initiates an update of all server in the xml_replication table.
......
265 296
   * queries the db for any document that was updated after the update date
266 297
   * and returns a list of those documents to the remote host.  It also 
267 298
   * sends back a list of the files that were locally deleted.
299
   
300
   * serverCheckCode allows the requestor to request documents from this 
301
   * server that reside on a different server.  Normally, this server
302
   * should only replicate files that it owns but in the case of updating 
303
   * a file that does not belong to this server, it is needed.  See 
304
   * DocumentImpl.write().
268 305
   */
269 306
  private void handleUpdateRequest(PrintWriter out, Hashtable params, 
270
                                   HttpServletResponse response)
271
  {
307
                                   HttpServletResponse response, 
308
                                   int serverCheckCode)
309
  { 
272 310
    System.out.println("incoming update request for dt/time " + 
273 311
                       ((String[])params.get("date"))[0] +
274 312
                       " from external metacat");
......
325 363
        String docid = rs.getString(1);
326 364
        String dateUpdated = rs.getString(2);
327 365
        int serverCode = rs.getInt(3);
328
        if(serverCode == 1)
366
        if(serverCode == serverCheckCode)
329 367
        { //check that this document is from this server.
330 368
          //servers only replicate their own documents!
331 369
          returnXML.append("<updatedDocument><docid>").append(docid);
src/edu/ucsb/nceas/metacat/DocumentImpl.java
735 735
  public static String write( Connection conn, Reader xml, Reader acl,
736 736
                              String action, String docid, String user,
737 737
                              String group, int serverCode )
738
                throws Exception {
738
                throws Exception 
739
  {
740
System.out.println("in write!!!!");
741
    MetaCatUtil util = new MetaCatUtil();
739 742
        // Determine if the docid is OK for INSERT or UPDATE
740 743
    AccessionNumber ac = new AccessionNumber(conn);
741 744
    String newdocid = ac.generate(docid, action);
......
790 793
        //after inserting the document locally, tell the document's home server
791 794
        //to come get a copy from here.
792 795
        URL comeAndGetIt = new URL("http://" + server + 
793
                                   "?action=forcereplicate&");
796
                                   "?action=forcereplicate&server=" + 
797
                                   util.getOption("server") + 
798
                                   util.getOption("replicationpath"));
799
        System.out.println("documentimpl url: " + comeAndGetIt.toString());
794 800
        String message = MetacatReplication.getURLContent(comeAndGetIt);
795 801
        
796 802
        if ( (docid != null) && !(newdocid.equals(docid)) ) 
src/edu/ucsb/nceas/metacat/ReplicationHandler.java
40 40
 */
41 41
public class ReplicationHandler extends TimerTask
42 42
{
43
  int serverCheckCode = 1;
43 44
  MetaCatUtil util = new MetaCatUtil();
44 45
  Hashtable serverList = new Hashtable(); 
45 46
  Connection conn;
......
50 51
    this.out = o;
51 52
  }
52 53
  
54
  public ReplicationHandler(PrintWriter o, int serverCheckCode)
55
  {
56
    this.out = o;
57
    this.serverCheckCode = serverCheckCode;
58
  }
59
  
53 60
  /**
54 61
   * Method that implements TimerTask.run().  It runs whenever the timer is 
55 62
   * fired.
......
115 122
        
116 123
        update = update.replace(' ', '+'); 
117 124
        
118
        u = new URL("http://" + server + "?action=update&date=" + update);
125
        if(serverCheckCode != 1)
126
        {
127
          u = new URL("http://" + server + "?action=update&date=" + update +
128
                      "&servercheckcode=" + serverCheckCode);
129
        }
130
        else
131
        {
132
          u = new URL("http://" + server + "?action=update&date=" + update);
133
        }
119 134
        responses.add(MetacatReplication.getURLContent(u)); //list of updates
120 135
      }
121 136

  

Also available in: Unified diff