View Javadoc
1   /*
2    * Copyright 2012 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.docstore.process;
17  
18  import org.apache.camel.Exchange;
19  import org.apache.camel.Predicate;
20  import org.kuali.ole.docstore.utility.BulkIngestStatistics;
21  import org.slf4j.Logger;
22  import org.slf4j.LoggerFactory;
23  
24  /**
25   * Class to predict split utility for processing.
26   *
27   * @author Rajesh Chowdary K
28   * @created Jun 11, 2012
29   */
30  public class SplitPredicate
31          implements Predicate {
32      private Logger logger = LoggerFactory.getLogger(SplitPredicate.class);
33      private Integer batchSize = 1000;
34      private BulkIngestStatistics bulkLoadStatistics = BulkIngestStatistics.getInstance();
35  
36      public SplitPredicate(Integer batchSize) {
37          this.batchSize = batchSize;
38      }
39  
40      public boolean matches(Exchange exchange) {
41  
42          if (exchange.getProperty("CamelSplitComplete") != null && Boolean.TRUE
43                  .equals(exchange.getProperty("CamelSplitComplete"))) {
44              logger.info("Processing End Of File: " + exchange.getProperty("CamelFileExchangeFile"));
45              bulkLoadStatistics.setLastBatch(true);
46              return true;
47          }
48  
49          if (exchange.getProperty("CamelAggregatedSize").equals(batchSize)) {
50              return true;
51          }
52  
53          return false;
54      }
55  }