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. import java.util.*;
  9. /**
  10. * <p>
  11. *
  12. * @author Hemanth Puttaswamy
  13. * </p>
  14. * <p>
  15. * StatisticsMonitoredAttribute is provided as a convenience to collect the
  16. * Statistics of any entity. The getValue() call will be delegated to the
  17. * StatisticsAccumulator set by the user.
  18. * </p>
  19. */
  20. public class StatisticMonitoredAttribute extends MonitoredAttributeBase {
  21. // Every StatisticMonitoredAttribute will have a StatisticAccumulator. User
  22. // will use Statisticsaccumulator to accumulate the samples associated with
  23. // this Monitored Attribute
  24. private StatisticsAccumulator statisticsAccumulator;
  25. // Mutex is passed from the user class which is providing the sample values.
  26. // getValue() and clearState() is synchronized on this user provided mutex
  27. private Object mutex;
  28. ///////////////////////////////////////
  29. // operations
  30. /**
  31. * <p>
  32. * Constructs the StaisticMonitoredAttribute, builds the required
  33. * MonitoredAttributeInfo with Long as the class type and is always
  34. * readonly attribute.
  35. * </p>
  36. * <p>
  37. *
  38. * @param name Of this attribute
  39. * </p>
  40. * <p>
  41. * @return a StatisticMonitoredAttribute
  42. * </p>
  43. * <p>
  44. * @param desc should provide a good description on the kind of statistics
  45. * collected, a good example is "Connection Response Time Stats will Provide the
  46. * detailed stats based on the samples provided from every request completion
  47. * time"
  48. * </p>
  49. * <p>
  50. * @param s is the StatisticsAcumulator that user will use to accumulate the
  51. * samples and this Attribute Object will get the computed statistics values
  52. * from.
  53. * </p>
  54. * <p>
  55. * @param mutex using which clearState() and getValue() calls need to be locked.
  56. * </p>
  57. */
  58. public StatisticMonitoredAttribute(String name, String desc,
  59. StatisticsAccumulator s, Object mutex)
  60. {
  61. super( name );
  62. MonitoredAttributeInfoFactory f =
  63. MonitoringFactories.getMonitoredAttributeInfoFactory();
  64. MonitoredAttributeInfo maInfo = f.createMonitoredAttributeInfo(
  65. desc, String.class, false, true );
  66. this.setMonitoredAttributeInfo( maInfo );
  67. this.statisticsAccumulator = s;
  68. this.mutex = mutex;
  69. } // end StatisticMonitoredAttribute
  70. /**
  71. * Gets the value from the StatisticsAccumulator, the value will be a formatted
  72. * String with the computed statistics based on the samples accumulated in the
  73. * Statistics Accumulator.
  74. */
  75. public Object getValue( ) {
  76. synchronized( mutex ) {
  77. return statisticsAccumulator.getValue( );
  78. }
  79. }
  80. /**
  81. * Clears the state on Statistics Accumulator, After this call all samples are
  82. * treated fresh and the old sample computations are disregarded.
  83. */
  84. public void clearState( ) {
  85. synchronized( mutex ) {
  86. statisticsAccumulator.clearState( );
  87. }
  88. }
  89. /**
  90. * Gets the statistics accumulator associated with StatisticMonitoredAttribute.
  91. * Usually, the user don't need to use this method as they can keep the handle
  92. * to Accumulator to collect the samples.
  93. */
  94. public StatisticsAccumulator getStatisticsAccumulator( ) {
  95. return statisticsAccumulator;
  96. }
  97. } // end StatisticMonitoredAttribute