Coverage Report - org.apache.camel.bam.rules.ActivityRules
 
Classes in this File Line Coverage Branch Coverage Complexity
ActivityRules
82% 
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 org.apache.camel.Exchange;
 20  
 import org.apache.camel.bam.ProcessBuilder;
 21  
 import org.apache.camel.bam.model.ActivityDefinition;
 22  
 import org.apache.camel.bam.model.ActivityState;
 23  
 import org.apache.camel.bam.model.ProcessInstance;
 24  
 import org.apache.camel.impl.ServiceSupport;
 25  
 import org.apache.camel.util.ServiceHelper;
 26  
 import org.apache.commons.logging.Log;
 27  
 import org.apache.commons.logging.LogFactory;
 28  
 
 29  
 import java.util.ArrayList;
 30  
 import java.util.List;
 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  1
     private static final transient Log log = LogFactory.getLog(ActivityRules.class);
 39  3
     private int expectedMessages = 1;
 40  
     private ProcessRules processRules;
 41  3
     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  3
     public ActivityRules(ProcessBuilder builder) {
 47  3
         this.builder = builder;
 48  3
         this.processRules = builder.getProcessRules();
 49  3
         processRules.getActivities().add(this);
 50  3
     }
 51  
 
 52  
     public void addRule(TemporalRule rule) {
 53  1
         rules.add(rule);
 54  1
     }
 55  
 
 56  
     /**
 57  
      * Handles overdue activities
 58  
      */
 59  
     public void processExpired(ActivityState activityState) throws Exception {
 60  3
         for (TemporalRule rule : rules) {
 61  1
             rule.processExpired(activityState);
 62  1
         }
 63  3
     }
 64  
 
 65  
     public void processExchange(Exchange exchange, ProcessInstance process) {
 66  3
         for (TemporalRule rule : rules) {
 67  1
             rule.processExchange(exchange, process);
 68  1
         }
 69  3
     }
 70  
 
 71  
     // Properties
 72  
     //-------------------------------------------------------------------------
 73  
 
 74  
     public ActivityDefinition getActivityDefinition() {
 75  4
         if (activityDefinition == null) {
 76  2
             activityDefinition = builder.findOrCreateActivityDefinition(activityName);
 77  
         }
 78  4
         return activityDefinition;
 79  
     }
 80  
 
 81  
     public void setActivityDefinition(ActivityDefinition activityDefinition) {
 82  0
         this.activityDefinition = activityDefinition;
 83  0
     }
 84  
 
 85  
     public int getExpectedMessages() {
 86  1
         return expectedMessages;
 87  
     }
 88  
 
 89  
     public void setExpectedMessages(int expectedMessages) {
 90  0
         this.expectedMessages = expectedMessages;
 91  0
     }
 92  
 
 93  
     public ProcessRules getProcessRules() {
 94  3
         return processRules;
 95  
     }
 96  
 
 97  
     public void setActivityName(String activityName) {
 98  6
         this.activityName = activityName;
 99  6
     }
 100  
 
 101  
     // Implementation methods
 102  
     //-------------------------------------------------------------------------
 103  
     protected void doStart() throws Exception {
 104  3
         ServiceHelper.startServices(rules);
 105  3
     }
 106  
 
 107  
     protected void doStop() throws Exception {
 108  0
         ServiceHelper.stopServices(rules);
 109  0
     }
 110  
 }