View Javadoc

1   package org.kuali.ole.docstore.process;
2   
3   import org.slf4j.Logger;
4   import org.slf4j.LoggerFactory;
5   
6   /**
7    * Created by IntelliJ IDEA.
8    * User: pvsubrah
9    * Date: 1/11/12
10   * Time: 6:40 AM
11   * To change this template use File | Settings | File Templates.
12   */
13  public class BulkLoadHandler {
14      private static Logger logger = LoggerFactory.getLogger(BulkLoadHandler.class);
15  
16      private        BulkIngestNIndexRouteBuilder bulkRoute   = null;
17      private static BulkLoadHandler              loadHandler = new BulkLoadHandler();
18  
19      private BulkLoadHandler() {
20      }
21  
22      public static BulkLoadHandler getInstance() {
23          return loadHandler;
24      }
25  
26      public synchronized void loadBulk(String folder, String user, String action) throws Exception {
27          if (bulkRoute == null) {
28              bulkRoute = new BulkIngestNIndexRouteBuilder(folder, user, action,
29                                                           DocStoreCamelContext.getInstance().getCamelContext());
30              bulkRoute.setErrorHandlerBuilder(DocStoreCamelContext.getInstance().getErrorHandler());
31              DocStoreCamelContext.getInstance().getCamelContext().addRoutes(bulkRoute);
32          }
33          else {
34              logger.warn("Bulk Ingest Process is Already Running @ " + folder);
35              throw new Exception("Bulk Ingest Process is Already Running @ " + folder);
36          }
37      }
38  
39      public synchronized void start() {
40          try {
41              bulkRoute.getFileEndPoint().start();
42          }
43          catch (Exception e) {
44              logger.error("Unable to Stop Bulk Ingest Process : ", e);
45          }
46      }
47  
48      public synchronized void stop() {
49          try {
50              if (bulkRoute != null && bulkRoute.getFileEndPoint() != null) {
51                  bulkRoute.getFileEndPoint().stop();
52              }
53          }
54          catch (Exception e) {
55              logger.error("Unable to Stop Bulk Ingest Process : ", e);
56          }
57      }
58  
59      public synchronized void remove() {
60          try {
61              bulkRoute.getFileEndPoint().shutdown();
62              bulkRoute = null;
63          }
64          catch (Exception e) {
65              logger.error("Unable to Stop Bulk Ingest Process : ", e);
66          }
67      }
68  
69      public String getStatus() {
70          if (bulkRoute != null) {
71              return bulkRoute.getFileEndPoint().getStatus().name();
72          }
73          else {
74              return null;
75          }
76      }
77  
78      public BulkIngestNIndexRouteBuilder getBulkRoute() {
79          return bulkRoute;
80      }
81  
82      public void setBulkRoute(BulkIngestNIndexRouteBuilder bulkRoute) {
83          this.bulkRoute = bulkRoute;
84      }
85  }