KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > spi > monitoring > StatisticMonitoredAttribute


1 /*
2  * @(#)StatisticMonitoredAttribute.java 1.3 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package com.sun.corba.se.spi.monitoring;
8
9 import java.util.*;
10
11 /**
12  * <p>
13  *
14  * @author Hemanth Puttaswamy
15  * </p>
16  * <p>
17  * StatisticsMonitoredAttribute is provided as a convenience to collect the
18  * Statistics of any entity. The getValue() call will be delegated to the
19  * StatisticsAccumulator set by the user.
20  * </p>
21  */

22 public class StatisticMonitoredAttribute extends MonitoredAttributeBase {
23
24
25     // Every StatisticMonitoredAttribute will have a StatisticAccumulator. User
26
// will use Statisticsaccumulator to accumulate the samples associated with
27
// this Monitored Attribute
28
private StatisticsAccumulator statisticsAccumulator;
29
30     // Mutex is passed from the user class which is providing the sample values.
31
// getValue() and clearState() is synchronized on this user provided mutex
32
private Object JavaDoc mutex;
33
34
35   ///////////////////////////////////////
36
// operations
37

38
39 /**
40  * <p>
41  * Constructs the StaisticMonitoredAttribute, builds the required
42  * MonitoredAttributeInfo with Long as the class type and is always
43  * readonly attribute.
44  * </p>
45  * <p>
46  *
47  * @param name Of this attribute
48  * </p>
49  * <p>
50  * @return a StatisticMonitoredAttribute
51  * </p>
52  * <p>
53  * @param desc should provide a good description on the kind of statistics
54  * collected, a good example is "Connection Response Time Stats will Provide the
55  * detailed stats based on the samples provided from every request completion
56  * time"
57  * </p>
58  * <p>
59  * @param s is the StatisticsAcumulator that user will use to accumulate the
60  * samples and this Attribute Object will get the computed statistics values
61  * from.
62  * </p>
63  * <p>
64  * @param mutex using which clearState() and getValue() calls need to be locked.
65  * </p>
66  */

67     public StatisticMonitoredAttribute(String JavaDoc name, String JavaDoc desc,
68         StatisticsAccumulator s, Object JavaDoc mutex)
69     {
70         super( name );
71         MonitoredAttributeInfoFactory f =
72             MonitoringFactories.getMonitoredAttributeInfoFactory();
73         MonitoredAttributeInfo maInfo = f.createMonitoredAttributeInfo(
74                 desc, String JavaDoc.class, false, true );
75
76         this.setMonitoredAttributeInfo( maInfo );
77         this.statisticsAccumulator = s;
78         this.mutex = mutex;
79     } // end StatisticMonitoredAttribute
80

81
82
83 /**
84  * Gets the value from the StatisticsAccumulator, the value will be a formatted
85  * String with the computed statistics based on the samples accumulated in the
86  * Statistics Accumulator.
87  */

88     public Object JavaDoc getValue( ) {
89         synchronized( mutex ) {
90             return statisticsAccumulator.getValue( );
91         }
92     }
93
94 /**
95  * Clears the state on Statistics Accumulator, After this call all samples are
96  * treated fresh and the old sample computations are disregarded.
97  */

98     public void clearState( ) {
99         synchronized( mutex ) {
100             statisticsAccumulator.clearState( );
101         }
102     }
103
104 /**
105  * Gets the statistics accumulator associated with StatisticMonitoredAttribute.
106  * Usually, the user don't need to use this method as they can keep the handle
107  * to Accumulator to collect the samples.
108  */

109     public StatisticsAccumulator getStatisticsAccumulator( ) {
110         return statisticsAccumulator;
111     }
112 } // end StatisticMonitoredAttribute
113

114
115
116
Popular Tags