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