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 */
018
019package org.apache.oozie.util;
020
021import org.apache.oozie.command.XCommand;
022
023/**
024 * Instrument utilities.
025 */
026public class InstrumentUtils {
027
028    private static final String INSTRUMENTATION_JOB_GROUP = "jobs";
029
030    /**
031     * Convenience method to increment counters.
032     *
033     * @param group the group name.
034     * @param name the counter name.
035     * @param count increment count.
036     * @param instrumentation the {@link Instrumentation} instance
037     */
038    public static void incrCounter(String group, String name, int count, Instrumentation instrumentation) {
039        if (instrumentation != null) {
040            instrumentation.incr(group, name, count);
041        }
042    }
043
044    /**
045     * Used to increment command counters.
046     *
047     * @param name the name
048     * @param count the increment count
049     * @param instrumentation the {@link Instrumentation} instance
050     */
051    public static void incrCommandCounter(String name, int count, Instrumentation instrumentation) {
052        incrCounter(XCommand.INSTRUMENTATION_GROUP, name, count, instrumentation);
053    }
054
055    /**
056     * Used to increment job counters. The counter name s the same as the command name.
057     *
058     * @param name the name
059     * @param count the increment count
060     * @param instrumentation the {@link Instrumentation} instance
061     */
062    public static void incrJobCounter(String name, int count, Instrumentation instrumentation) {
063        incrCounter(INSTRUMENTATION_JOB_GROUP, name, count, instrumentation);
064    }
065}