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.mbean; 018 019/** 020 * Base implementation of {@link Statistic} 021 * <p/> 022 * The following modes is available: 023 * <ul> 024 * <li>VALUE - A statistic with this update mode is a simple value that is a straight forward 025 * representation of the updated value.</li> 026 * <li>DELTA - A statistic with this update mode is a value that represents the delta 027 * between the last two recorded values (or the initial value if two updates have 028 * not been recorded). This value can be negative if the delta goes up or down.</li> 029 * <li>COUNTER - A statistic with this update mode interprets updates as increments (positive values) 030 * or decrements (negative values) to the current value.</li> 031 * <li>MAXIMUM - A statistic with this update mode is a value that represents the maximum value 032 * amongst the update values applied to this statistic.</li> 033 * <li>MINIMUM - A statistic with this update mode is a value that represents the minimum value 034 * amongst the update values applied to this statistic.</li> 035 * <ul> 036 * The MAXIMUM and MINIMUM modes are not 100% thread-safe as there can be a lost-update problem. 037 * This is on purpose because the performance overhead to ensure atomic updates costs to much 038 * on CPU and memory footprint. The other modes are thread-safe. 039 */ 040public abstract class Statistic { 041 042 public abstract void updateValue(long newValue); 043 044 public void increment() { 045 updateValue(1); 046 } 047 048 public void decrement() { 049 updateValue(-1); 050 } 051 052 public abstract long getValue(); 053 054 /** 055 * Whether the statistic has been updated one or more times. 056 * Notice this is only working for value, maximum and minimum modes. 057 */ 058 public abstract boolean isUpdated(); 059 060 public abstract void reset(); 061 062}