Repository: camel Updated Branches: refs/heads/master e4ba8a7bd -> 7558e631e
CAMEL-11353: Optimise - JMX Statistic split into specialized classes Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3081eda5 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3081eda5 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3081eda5 Branch: refs/heads/master Commit: 3081eda56bf9cdbda3c0641a38b264c80abc6257 Parents: e4ba8a7 Author: Claus Ibsen <davscl...@apache.org> Authored: Sun May 28 18:27:21 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun May 28 18:27:21 2017 +0200 ---------------------------------------------------------------------- .../management/DefaultManagementStrategy.java | 6 - .../camel/management/mbean/ManagedCounter.java | 6 +- .../mbean/ManagedPerformanceCounter.java | 42 +++--- .../camel/management/mbean/Statistic.java | 127 ++++--------------- .../management/mbean/StatisticCounter.java | 46 +++++++ .../camel/management/mbean/StatisticDelta.java | 45 +++++++ .../management/mbean/StatisticMaximum.java | 49 +++++++ .../management/mbean/StatisticMinimum.java | 49 +++++++ .../camel/management/mbean/StatisticValue.java | 47 +++++++ 9 files changed, 282 insertions(+), 135 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/3081eda5/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java index 6a46c61..c41b5d4 100644 --- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java +++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java @@ -24,7 +24,6 @@ import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; import org.apache.camel.ManagementStatisticsLevel; import org.apache.camel.management.event.DefaultEventFactory; -import org.apache.camel.management.mbean.Statistic; import org.apache.camel.model.ProcessorDefinition; import org.apache.camel.spi.EventFactory; import org.apache.camel.spi.EventNotifier; @@ -190,11 +189,6 @@ public class DefaultManagementStrategy extends ServiceSupport implements Managem } } - public Statistic createStatistic(String name, Object owner, Statistic.UpdateMode updateMode) { - // noop - return null; - } - @Deprecated public void setStatisticsLevel(ManagementStatisticsLevel level) { LOG.warn("Using @deprecated option statisticsLevel on ManagementStrategy. Configure this on ManagementAgent instead."); http://git-wip-us.apache.org/repos/asf/camel/blob/3081eda5/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCounter.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCounter.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCounter.java index f8fdc86..5605ae2 100644 --- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCounter.java +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCounter.java @@ -29,9 +29,9 @@ public abstract class ManagedCounter implements ManagedCounterMBean { protected Statistic resetTimestamp; public void init(ManagementStrategy strategy) { - this.exchangesTotal = new Statistic("org.apache.camel.exchangesTotal", this, Statistic.UpdateMode.COUNTER); - this.startTimestamp = new Statistic("org.apache.camel.startTimestamp", this, Statistic.UpdateMode.VALUE); - this.resetTimestamp = new Statistic("org.apache.camel.resetTimestamp", this, Statistic.UpdateMode.VALUE); + this.exchangesTotal = new StatisticCounter(); + this.startTimestamp = new StatisticValue(); + this.resetTimestamp = new StatisticValue(); long now = new Date().getTime(); startTimestamp.updateValue(now); resetTimestamp.updateValue(now); http://git-wip-us.apache.org/repos/asf/camel/blob/3081eda5/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java index 6e020c1..2ac6214 100644 --- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java @@ -55,25 +55,25 @@ public abstract class ManagedPerformanceCounter extends ManagedCounter implement public void init(ManagementStrategy strategy) { super.init(strategy); - this.exchangesCompleted = new Statistic("org.apache.camel.exchangesCompleted", this, Statistic.UpdateMode.COUNTER); - this.exchangesFailed = new Statistic("org.apache.camel.exchangesFailed", this, Statistic.UpdateMode.COUNTER); - this.exchangesInflight = new Statistic("org.apache.camel.exchangesInflight", this, Statistic.UpdateMode.COUNTER); - - this.failuresHandled = new Statistic("org.apache.camel.failuresHandled", this, Statistic.UpdateMode.COUNTER); - this.redeliveries = new Statistic("org.apache.camel.redeliveries", this, Statistic.UpdateMode.COUNTER); - this.externalRedeliveries = new Statistic("org.apache.camel.externalRedeliveries", this, Statistic.UpdateMode.COUNTER); - - this.minProcessingTime = new Statistic("org.apache.camel.minimumProcessingTime", this, Statistic.UpdateMode.MINIMUM); - this.maxProcessingTime = new Statistic("org.apache.camel.maximumProcessingTime", this, Statistic.UpdateMode.MAXIMUM); - this.totalProcessingTime = new Statistic("org.apache.camel.totalProcessingTime", this, Statistic.UpdateMode.COUNTER); - this.lastProcessingTime = new Statistic("org.apache.camel.lastProcessingTime", this, Statistic.UpdateMode.VALUE); - this.deltaProcessingTime = new Statistic("org.apache.camel.deltaProcessingTime", this, Statistic.UpdateMode.DELTA); - this.meanProcessingTime = new Statistic("org.apache.camel.meanProcessingTime", this, Statistic.UpdateMode.VALUE); - - this.firstExchangeCompletedTimestamp = new Statistic("org.apache.camel.firstExchangeCompletedTimestamp", this, Statistic.UpdateMode.VALUE); - this.firstExchangeFailureTimestamp = new Statistic("org.apache.camel.firstExchangeFailureTimestamp", this, Statistic.UpdateMode.VALUE); - this.lastExchangeCompletedTimestamp = new Statistic("org.apache.camel.lastExchangeCompletedTimestamp", this, Statistic.UpdateMode.VALUE); - this.lastExchangeFailureTimestamp = new Statistic("org.apache.camel.lastExchangeFailureTimestamp", this, Statistic.UpdateMode.VALUE); + this.exchangesCompleted = new StatisticCounter(); + this.exchangesFailed = new StatisticCounter(); + this.exchangesInflight = new StatisticCounter(); + + this.failuresHandled = new StatisticCounter(); + this.redeliveries = new StatisticCounter(); + this.externalRedeliveries = new StatisticCounter(); + + this.minProcessingTime = new StatisticMinimum(); + this.maxProcessingTime = new StatisticMaximum(); + this.totalProcessingTime = new StatisticCounter(); + this.lastProcessingTime = new StatisticValue(); + this.deltaProcessingTime = new StatisticDelta(); + this.meanProcessingTime = new StatisticValue(); + + this.firstExchangeCompletedTimestamp = new StatisticValue(); + this.firstExchangeFailureTimestamp = new StatisticValue(); + this.lastExchangeCompletedTimestamp = new StatisticValue(); + this.lastExchangeFailureTimestamp = new StatisticValue(); } @Override @@ -228,8 +228,8 @@ public abstract class ManagedPerformanceCounter extends ManagedCounter implement lastExchangeCompletedExchangeId = exchange.getExchangeId(); // update mean - long count = exchangesCompleted.getValue(); - long mean = count > 0 ? totalProcessingTime.getValue() / count : 0; + long count = exchangesCompleted.getUpdateCount(); + long mean = count > 0 ? totalProcessingTime.getValue() / exchangesCompleted.getValue() : 0; meanProcessingTime.updateValue(mean); } http://git-wip-us.apache.org/repos/asf/camel/blob/3081eda5/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java b/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java index aa866e0..63dc8a5 100644 --- a/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/Statistic.java @@ -16,92 +16,27 @@ */ package org.apache.camel.management.mbean; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.LongAdder; - /** - * Default implementation of {@link Statistic} + * Base implementation of {@link Statistic} + * <p/> + * The following modes is available: + * <ul> + * <li>VALUE - A statistic with this update mode is a simple value that is a straight forward + * representation of the updated value.</li> + * <li>DELTA - A statistic with this update mode is a value that represents the delta + * between the last two recorded values (or the initial value if two updates have + * not been recorded). This value can be negative if the delta goes up or down.</li> + * <li>COUNTER - A statistic with this update mode interprets updates as increments (positive values) + * or decrements (negative values) to the current value.</li> + * <li>MAXIMUM - A statistic with this update mode is a value that represents the maximum value + * amongst the update values applied to this statistic.</li> + * <li>MINIMUM - A statistic with this update mode is a value that represents the minimum value + * amongst the update values applied to this statistic.</li> + * <ul> */ -public class Statistic { - - /** - * Statistics mode - * <ul> - * <li>VALUE - A statistic with this update mode is a simple value that is a straight forward - * representation of the updated value.</li> - * <li>DELTA - A statistic with this update mode is a value that represents the delta - * between the last two recorded values (or the initial value if two updates have - * not been recorded). This value can be negative if the delta goes up or down.</li> - * <li>COUNTER - A statistic with this update mode interprets updates as increments (positive values) - * or decrements (negative values) to the current value.</li> - * <li>MAXIMUM - A statistic with this update mode is a value that represents the maximum value - * amongst the update values applied to this statistic.</li> - * <li>MINIMUM - A statistic with this update mode is a value that represents the minimum value - * amongst the update values applied to this statistic.</li> - * <ul> - */ - public enum UpdateMode { - VALUE, DELTA, COUNTER, MAXIMUM, MINIMUM - } +public abstract class Statistic { - private final UpdateMode updateMode; - private final AtomicLong value = new AtomicLong(); - private final AtomicLong lastValue; - private final LongAdder updateCount = new LongAdder(); - - /** - * Instantiates a new statistic. - * - * @param name name of statistic - * @param owner owner - * @param updateMode The statistic update mode. - */ - public Statistic(String name, Object owner, UpdateMode updateMode) { - this.updateMode = updateMode; - if (UpdateMode.DELTA == updateMode) { - this.lastValue = new AtomicLong(); - } else { - this.lastValue = null; - } - } - - public void updateValue(long newValue) { - switch (updateMode) { - case COUNTER: - value.addAndGet(newValue); - break; - case VALUE: - value.set(newValue); - break; - case DELTA: - if (updateCount.longValue() > 0) { - // remember previous value before updating it - lastValue.set(value.longValue()); - } - value.set(newValue); - break; - case MAXIMUM: - value.updateAndGet(value -> { - if (updateCount.longValue() == 0 || value < newValue) { - return newValue; - } else { - return value; - } - }); - break; - case MINIMUM: - value.updateAndGet(value -> { - if (updateCount.longValue() == 0 || value > newValue) { - return newValue; - } else { - return value; - } - }); - break; - default: - } - updateCount.add(1); - } + public abstract void updateValue(long newValue); public void increment() { updateValue(1); @@ -111,31 +46,13 @@ public class Statistic { updateValue(-1); } - public long getValue() { - if (updateMode == UpdateMode.DELTA) { - if (updateCount.longValue() == 0) { - return value.get(); - } else { - return value.get() - lastValue.get(); - } - } - return value.get(); - } + public abstract long getValue(); + @Deprecated public long getUpdateCount() { - return updateCount.longValue(); + return 0; } - public void reset() { - value.set(0); - if (lastValue != null) { - lastValue.set(0); - } - updateCount.reset(); - } - - public String toString() { - return "" + value.get(); - } + public abstract void reset(); } http://git-wip-us.apache.org/repos/asf/camel/blob/3081eda5/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java new file mode 100644 index 0000000..d947e6b --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticCounter.java @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.management.mbean; + +import java.util.concurrent.atomic.AtomicLong; + +public class StatisticCounter extends Statistic { + + private final AtomicLong value = new AtomicLong(0); + + public void updateValue(long newValue) { + value.addAndGet(newValue); + } + + public long getValue() { + return value.get(); + } + + @Override + public String toString() { + return "" + value.get(); + } + + public void reset() { + value.set(0); + } + + @Override + public long getUpdateCount() { + return value.get(); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/3081eda5/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticDelta.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticDelta.java b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticDelta.java new file mode 100644 index 0000000..b288972 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticDelta.java @@ -0,0 +1,45 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.management.mbean; + +import java.util.concurrent.atomic.AtomicLong; + +public class StatisticDelta extends Statistic { + + private final AtomicLong value = new AtomicLong(); + private final AtomicLong lastValue = new AtomicLong(); + + public void updateValue(long newValue) { + lastValue.set(value.longValue()); + value.set(newValue); + } + + public long getValue() { + return value.get() - lastValue.get(); + } + + @Override + public String toString() { + return "" + value.get(); + } + + public void reset() { + value.set(0); + lastValue.set(0); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/3081eda5/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMaximum.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMaximum.java b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMaximum.java new file mode 100644 index 0000000..d403370 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMaximum.java @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.management.mbean; + +import java.util.concurrent.atomic.AtomicLong; + +public class StatisticMaximum extends Statistic { + + private final AtomicLong value = new AtomicLong(-1); + + public void updateValue(long newValue) { + value.updateAndGet(value -> { + if (value == -1 || value < newValue) { + return newValue; + } else { + return value; + } + }); + } + + public long getValue() { + long num = value.get(); + return num == -1 ? 0 : num; + } + + @Override + public String toString() { + return "" + value.get(); + } + + public void reset() { + value.set(-1); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/3081eda5/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMinimum.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMinimum.java b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMinimum.java new file mode 100644 index 0000000..55b5a54 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticMinimum.java @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.management.mbean; + +import java.util.concurrent.atomic.AtomicLong; + +public class StatisticMinimum extends Statistic { + + private final AtomicLong value = new AtomicLong(-1); + + public void updateValue(long newValue) { + value.updateAndGet(value -> { + if (value == -1 || value > newValue) { + return newValue; + } else { + return value; + } + }); + } + + public long getValue() { + long num = value.get(); + return num == -1 ? 0 : num; + } + + @Override + public String toString() { + return "" + value.get(); + } + + public void reset() { + value.set(-1); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/3081eda5/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticValue.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticValue.java b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticValue.java new file mode 100644 index 0000000..6391799 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/StatisticValue.java @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.management.mbean; + +import java.util.concurrent.atomic.AtomicLong; + +public class StatisticValue extends Statistic { + + private final AtomicLong value = new AtomicLong(-1); + + public void updateValue(long newValue) { + value.set(newValue); + } + + public long getValue() { + return value.get(); + } + + @Override + public String toString() { + return "" + value.get(); + } + + @Override + public long getUpdateCount() { + return value.get() == -1 ? 0 : 1; + } + + public void reset() { + value.set(-1); + } + +}