Project

General

Profile

« Previous | Next » 

Revision 572

Added by berkley almost 24 years ago

added more locking support and support for remote update of files.

View differences:

src/edu/ucsb/nceas/metacat/MetacatReplication.java
117 117
        replicationDaemon.scheduleAtFixedRate(new ReplicationHandler(out), 0, 
118 118
                                              rate * 1000);
119 119
        out.println("Replication Handler Started");
120
        System.out.println("Replication Handler Started");
120 121
      }
122
      else if(((String[])params.get("action"))[0].equals("forcereplicate"))
123
      {
124
        replicationDaemon.schedule(new ReplicationHandler(out), 0);
125
      }
121 126
      else if(((String[])params.get("action"))[0].equals("update"))
122 127
      { //request an update list from the server
123 128
        handleUpdateRequest(out, params, response);
......
159 164
    {
160 165
      Connection conn = util.openDBConnection();
161 166
      String docid = ((String[])params.get("docid"))[0];
162
System.out.println("docid: " + docid);
163 167
      String remoteDateStr = ((String[])params.get("updatedate"))[0];
164 168
      DocumentImpl requestDoc = new DocumentImpl(conn, docid);
165 169

  
......
169 173
      remoteDate = formatter.parse(remoteDateStr, pos);
170 174
      pos = new ParsePosition(0);
171 175
      localDate = formatter.parse(localDateStr, pos);
172
System.out.println("remotedate: " + remoteDate.toString());
173
System.out.println("localdate: " + localDate.toString());
176

  
174 177
      if(remoteDate.compareTo(localDate) >= 0)
175 178
      {
176 179
        if(!fileLocks.contains(docid))
......
255 258
    }
256 259
    
257 260
  }
258
  
261

  
262
  /**
263
   * Initiates an update of all server in the xml_replication table.
264
   * the remote host sends an update date.  The local host (this method)
265
   * queries the db for any document that was updated after the update date
266
   * and returns a list of those documents to the remote host.  It also 
267
   * sends back a list of the files that were locally deleted.
268
   */
259 269
  private void handleUpdateRequest(PrintWriter out, Hashtable params, 
260 270
                                   HttpServletResponse response)
261 271
  {
src/edu/ucsb/nceas/metacat/DocumentImpl.java
761 761
      
762 762
      if(openingtag.equals("<lockgranted>"))
763 763
      {//the lock was granted go ahead with the insert
764
        if ( action.equals("UPDATE") ) 
765
        {
766
          // check for 'write' permission for 'user' to update this document
767
          if ( !hasWritePermission(conn, docid, user, group) ) 
768
          {
769
            throw new Exception("User " + user + 
770
                  " does not have permission to update XML Document #" + docid);
771
          }          
772
        }
773

  
774 764
        try 
775 765
        {
776 766
          XMLReader parser = initializeParser(conn,action,newdocid,user,serverCode);
......
787 777
            }
788 778
            AccessControlList aclobj = new AccessControlList(conn, newdocid, acl);
789 779
            conn.commit();
790
          }
780
          } 
791 781
          conn.setAutoCommit(true);
792

  
793 782
        } 
794 783
        catch (Exception e) 
795 784
        {
src/edu/ucsb/nceas/metacat/ReplicationHandler.java
190 190
        }
191 191
      }
192 192

  
193
      //update the last_update field for each server to the current date/time      
194
      SimpleDateFormat formatter = new SimpleDateFormat ("yy-MM-dd HH:mm:ss");
195
      java.util.Date newDate = new java.util.Date(System.currentTimeMillis());
196
      ParsePosition pos = new ParsePosition(0);
197
      String dateString = formatter.format(newDate);
198
      //System.out.println("dateString: " + dateString);
199
      StringBuffer sql = new StringBuffer();
200
      sql.append("update xml_replication set last_checked = to_date('");
201
      sql.append(dateString).append("', 'YY-MM-DD HH24:MI:SS')");
202
      //System.out.println("sql: " + sql.toString());
203
      pstmt = conn.prepareStatement(sql.toString());
204
      pstmt.executeUpdate();
205
      //conn.commit();
206
      System.out.println("last_checked updated: " + dateString);
193
      keys = serverList.keys();
194
      while(keys.hasMoreElements())
195
      {
196
        server = (String)(keys.nextElement()); 
197
        URL dateurl = new URL("http://" + server + "?action=gettime");
198
        String datexml = MetacatReplication.getURLContent(dateurl);
199
        System.out.println("datexml: " + datexml);
200
        String datestr = datexml.substring(11, datexml.indexOf('<', 11));
201
        System.out.println("datestr: " + datestr);
202
        StringBuffer sql = new StringBuffer();
203
        sql.append("update xml_replication set last_checked = to_date('");
204
        sql.append(datestr).append("', 'YY-MM-DD HH24:MI:SS') where ");
205
        sql.append("server like '").append(server).append("'");
206
        //System.out.println("sql: " + sql.toString());
207
        pstmt = conn.prepareStatement(sql.toString());
208
        pstmt.executeUpdate();
209
        //conn.commit();
210
        System.out.println("last_checked updated to " + datestr + " on " +
211
                            server);
212
      }
207 213
  
208 214
    }
209 215
    catch(Exception e)

Also available in: Unified diff