Project

General

Profile

« Previous | Next » 

Revision 537

Added by berkley over 23 years ago

no message

View differences:

src/edu/ucsb/nceas/metacat/MetacatReplication.java
86 86
    if(params.containsKey("action"))
87 87
    {
88 88
      if(((String[])params.get("action"))[0].equals("stop"))
89
      {  
89
      { //stop the replication server
90 90
        replicationDaemon.cancel();
91 91
        out.println("Replication Handler Stopped");
92 92
      }
93 93
      else if(((String[])params.get("action"))[0].equals("start"))
94
      {
94
      { //start the replication server
95 95
        int rate;
96 96
        if(params.containsKey("rate"))
97 97
          rate = new Integer(
......
107 107
        out.println("Replication Handler Started");
108 108
      }
109 109
      else if(((String[])params.get("action"))[0].equals("update"))
110
      {
110
      { //request an update list from the server
111 111
        handleUpdateRequest(out, params, response);
112 112
      }
113
      else if(((String[])params.get("action"))[0].equals("update"))
114
      {
113
      else if(((String[])params.get("action"))[0].equals("getdocument"))
114
      { //request a specific document from the server
115
        //note that this could be replaced by a call to metacatServlet
116
        //handleGetDocumentAction().
115 117
        handleGetDocumentRequest(out, params, response);
116 118
      }
117 119
    }
......
128 130
      Connection conn = util.openDBConnection();
129 131
      DocumentImpl di = new DocumentImpl(conn, docid);
130 132
      response.setContentType("text/xml");
131
      out.println(di.toString());
133
      out.print(di.toString());
132 134
      conn.close();
133 135
    }
134 136
    catch(Exception e)
......
156 158
    //get the date/time from the requestor, query the db for any documents
157 159
    //that have an update date later than the requested date and send
158 160
    //those docids back to the requestor.  If there are no newer documents
159
    //then send back an up-to-date message.
161
    //then send back a null message.
160 162
    ///////////////////////////////////////////////////////////////////////
161 163
    
162 164
    //Timestamp update = Timestamp.valueOf(updateStr);
......
177 179
      pstmt.execute();
178 180
      ResultSet rs = pstmt.getResultSet();
179 181
      boolean tablehasrows = rs.next();
182
      String serverCode = util.getOption("servercode");
180 183
      returnXML.append("<server>").append(util.getOption("server"));
181 184
      returnXML.append(util.getOption("replicationpath"));
182 185
      returnXML.append("</server><updates>");
183 186
      while(tablehasrows)
184 187
      {
185
        returnXML.append("<updatedDocument><docid>").append(rs.getString(1));
186
        returnXML.append("</docid><date_updated>").append(rs.getString(2));
187
        returnXML.append("</date_updated></updatedDocument>");
188
        String docid = rs.getString(1);
189
        String dateUpdated = rs.getString(2);
190
        int dotIndex = docid.indexOf(".");
191
        if(docid.substring(0, dotIndex).equals(serverCode))
192
        { //check that this document is from this server.
193
          //servers only replicate their own documents!
194
          returnXML.append("<updatedDocument><docid>").append(docid);
195
          returnXML.append("</docid><date_updated>").append(dateUpdated);
196
          returnXML.append("</date_updated></updatedDocument>");
197
        }
188 198
        tablehasrows = rs.next();
189 199
      }
190 200
      returnXML.append("</updates></replication>");
src/edu/ucsb/nceas/metacat/ReplicationHandler.java
123 123

  
124 124
      //initialize the parser
125 125
      XMLReader parser = initParser(message);
126
      //System.out.println("response: " + responses.toString());
127
      //System.out.println("<--end response-->");
126 128
      for(int i=0; i<responses.size(); i++)
127 129
      { //parse the xml and get the result
128 130
        parser.parse(new InputSource(
......
142 144
          InputStreamReader getDocIstream = new InputStreamReader(
143 145
                                                getDocURL.openStream());
144 146

  
147
                                                //the following while loop should not be needed.  see the note
148
          //below before the DocumentImpl.write() call.
149
          serverResponse = new StringBuffer();
150
          while((istreamInt = getDocIstream.read()) != -1)
151
          {
152
            istreamChar = (char)istreamInt;
153
            serverResponse.append(istreamChar);
154
          }
155
          //System.out.println("<<<<<<document>>>>>");
156
          //System.out.println(serverResponse.toString());
157
          //System.out.println("<<<<<<end document>>>>>");
158
          
145 159
          //update the document into the DB
146 160
          String action = getAction(docid);
147
          String newDocid = DocumentImpl.write(conn, getDocIstream, action, 
161
          //System.out.println("action: " + action + " docid: " + docid);
162
          
163
          //note that getDocIstream is commented out below.  This should
164
          //work as a param to this method but it doesn'.  I don't know why
165
          //but putting a string reader there works but not an 
166
          //inputStreamReader.
167
          String newDocid = DocumentImpl.write(conn, 
168
                                               new StringReader(serverResponse.toString())
169
                                               /*getDocIstream*/, 
170
                                               action, 
148 171
                                               docid, null, null);
149
          //System.out.println("newDocid: " + newDocid);
172
          System.out.println("newDocid: " + newDocid + " " + action + "ED");
150 173
        }
151 174
      }
152 175
      //update the last_update field for each server to the current date/time

Also available in: Unified diff