KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > instrument > manager > impl > InstrumentDescriptorImpl


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.impl;
21
22 import org.apache.excalibur.instrument.manager.CounterInstrumentListener;
23 import org.apache.excalibur.instrument.manager.InstrumentableDescriptor;
24 import org.apache.excalibur.instrument.manager.InstrumentDescriptor;
25 import org.apache.excalibur.instrument.manager.InstrumentSampleDescriptor;
26 import org.apache.excalibur.instrument.manager.NoSuchInstrumentSampleException;
27 import org.apache.excalibur.instrument.manager.ValueInstrumentListener;
28
29 /**
30  * Describes a Instrument and acts as a Proxy to protect the original
31  * Instrument.
32  *
33  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
34  * @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:25 $
35  * @since 4.1
36  */

37 public class InstrumentDescriptorImpl
38     implements InstrumentDescriptor
39 {
40     /** InstrumentProxy being described. */
41     private InstrumentProxy m_instrumentProxy;
42     
43     /*---------------------------------------------------------------
44      * Constructors
45      *-------------------------------------------------------------*/

46     /**
47      * Creates a new InstrumentDescriptor.
48      *
49      * @param instrumentProxy InstrumentProxy being described.
50      */

51     InstrumentDescriptorImpl( InstrumentProxy instrumentProxy )
52     {
53         m_instrumentProxy = instrumentProxy;
54     }
55     
56     /*---------------------------------------------------------------
57      * InstrumentDescriptor Methods
58      *-------------------------------------------------------------*/

59     /**
60      * Returns true if the Instrument was configured in the instrumentables
61      * section of the configuration.
62      *
63      * @return True if configured.
64      */

65     public boolean isConfigured()
66     {
67         return m_instrumentProxy.isConfigured();
68     }
69
70     /**
71      * Returns true if the Instrument was registered with the Instrument
72      * Manager.
73      *
74      * @return True if registered.
75      */

76     public boolean isRegistered()
77     {
78         return m_instrumentProxy.isRegistered();
79     }
80     
81     /**
82      * Gets the name for the Instrument. The Instrument Name is used to
83      * uniquely identify the Instrument during the configuration of the
84      * Profiler. The value should be a string which does not contain spaces
85      * or periods.
86      *
87      * @return The name used to identify a Instrument.
88      */

89     public String JavaDoc getName()
90     {
91         return m_instrumentProxy.getName();
92     }
93     
94     /**
95      * Gets the description of the Instrument.
96      *
97      * @return The description of the Instrument.
98      */

99     public String JavaDoc getDescription()
100     {
101         return m_instrumentProxy.getDescription();
102     }
103     
104     /**
105      * Returns the type of the Instrument. Possible values include
106      * InstrumentManagerClient.INSTRUMENT_TYPE_COUNTER,
107      * InstrumentManagerClient.INSTRUMENT_TYPE_VALUE or
108      * InstrumentManagerClient.INSTRUMENT_TYPE_NONE, if the type was never set.
109      *
110      * @return The type of the Instrument.
111      */

112     public int getType()
113     {
114         return m_instrumentProxy.getType();
115     }
116     
117     /**
118      * Returns a reference to the descriptor of the Instrumentable of the
119      * instrument.
120      *
121      * @return A reference to the descriptor of the Instrumentable of the
122      * instrument.
123      */

124     public InstrumentableDescriptor getInstrumentableDescriptor()
125     {
126         return m_instrumentProxy.getInstrumentableProxy().getDescriptor();
127     }
128     
129     /**
130      * Adds a CounterInstrumentListener to the list of listeners which will
131      * receive updates of the value of the Instrument.
132      *
133      * @param listener CounterInstrumentListener which will start receiving
134      * profile updates.
135      *
136      * @throws IllegalStateException If the Instrument's type is not
137      * InstrumentManager.PROFILE_POINT_TYPE_COUNTER.
138      */

139     public void addCounterInstrumentListener( CounterInstrumentListener listener )
140     {
141         m_instrumentProxy.addCounterInstrumentListener( listener );
142     }
143     
144     /**
145      * Removes a InstrumentListener from the list of listeners which will
146      * receive profile events.
147      *
148      * @param listener InstrumentListener which will stop receiving profile
149      * events.
150      *
151      * @throws IllegalStateException If the Instrument's type is not
152      * InstrumentManager.PROFILE_POINT_TYPE_COUNTER.
153      */

154     public void removeCounterInstrumentListener( CounterInstrumentListener listener )
155     {
156         m_instrumentProxy.removeCounterInstrumentListener( listener );
157     }
158     
159     /**
160      * Adds a ValueInstrumentListener to the list of listeners which will
161      * receive updates of the value of the Instrument.
162      *
163      * @param listener ValueInstrumentListener which will start receiving
164      * profile updates.
165      *
166      * @throws IllegalStateException If the Instrument's type is not
167      * DefaultInstrumentManager.INSTRUMENT_TYPE_VALUE.
168      */

169     public void addValueInstrumentListener( ValueInstrumentListener listener )
170     {
171         m_instrumentProxy.addValueInstrumentListener( listener );
172     }
173         
174     /**
175      * Removes a InstrumentListener from the list of listeners which will
176      * receive profile events.
177      *
178      * @param listener InstrumentListener which will stop receiving profile
179      * events.
180      *
181      * @throws IllegalStateException If the Instrument's type is not
182      * DefaultInstrumentManager.INSTRUMENT_TYPE_VALUE.
183      */

184     public void removeValueInstrumentListener( ValueInstrumentListener listener )
185     {
186         m_instrumentProxy.removeValueInstrumentListener( listener );
187     }
188     
189     /**
190      * Returns a InstrumentSampleDescriptor based on its name.
191      *
192      * @param instrumentSampleName Name of the InstrumentSample being requested.
193      *
194      * @return A Descriptor of the requested InstrumentSample.
195      *
196      * @throws NoSuchInstrumentSampleException If the specified InstrumentSample
197      * does not exist.
198      */

199     public InstrumentSampleDescriptor getInstrumentSampleDescriptor( String JavaDoc instrumentSampleName )
200         throws NoSuchInstrumentSampleException
201     {
202         InstrumentSample instrumentSample =
203             m_instrumentProxy.getInstrumentSample( instrumentSampleName );
204         if ( instrumentSample == null )
205         {
206             throw new NoSuchInstrumentSampleException(
207                 "No instrument sample can be found using name: " + instrumentSampleName );
208         }
209         
210         return instrumentSample.getDescriptor();
211     }
212     
213     /**
214      * Returns a InstrumentSampleDescriptor based on its name. If the requested
215      * sample is invalid in any way, then an expired Descriptor will be
216      * returned.
217      *
218      * @param sampleDescription Description to assign to the new Sample.
219      * @param sampleInterval Sample interval to use in the new Sample.
220      * @param sampleLease Requested lease time for the new Sample in
221      * milliseconds. The InstrumentManager may grant a
222      * lease which is shorter or longer than the requested
223      * period.
224      * @param sampleType Type of sample to request. Must be one of the
225      * following: InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER,
226      * InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MINIMUM,
227      * InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM,
228      * InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN.
229      *
230      * @return A Descriptor of the requested InstrumentSample.
231      *
232      * @throws NoSuchInstrumentSampleException If the specified InstrumentSample
233      * does not exist.
234      */

235     public InstrumentSampleDescriptor createInstrumentSample( String JavaDoc sampleDescription,
236                                                               long sampleInterval,
237                                                               int sampleSize,
238                                                               long sampleLease,
239                                                               int sampleType )
240     {
241         InstrumentSample sample = m_instrumentProxy.createInstrumentSample(
242             sampleDescription, sampleInterval, sampleSize, sampleLease, sampleType );
243         return sample.getDescriptor();
244     }
245     
246     /**
247      * Returns an array of Descriptors for the InstrumentSamples configured for this
248      * Instrument.
249      *
250      * @return An array of Descriptors for the InstrumentSamples configured for this
251      * Instrument.
252      */

253     public InstrumentSampleDescriptor[] getInstrumentSampleDescriptors()
254     {
255         return m_instrumentProxy.getInstrumentSampleDescriptors();
256     }
257     
258     /**
259      * Returns the stateVersion of the instrument. The state version will be
260      * incremented each time any of the configuration of the instrument or
261      * any of its children is modified.
262      * Clients can use this value to tell whether or not anything has
263      * changed without having to do an exhaustive comparison.
264      *
265      * @return The state version of the instrument.
266      */

267     public int getStateVersion()
268     {
269         return m_instrumentProxy.getStateVersion();
270     }
271 }
272
Popular Tags