001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.bam; 018 019 import org.apache.camel.bam.model.ActivityDefinition; 020 import org.apache.camel.bam.model.ActivityState; 021 import org.apache.commons.logging.Log; 022 import org.apache.commons.logging.LogFactory; 023 024 import java.util.ArrayList; 025 import java.util.List; 026 027 /** 028 * Represents a activity which is typically a system or could be an endpoint 029 * 030 * @version $Revision: $ 031 */ 032 public class ActivityRules { 033 private static final transient Log log = LogFactory.getLog(ActivityRules.class); 034 private int expectedMessages = 1; 035 private ActivityDefinition activity; 036 private ProcessRules process; 037 private List<TemporalRule> rules = new ArrayList<TemporalRule>(); 038 private String activityName; 039 040 public ActivityRules(ProcessRules process) { 041 this.process = process; 042 process.getActivities().add(this); 043 } 044 045 public ActivityDefinition getActivity() { 046 return activity; 047 } 048 049 public void setActivity(ActivityDefinition activity) { 050 this.activity = activity; 051 } 052 053 public int getExpectedMessages() { 054 return expectedMessages; 055 } 056 057 public void setExpectedMessages(int expectedMessages) { 058 this.expectedMessages = expectedMessages; 059 } 060 061 public ProcessRules getProcess() { 062 return process; 063 } 064 065 /** 066 * Perform any assertions after the state has been updated 067 */ 068 public void processExchange(ActivityState activityState, ProcessContext context) { 069 070 log.info("Received state: " + activityState 071 + " message count " + activityState.getReceivedMessageCount() 072 + " started: " + activityState.getTimeStarted() 073 + " completed: " + activityState.getTimeCompleted()); 074 075 /* 076 process.fireRules(activityState, context); 077 078 for (TemporalRule rule : rules) { 079 rule.evaluate(context, activityState); 080 } 081 */ 082 } 083 084 public void setActivityName(String activityName) { 085 this.activityName = activityName; 086 } 087 088 public void addRule(TemporalRule rule) { 089 rules.add(rule); 090 } 091 092 /** 093 * Handles overdue activities 094 */ 095 public void processExpired(ActivityState activityState) throws Exception { 096 for (TemporalRule rule : rules) { 097 rule.processExpired(activityState); 098 } 099 } 100 }