001/*
002 * ModeShape (http://www.modeshape.org)
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 */
016package org.modeshape.web.server.impl;
017
018import org.modeshape.jcr.api.monitor.DurationMetric;
019
020/**
021 *
022 * @author kulikov
023 */
024public class MsDurationMetric {
025    private final static MsDurationMetric[] METRICS = {
026        new MsDurationMetric(DurationMetric.QUERY_EXECUTION_TIME, "Query execution time"),
027        new MsDurationMetric(DurationMetric.SEQUENCER_EXECUTION_TIME, "Sequencer execution time"),
028        new MsDurationMetric(DurationMetric.SESSION_LIFETIME, "Session Life time")
029    };
030    
031    private DurationMetric metric;
032    private String title;
033
034    public MsDurationMetric(DurationMetric metric, String title) {
035        this.metric = metric;
036        this.title = title;
037    }
038
039    public DurationMetric metric() {
040        return metric;
041    }
042
043    public String title() {
044        return title;
045    }
046    
047    public static String[] getNames() {
048        String[] names = new String[METRICS.length];
049        for (int i = 0; i < names.length; i++) {
050            names[i] = METRICS[i].title();
051        }
052        return names;
053    }
054    
055    public static MsDurationMetric find( String name ) {
056        for (int i = 0; i < METRICS.length; i++) {
057            if (METRICS[i].title().equals(name)) {
058                return METRICS[i];
059            }
060        }
061        return null;
062    }
063    
064}