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          } else {
33              logger.warn("Bulk Ingest Process is Already Running @ " + folder);
34              throw new Exception("Bulk Ingest Process is Already Running @ " + folder);
35          }
36      }
37  
38      public synchronized void start() {
39          try {
40              bulkRoute.getFileEndPoint().start();
41          } catch (Exception e) {
42              logger.error("Unable to Stop Bulk Ingest Process : ", e);
43          }
44      }
45  
46      public synchronized void stop() {
47          try {
48              if (bulkRoute != null && bulkRoute.getFileEndPoint() != null) {
49                  bulkRoute.getFileEndPoint().stop();
50              }
51          } catch (Exception e) {
52              logger.error("Unable to Stop Bulk Ingest Process : ", e);
53          }
54      }
55  
56      public synchronized void remove() {
57          try {
58              bulkRoute.getFileEndPoint().shutdown();
59              bulkRoute = null;
60          } catch (Exception e) {
61              logger.error("Unable to Stop Bulk Ingest Process : ", e);
62          }
63      }
64  
65      public String getStatus() {
66          if (bulkRoute != null) {
67              return bulkRoute.getFileEndPoint().getStatus().name();
68          } else {
69              return null;
70          }
71      }
72  
73      public BulkIngestNIndexRouteBuilder getBulkRoute() {
74          return bulkRoute;
75      }
76  
77      public void setBulkRoute(BulkIngestNIndexRouteBuilder bulkRoute) {
78          this.bulkRoute = bulkRoute;
79      }
80  }