Project

General

Profile

« Previous | Next » 

Revision 10102

Added by Jing Tao over 7 years ago

Call the cn.synchronize method asynchronously in the mn.updateSystemmetadata method.

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
154 154
import edu.ucsb.nceas.metacat.index.MetacatSolrEngineDescriptionHandler;
155 155
import edu.ucsb.nceas.metacat.index.MetacatSolrIndex;
156 156
import edu.ucsb.nceas.metacat.properties.PropertyService;
157
import edu.ucsb.nceas.metacat.restservice.v2.MNResourceHandler;
157 158
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
158 159
import edu.ucsb.nceas.metacat.util.DeleteOnCloseFileInputStream;
159 160
import edu.ucsb.nceas.metacat.util.DocumentUtil;
......
2639 2640
      }
2640 2641
      
2641 2642
      if(success) {
2643
          this.cn = D1Client.getCN();
2642 2644
          //TODO
2643 2645
          //notify the cns the synchornize the new system metadata.
2644
          this.cn = D1Client.getCN();
2645
          try {
2646
              if(this.cn == null)  {
2647
                  logMetacat.warn("updateSystemMetadata - can't get the instance of the CN. So the system metadata in CN can't be updated.");
2648
              } else {
2649
                  this.cn.synchronize(null, pid);
2646
          // run it in a thread to avoid connection timeout
2647
          Runnable runner = new Runnable() {
2648
              private CNode cNode = null;
2649
              private SystemMetadata sys = null;
2650
              private Identifier id = null;
2651
              @Override
2652
              public void run() {
2653
                  try {
2654
                      if(this.cNode == null)  {
2655
                          logMetacat.warn("MNodeService.updateSystemMetadata - can't get the instance of the CN. So can't call cn.synchronize to update the system metadata in CN.");
2656
                      } else if(id != null) {
2657
                          logMetacat.info("MNodeService.updateSystemMetadata - calling cn.synchornized in another thread for pid "+id.getValue());
2658
                          this.cNode.synchronize(null, id);
2659
                      } else {
2660
                          logMetacat.warn("MNodeService.updateSystemMetadata - can't update system metadata in CN can't be updated.");
2661
                      }
2662
                  } catch (BaseException e) {
2663
                      e.printStackTrace();
2664
                      logMetacat.error("It is a DataONEBaseException and its detail code is "+e.getDetail_code() +" and its code is "+e.getCode());
2665
                      logMetacat.error("Can't update the systemmetadata of pid "+id.getValue()+" in CNs through cn.synchronize method since "+e.getMessage(), e);
2666
                  } catch (Exception e) {
2667
                      e.printStackTrace();
2668
                      logMetacat.error("Can't update the systemmetadata of pid "+id.getValue()+" in CNs through cn.synchronize method since "+e.getMessage(), e);
2669
                  }
2670
                  
2671
                  // attempt to re-register the identifier (it checks if it is a doi)
2672
                  try {
2673
                      logMetacat.info("MNodeSerice.updateSystemMetadata - register doi if the pid "+sys.getIdentifier().getValue()+" is a doi");
2674
                      DOIService.getInstance().registerDOI(sys);
2675
                  } catch (Exception e) {
2676
                    logMetacat.warn("Could not [re]register DOI: " + e.getMessage(), e);
2677
                  }
2650 2678
              }
2651
          } catch (BaseException e) {
2652
              e.printStackTrace();
2653
              logMetacat.error("It is a DataONEBaseException and its detail code is "+e.getDetail_code() +" and its code is "+e.getCode());
2654
              logMetacat.error("Can't update the systemmetadata of pid "+pid.getValue()+" in CNs since "+e.getMessage());
2655
          } catch (Exception e) {
2656
              e.printStackTrace();
2657
              logMetacat.error("Can't update the systemmetadata of pid "+pid.getValue()+" in CNs since "+e.getMessage());
2679
              private Runnable init(CNode cn, SystemMetadata sys, Identifier id){
2680
                  this.cNode = cn;
2681
                  this.sys = sys;
2682
                  this.id = id;
2683
                  return this;
2684
                 
2685
              }
2686
          }.init(cn, sysmeta, pid);
2687
          // submit the task, and that's it
2688
          if(MNResourceHandler.getExecutorService() != null) {
2689
              MNResourceHandler.getExecutorService().submit(runner);
2690
          } else {
2691
              logMetacat.error("MNodeSerivce.updateSystemMetadata - since the executor service for submit the change to cn is null, the system metadata change of the id "+pid.getValue()+" can't go to cn by the method through cn.synchronize.");
2658 2692
          }
2659
          
2660
          // attempt to re-register the identifier (it checks if it is a doi)
2661
          try {
2662
        	  DOIService.getInstance().registerDOI(sysmeta);
2663
          } catch (Exception e) {
2664
  			logMetacat.warn("Could not [re]register DOI: " + e.getMessage(), e);
2665
          }
2666 2693
      }
2667 2694
      return success;
2668 2695
    }
src/edu/ucsb/nceas/metacat/restservice/v2/MNResourceHandler.java
1690 1690
        MNodeService.getInstance(request).updateSystemMetadata(session, pid, systemMetadata);
1691 1691
	}
1692 1692
	
1693
	
1693
	/**
1694
     * Get the executor from the service. 
1695
     * @return
1696
     */
1697
    public static ExecutorService getExecutorService() {
1698
        return executor;
1699
    }
1694 1700

  
1695 1701
}

Also available in: Unified diff