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 */ 017package org.apache.camel.management; 018 019import org.apache.camel.Exchange; 020import 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 */ 029public 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 processExchange(Exchange exchange) { 041 if (counter1.isStatisticsEnabled()) { 042 counter1.processExchange(exchange); 043 } 044 if (counter2.isStatisticsEnabled()) { 045 counter2.processExchange(exchange); 046 } 047 } 048 049 @Override 050 public void completedExchange(Exchange exchange, long time) { 051 if (counter1.isStatisticsEnabled()) { 052 counter1.completedExchange(exchange, time); 053 } 054 if (counter2.isStatisticsEnabled()) { 055 counter2.completedExchange(exchange, time); 056 } 057 } 058 059 @Override 060 public void failedExchange(Exchange exchange) { 061 if (counter1.isStatisticsEnabled()) { 062 counter1.failedExchange(exchange); 063 } 064 if (counter2.isStatisticsEnabled()) { 065 counter2.failedExchange(exchange); 066 } 067 } 068 069 @Override 070 public boolean isStatisticsEnabled() { 071 // this method is not used 072 return true; 073 } 074 075 @Override 076 public void setStatisticsEnabled(boolean statisticsEnabled) { 077 // this method is not used 078 } 079}