001/*
002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021package org.nuxeo.runtime.management.counters;
022
023import org.nuxeo.runtime.api.Framework;
024
025/**
026 * Dummy helper class to be used by code that updates the counters to avoid having to do the service lookup
027 *
028 * @author Tiry (tdelprat@nuxeo.com)
029 */
030public class CounterHelper {
031
032    protected static CounterManager cm = Framework.getLocalService(CounterManager.class);
033
034    public static void increaseCounter(String counterName) {
035        if (cm != null) {
036            cm.increaseCounter(counterName);
037        }
038    }
039
040    public static void increaseCounter(String counterName, long value) {
041        if (cm != null) {
042            cm.increaseCounter(counterName, value);
043        }
044    }
045
046    public static void setCounterValue(String counterName, long value) {
047        if (cm != null) {
048            cm.setCounterValue(counterName, value);
049        }
050    }
051
052    public static void decreaseCounter(String counterName) {
053        if (cm != null) {
054            cm.decreaseCounter(counterName);
055        }
056    }
057
058    public static void decreaseCounter(String counterName, long value) {
059        if (cm != null) {
060            cm.decreaseCounter(counterName, value);
061        }
062    }
063
064}