KickJava   Java API By Example, From Geeks To Geeks.

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


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.avalon.framework.configuration.Configuration;
23 import org.apache.avalon.framework.configuration.ConfigurationException;
24 import org.apache.avalon.framework.configuration.DefaultConfiguration;
25
26 import org.apache.excalibur.instrument.manager.DefaultInstrumentManager;
27
28 /**
29  * A InstrumentSample which stores the maximum value set during the sample
30  * period.
31  *
32  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
33  */

34 class MaximumValueInstrumentSample
35     extends AbstractValueInstrumentSample
36 {
37     /*---------------------------------------------------------------
38      * Constructors
39      *-------------------------------------------------------------*/

40     /**
41      * Creates a new MaximumValueInstrumentSample
42      *
43      * @param instrumentProxy The InstrumentProxy which owns the
44      * InstrumentSample.
45      * @param name The name of the new InstrumentSample.
46      * @param interval The sample interval of the new InstrumentSample.
47      * @param size The number of samples to store as history. Assumes that size is at least 1.
48      * @param description The description of the new InstrumentSample.
49      * @param lease The length of the lease in milliseconds.
50      */

51     MaximumValueInstrumentSample( InstrumentProxy instrumentProxy,
52                                   String JavaDoc name,
53                                   long interval,
54                                   int size,
55                                   String JavaDoc description,
56                                   long lease )
57     {
58         super( instrumentProxy, name, interval, size, description, lease );
59     }
60     
61     /*---------------------------------------------------------------
62      * InstrumentSample Methods
63      *-------------------------------------------------------------*/

64     /**
65      * Returns the type of the Instrument Sample.
66      *
67      * @return The type of the Instrument Sample.
68      */

69     public int getType()
70     {
71         return DefaultInstrumentManager.INSTRUMENT_SAMPLE_TYPE_MAXIMUM;
72     }
73     
74     /*---------------------------------------------------------------
75      * AbstractValueInstrumentSample Methods
76      *-------------------------------------------------------------*/

77     /**
78      * Sets the current value of the sample. The value will be set as the
79      * sample value if it is the largest value seen during the sample period.
80      *
81      * @param value New sample value.
82      * @param time Time that the new sample arrives.
83      */

84     protected void setValueInner( int value, long time )
85     {
86         boolean update;
87         int sampleValue;
88         long sampleTime;
89         
90         synchronized(this)
91         {
92             update = update( time, false );
93             
94             // Always store the last value to use for samples where a value is not set.
95
m_lastValue = value;
96             
97             if ( m_valueCount > 0 )
98             {
99                 // Additional sample
100
m_valueCount++;
101                 if ( value > m_value )
102                 {
103                     m_value = value;
104                     update = true;
105                 }
106             }
107             else
108             {
109                 // First value of this sample.
110
m_valueCount = 1;
111                 m_value = value;
112                 update = true;
113             }
114             
115             sampleValue = m_value;
116             sampleTime = m_time;
117         }
118         
119         if ( update )
120         {
121             updateListeners( sampleValue, sampleTime );
122         }
123     }
124 }
125
Popular Tags