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          } catch (Exception e) {
28              log.error("Ingest Handler Service Starup Failed : ", e);
29              log.info(e.getMessage());
30          }
31      }
32  
33      /**
34       * Method to get Instance of DocStoreCamelContext.
35       *
36       * @return
37       */
38      public static DocStoreCamelContext getInstance() {
39          if (handlerContext == null) {
40              handlerContext = new DocStoreCamelContext();
41          }
42          return handlerContext;
43      }
44  
45      public boolean isRunning() {
46          return !context.isSuspended();
47      }
48  
49      public void resume() throws Exception {
50          if (context.isSuspended()) {
51              context.resume();
52          }
53      }
54  
55      public void suspend() throws Exception {
56          if (!context.isSuspended()) {
57              context.suspend();
58          }
59      }
60  
61      public void stop() {
62          try {
63              BulkLoadHandler.getInstance().stop();
64              context.stop();
65          } catch (Exception e) {
66              log.error("Ingest Handler Service Cold Stop Failed : ", e);
67          }
68      }
69  
70      public CamelContext getCamelContext() {
71          return context;
72      }
73  
74      public LoggingErrorHandlerBuilder getErrorHandler() {
75          return errorHandler;
76      }
77  
78  }