KickJava   Java API By Example, From Geeks To Geeks.

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


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

35 public class InstrumentSampleDescriptorImpl
36     implements InstrumentSampleDescriptor
37 {
38     /** The InstrumentSample. */
39     private InstrumentSample m_instrumentSample;
40     
41     /*---------------------------------------------------------------
42      * Constructors
43      *-------------------------------------------------------------*/

44     /**
45      * Creates a new InstrumentSampleDescriptor.
46      *
47      * @param InstrumentSample InstrumentSample being described.
48      */

49     InstrumentSampleDescriptorImpl( InstrumentSample InstrumentSample )
50     {
51         m_instrumentSample = InstrumentSample;
52     }
53     
54     /*---------------------------------------------------------------
55      * Methods InstrumentSampleDescriptor
56      *-------------------------------------------------------------*/

57     /**
58      * Returns true if the InstrumentSample was configured in the instrumentables
59      * section of the configuration.
60      *
61      * @return True if configured.
62      */

63     public boolean isConfigured()
64     {
65         return m_instrumentSample.isConfigured();
66     }
67     
68     /**
69      * Returns the name of the sample.
70      *
71      * @return The name of the sample.
72      */

73     public String JavaDoc getName()
74     {
75         return m_instrumentSample.getName();
76     }
77     
78     /**
79      * Returns the sample interval. The period of each sample in millisends.
80      *
81      * @return The sample interval.
82      */

83     public long getInterval()
84     {
85         return m_instrumentSample.getInterval();
86     }
87     
88     /**
89      * Returns the number of samples in the sample history.
90      *
91      * @return The size of the sample history.
92      */

93     public int getSize()
94     {
95         return m_instrumentSample.getSize();
96     }
97     
98     /**
99      * Returns the description of the sample.
100      *
101      * @return The description of the sample.
102      */

103     public String JavaDoc getDescription()
104     {
105         return m_instrumentSample.getDescription();
106     }
107     
108     /**
109      * Returns the type of the Instrument Sample. Possible values include
110      * InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_COUNTER,
111      * InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MAXIMUM,
112      * InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MEAN, or
113      * InstrumentManagerClient.INSTRUMENT_SAMPLE_TYPE_MINIMUM.
114      *
115      * @return The type of the Instrument Sample.
116      */

117     public int getType()
118     {
119         return m_instrumentSample.getType();
120     }
121     
122     /**
123      * Obtain the value of the sample. All samples are integers, so the profiled
124      * objects must measure quantity (numbers of items), rate (items/period), time in
125      * milliseconds, etc.
126      *
127      * @return The sample value.
128      */

129     public int getValue()
130     {
131         return m_instrumentSample.getValue();
132     }
133     
134     /**
135      * Obtain the UNIX time of the beginning of the sample.
136      *
137      * @return The UNIX time of the beginning of the sample.
138      */

139     public long getTime()
140     {
141         return m_instrumentSample.getTime();
142     }
143     
144     /**
145      * Returns the Type of the Instrument which can use the sample. This
146      * should be the same for all instances of a class.
147      * <p>
148      * Should be one of the following: InstrumentManager.PROFILE_POINT_TYPE_COUNTER
149      * or InstrumentManager.PROFILE_POINT_TYPE_VALUE
150      *
151      * @return The Type of the Instrument which can use the sample.
152      */

153     public int getInstrumentType()
154     {
155         return m_instrumentSample.getInstrumentType();
156     }
157     
158     /**
159      * Returns a reference to the descriptor of the Instrument of the sample.
160      *
161      * @return A reference to the descriptor of the Instrument of the sample.
162      */

163     public InstrumentDescriptor getInstrumentDescriptor()
164     {
165         return m_instrumentSample.getInstrumentProxy().getDescriptor();
166     }
167     
168     /**
169      * Registers a InstrumentSampleListener with a InstrumentSample given a name.
170      *
171      * @param listener The listener which should start receiving updates from the
172      * InstrumentSample.
173      */

174     public void addInstrumentSampleListener( InstrumentSampleListener listener )
175     {
176         m_instrumentSample.addInstrumentSampleListener( listener );
177     }
178     
179     /**
180      * Unregisters a InstrumentSampleListener from a InstrumentSample given a name.
181      *
182      * @param listener The listener which should stop receiving updates from the
183      * InstrumentSample.
184      */

185     public void removeInstrumentSampleListener( InstrumentSampleListener listener )
186     {
187         m_instrumentSample.removeInstrumentSampleListener( listener );
188     }
189     
190     /**
191      * Returns the time that the current lease expires. Permanent samples will
192      * return a value of 0.
193      *
194      * @return The time that the current lease expires.
195      */

196     public long getLeaseExpirationTime()
197     {
198         return m_instrumentSample.getLeaseExpirationTime();
199     }
200     
201     /**
202      * Extends the lease to be lease milliseconds from the current time.
203      *
204      * @param lease The length of the lease in milliseconds.
205      *
206      * @return The new lease expiration time. Returns 0 if the sample is
207      * permanent.
208      */

209     public long extendLease( long lease )
210     {
211         return m_instrumentSample.extendLease( lease );
212     }
213     
214     /**
215      * Obtains a static snapshot of the InstrumentSample.
216      *
217      * @return A static snapshot of the InstrumentSample.
218      */

219     public InstrumentSampleSnapshot getSnapshot()
220     {
221         return m_instrumentSample.getSnapshot();
222     }
223     
224     /**
225      * Returns the stateVersion of the sample. The state version will be
226      * incremented each time any of the configuration of the sample is
227      * modified.
228      * Clients can use this value to tell whether or not anything has
229      * changed without having to do an exhaustive comparison.
230      *
231      * @return The state version of the sample.
232      */

233     public int getStateVersion()
234     {
235         return m_instrumentSample.getStateVersion();
236     }
237 }
238
239
Popular Tags