KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > manager > InstrumentSampleUtils


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 package org.apache.excalibur.instrument.manager;
21
22 import org.apache.avalon.framework.configuration.ConfigurationException;
23
24 /**
25  * A series of methods which are useful when working with InstrumentSamples.
26  * These methods can be used on the server as well as the client.
27  *
28  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
29  */

30 public class InstrumentSampleUtils
31 {
32     /**
33      * Resolves an instrument sample type based on a name.
34      *
35      * @param type Type of the InstrumentSample to resolve. Accepted values are:
36      * "max", "maximum", "min", "minimum", "mean",
37      * "ctr", and "counter".
38      *
39      * @throws ConfigurationException if the specified sample type is unknown.
40      */

41     public static int resolveInstrumentSampleType( String JavaDoc type )
42         throws ConfigurationException {
43         
44         if ( type.equalsIgnoreCase( "max" ) || type.equalsIgnoreCase( "maximum" ) )
45         {
46             return DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MAXIMUM;
47         }
48         else if ( type.equalsIgnoreCase( "min" ) || type.equalsIgnoreCase( "minimum" ) )
49         {
50             return DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MINIMUM;
51         }
52         else if ( type.equalsIgnoreCase( "mean" ) )
53         {
54             return DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MEAN;
55         }
56         else if ( type.equalsIgnoreCase( "ctr" ) || type.equalsIgnoreCase( "counter" ) )
57         {
58             return DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_COUNTER;
59         }
60         else
61         {
62             throw new ConfigurationException( "'" + type + "' is not a valid sample type." );
63         }
64     }
65     
66     public static String JavaDoc getInstrumentSampleTypeName( int type )
67     {
68         switch ( type )
69         {
70         case DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MAXIMUM:
71             return "maximum";
72             
73         case DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MINIMUM:
74             return "minimum";
75         
76         case DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MEAN:
77             return "mean";
78             
79         case DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_COUNTER:
80             return "counter";
81             
82         default:
83             return "unknown-" + type;
84         }
85     }
86     
87     /**
88      * Generates a sample name given its parameters.
89      *
90      * @param sampleType Type of the sample.
91      * @param sampleInterval Interval of the sample.
92      * @param sampleSize Size of the sample.
93      *
94      * @return A sample name.
95      */

96     public static String JavaDoc generateInstrumentSampleName( int sampleType,
97                                                        long sampleInterval,
98                                                        int sampleSize )
99     {
100         return getInstrumentSampleTypeName( sampleType ) + "_" +
101             sampleInterval + "_" + sampleSize;
102     }
103     
104     /**
105      * Generates a fully qualified sample name given its parameters.
106      *
107      * @param instrumentName Name of the instrument which owns the sample.
108      * @param sampleType Type of the sample.
109      * @param sampleInterval Interval of the sample.
110      * @param sampleSize Size of the sample.
111      *
112      * @return A fully qualified sample name.
113      */

114     public static String JavaDoc generateFullInstrumentSampleName( String JavaDoc instrumentName,
115                                                            int sampleType,
116                                                            long sampleInterval,
117                                                            int sampleSize )
118     {
119         return instrumentName + "." +
120             generateInstrumentSampleName( sampleType, sampleInterval, sampleSize );
121     }
122 }
123
Popular Tags