View Javadoc

1   package org.kuali.ole.docstore.process;
2   
3   import org.apache.camel.CamelContext;
4   import org.apache.camel.builder.LoggingErrorHandlerBuilder;
5   import org.apache.camel.impl.DefaultCamelContext;
6   import org.slf4j.Logger;
7   import org.slf4j.LoggerFactory;
8   
9   /**
10   * Class to Handle DocStore Processes.
11   *
12   * @author Rajesh Chowdary K
13   * @created Mar 15, 2012
14   */
15  public class DocStoreCamelContext {
16  
17      private static Logger                     log            = LoggerFactory.getLogger(BulkLoadHandler.class);
18      private static DocStoreCamelContext       handlerContext = null;
19      private        CamelContext               context        = null;
20      private        LoggingErrorHandlerBuilder errorHandler   = new LoggingErrorHandlerBuilder();
21  
22      private DocStoreCamelContext() {
23          context = new DefaultCamelContext();
24          try {
25              context.start();
26              log.info("DocStoreCamelContext Initialized");
27          }
28          catch (Exception e) {
29              log.error("Ingest Handler Service Starup Failed : ", e);
30              log.info(e.getMessage());
31          }
32      }
33  
34      /**
35       * Method to get Instance of DocStoreCamelContext.
36       *
37       * @return
38       */
39      public static DocStoreCamelContext getInstance() {
40          if (handlerContext == null) {
41              handlerContext = new DocStoreCamelContext();
42          }
43          return handlerContext;
44      }
45  
46      public boolean isRunning() {
47          return !context.isSuspended();
48      }
49  
50      public void resume() throws Exception {
51          if (context.isSuspended()) {
52              context.resume();
53          }
54      }
55  
56      public void suspend() throws Exception {
57          if (!context.isSuspended()) {
58              context.suspend();
59          }
60      }
61  
62      public void stop() {
63          try {
64              BulkLoadHandler.getInstance().stop();
65              context.stop();
66          }
67          catch (Exception e) {
68              log.error("Ingest Handler Service Cold Stop Failed : ", e);
69          }
70      }
71  
72      public CamelContext getCamelContext() {
73          return context;
74      }
75  
76      public LoggingErrorHandlerBuilder getErrorHandler() {
77          return errorHandler;
78      }
79  
80  }