001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 * 
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 * 
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.oozie.util;
019
020import org.apache.oozie.command.XCommand;
021
022/**
023 * Instrument utilities.
024 */
025public class InstrumentUtils {
026
027    private static final String INSTRUMENTATION_JOB_GROUP = "jobs";
028
029    /**
030     * Convenience method to increment counters.
031     *
032     * @param group the group name.
033     * @param name the counter name.
034     * @param count increment count.
035     * @param instrumentation the {@link Instrumentation} instance
036     */
037    public static void incrCounter(String group, String name, int count, Instrumentation instrumentation) {
038        if (instrumentation != null) {
039            instrumentation.incr(group, name, count);
040        }
041    }
042
043    /**
044     * Used to increment command counters.
045     *
046     * @param name the name
047     * @param count the increment count
048     * @param instrumentation the {@link Instrumentation} instance
049     */
050    public static void incrCommandCounter(String name, int count, Instrumentation instrumentation) {
051        incrCounter(XCommand.INSTRUMENTATION_GROUP, name, count, instrumentation);
052    }
053
054    /**
055     * Used to increment job counters. The counter name s the same as the command name.
056     *
057     * @param name the name
058     * @param count the increment count
059     * @param instrumentation the {@link Instrumentation} instance
060     */
061    public static void incrJobCounter(String name, int count, Instrumentation instrumentation) {
062        incrCounter(INSTRUMENTATION_JOB_GROUP, name, count, instrumentation);
063    }
064}