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.management;
018
019 import org.apache.camel.Exchange;
020 import org.apache.camel.api.management.PerformanceCounter;
021
022 /**
023 * A composite {@link PerformanceCounter} is used for tracking performance statistics on both a per
024 * context and route level, by issuing callbacks on both when an event happens.
025 * <p/>
026 * This implementation is used so the {@link org.apache.camel.management.mbean.ManagedCamelContext}
027 * can aggregate all stats from the routes.
028 */
029 public class CompositePerformanceCounter implements PerformanceCounter {
030
031 private final PerformanceCounter counter1;
032 private final PerformanceCounter counter2;
033
034 public CompositePerformanceCounter(PerformanceCounter counter1, PerformanceCounter counter2) {
035 this.counter1 = counter1;
036 this.counter2 = counter2;
037 }
038
039 @Override
040 public void completedExchange(Exchange exchange, long time) {
041 if (counter1.isStatisticsEnabled()) {
042 counter1.completedExchange(exchange, time);
043 }
044 if (counter2.isStatisticsEnabled()) {
045 counter2.completedExchange(exchange, time);
046 }
047 }
048
049 @Override
050 public void failedExchange(Exchange exchange) {
051 if (counter1.isStatisticsEnabled()) {
052 counter1.failedExchange(exchange);
053 }
054 if (counter2.isStatisticsEnabled()) {
055 counter2.failedExchange(exchange);
056 }
057 }
058
059 @Override
060 public boolean isStatisticsEnabled() {
061 // this method is not used
062 return true;
063 }
064
065 @Override
066 public void setStatisticsEnabled(boolean statisticsEnabled) {
067 // this method is not used
068 }
069 }