Coverage Report - org.apache.camel.bam.rules.ActivityRules
 
Classes in this File Line Coverage Branch Coverage Complexity
ActivityRules
81% 
100% 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.bam.rules;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 
 22  
 import org.apache.camel.Exchange;
 23  
 import org.apache.camel.bam.ProcessBuilder;
 24  
 import org.apache.camel.bam.model.ActivityDefinition;
 25  
 import org.apache.camel.bam.model.ActivityState;
 26  
 import org.apache.camel.bam.model.ProcessInstance;
 27  
 import org.apache.camel.impl.ServiceSupport;
 28  
 import org.apache.camel.util.ServiceHelper;
 29  
 import org.apache.commons.logging.Log;
 30  
 import org.apache.commons.logging.LogFactory;
 31  
 
 32  
 /**
 33  
  * Represents a activity which is typically a system or could be an endpoint
 34  
  *
 35  
  * @version $Revision: $
 36  
  */
 37  
 public class ActivityRules extends ServiceSupport {
 38  2
     private static final transient Log LOG = LogFactory.getLog(ActivityRules.class);
 39  4
     private int expectedMessages = 1;
 40  
     private ProcessRules processRules;
 41  4
     private List<TemporalRule> rules = new ArrayList<TemporalRule>();
 42  
     private ActivityDefinition activityDefinition;
 43  
     private String activityName;
 44  
     private final org.apache.camel.bam.ProcessBuilder builder;
 45  
 
 46  4
     public ActivityRules(ProcessBuilder builder) {
 47  4
         this.builder = builder;
 48  4
         this.processRules = builder.getProcessRules();
 49  4
         processRules.getActivities().add(this);
 50  4
     }
 51  
 
 52  
     public void addRule(TemporalRule rule) {
 53  2
         rules.add(rule);
 54  2
     }
 55  
 
 56  
     /**
 57  
      * Handles overdue activities
 58  
      */
 59  
     public void processExpired(ActivityState activityState) throws Exception {
 60  4
         for (TemporalRule rule : rules) {
 61  2
             rule.processExpired(activityState);
 62  2
         }
 63  4
     }
 64  
 
 65  
     public void processExchange(Exchange exchange, ProcessInstance process) {
 66  12
         for (TemporalRule rule : rules) {
 67  6
             rule.processExchange(exchange, process);
 68  6
         }
 69  12
     }
 70  
 
 71  
     // Properties
 72  
     //-------------------------------------------------------------------------
 73  
 
 74  
     public ActivityDefinition getActivityDefinition() {
 75  
         // lets always query for it, to avoid issues with refreshing before a commit etc
 76  22
         return builder.findOrCreateActivityDefinition(activityName);
 77  
     }
 78  
 
 79  
     public void setActivityDefinition(ActivityDefinition activityDefinition) {
 80  0
         this.activityDefinition = activityDefinition;
 81  0
     }
 82  
 
 83  
     public int getExpectedMessages() {
 84  6
         return expectedMessages;
 85  
     }
 86  
 
 87  
     public void setExpectedMessages(int expectedMessages) {
 88  0
         this.expectedMessages = expectedMessages;
 89  0
     }
 90  
 
 91  
     public ProcessRules getProcessRules() {
 92  16
         return processRules;
 93  
     }
 94  
 
 95  
     public void setActivityName(String activityName) {
 96  8
         this.activityName = activityName;
 97  8
     }
 98  
 
 99  
     // Implementation methods
 100  
     //-------------------------------------------------------------------------
 101  
     protected void doStart() throws Exception {
 102  4
         ServiceHelper.startServices(rules);
 103  4
     }
 104  
 
 105  
     protected void doStop() throws Exception {
 106  0
         ServiceHelper.stopServices(rules);
 107  0
     }
 108  
 }