Project

General

Profile

« Previous | Next » 

Revision 567

Added by berkley about 24 years ago

created locking action in replication servlet and added semi-support to documentImpl to handle documents updatedee by replicatio

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
727 727
                              String action, String docid, String user,
728 728
                              String group, int serverCode )
729 729
                throws Exception {
730
System.out.println("outside of if: action: " + action + "servercode: " + serverCode);
730
System.out.println("action: " + action + " servercode: " + 
731
                    serverCode);
732

  
731 733
    if(serverCode != 1 && action.equals("UPDATE"))
732 734
    { //if this document being written is not a resident of this server then
733 735
      //we need to try to get a lock from it's resident server.  If the
734 736
      //resident server will not give a lock then we send the user a message
735 737
      //saying that he/she needs to download a new copy of the file and
736 738
      //merge the differences manually.
737
System.out.println("in if: action: " + action + "servercode: " + serverCode);
738
      int istreamInt;
739
      int istreamInt; 
739 740
      char istreamChar;
740 741
      DocumentImpl newdoc = new DocumentImpl(conn, docid);
741 742
      String update = newdoc.getUpdateDate();
742 743
      String server = MetacatReplication.getServer(serverCode);
743
      
744
      URL u = new URL("http://" + server + "?action=getlock&updatedate=" + update +
745
                  "&docid=" + docid);
744
      update = update.replace(' ', '+');
745
      URL u = new URL("http://" + server + "?action=getlock&updatedate=" + 
746
                      update + "&docid=" + docid);
747
      //System.out.println("url: " + u.toString());
746 748
      InputStreamReader istream = new InputStreamReader(u.openStream());
747 749
      StringBuffer serverResponse = new StringBuffer();
748 750
      while((istreamInt = istream.read()) != -1)
......
752 754
      }
753 755
      
754 756
      String serverResStr = serverResponse.toString();
755
      String openingtag = serverResStr.substring(0, serverResStr.indexOf(">"));
756
      System.out.println("openingtag: " + openingtag);
757
      System.out.println("serverResStr: " + serverResStr);
758
      String openingtag = serverResStr.substring(0, serverResStr.indexOf(">")+1);
759
      //System.out.println("openingtag: " + openingtag);
757 760
      if(openingtag.equals("<lockgranted>"))
758 761
      {//the lock was granted go ahead with the insert
759
        
762
        System.out.println("lock granted");
760 763
      }
761 764
      else if(openingtag.equals("<filelocked>"))
762 765
      {//the file is currently locked by another user
763 766
       //notify our user to wait a few minutes, check out a new copy and try
764 767
       //again.
765
        
768
        System.out.println("file locked");
766 769
      }
767 770
      else if(openingtag.equals("<outdatedfile>"))
768 771
      {//our file is outdated.  notify our user to check out a new copy of the
769 772
       //file and merge his version with the new version.
770
        
773
        System.out.println("outdated file");
771 774
      }
772 775
    }
773
    
776
 
774 777
    // Determine if the docid is OK for INSERT or UPDATE
775 778
    AccessionNumber ac = new AccessionNumber(conn);
776 779
    String newdocid = ac.generate(docid, action);
src/edu/ucsb/nceas/metacat/ReplicationHandler.java
197 197
            InputStreamReader isr = new InputStreamReader(
198 198
                                        docinfoUrl.openStream());
199 199
            StringBuffer docInfoBuffer = new StringBuffer();
200
            while((istreamInt = isr.read()) != 1)
200
            while((istreamInt = isr.read()) != -1)
201 201
            {
202 202
              istreamChar = (char)istreamInt;
203 203
              docInfoBuffer.append(istreamChar);
......
206 206
            docinfoParser.parse(new InputSource(new StringReader(
207 207
                                                docInfoBuffer.toString())));
208 208
            Hashtable docinfoHash = dih.getDocInfo();
209
            
210 209
            String newDocid = DocumentImpl.write(conn, 
211 210
                               new StringReader(serverResponse.toString())
212 211
                               /*getDocIstream*/, 

Also available in: Unified diff