1. /*
  2. * @(#)MonitoredObjectImpl.java 1.4 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.impl.monitoring;
  8. import java.util.Map;
  9. import java.util.HashMap;
  10. import java.util.Collection;
  11. import java.util.Iterator;
  12. import com.sun.corba.se.spi.monitoring.MonitoredObject;
  13. import com.sun.corba.se.spi.monitoring.MonitoredAttribute;
  14. public class MonitoredObjectImpl implements MonitoredObject {
  15. private final String name;
  16. private final String description;
  17. // List of all child Monitored Objects
  18. private Map children = new HashMap();
  19. // All the Attributes of this Monitored Object instance
  20. private Map monitoredAttributes = new HashMap();
  21. private MonitoredObject parent = null;
  22. // Constructor
  23. MonitoredObjectImpl( String name, String description ) {
  24. this.name = name;
  25. this.description = description;
  26. }
  27. public MonitoredObject getChild( String name ) {
  28. synchronized( this ) {
  29. return (MonitoredObject) children.get( name );
  30. }
  31. }
  32. public Collection getChildren( ) {
  33. synchronized( this ) {
  34. return children.values();
  35. }
  36. }
  37. public void addChild( MonitoredObject m ) {
  38. if (m != null){
  39. synchronized( this ) {
  40. children.put( m.getName(), m);
  41. m.setParent( this );
  42. }
  43. }
  44. }
  45. public void removeChild( String name ) {
  46. if (name != null){
  47. synchronized( this ) {
  48. children.remove( name );
  49. }
  50. }
  51. }
  52. public synchronized MonitoredObject getParent( ) {
  53. return parent;
  54. }
  55. public synchronized void setParent( MonitoredObject p ) {
  56. parent = p;
  57. }
  58. public MonitoredAttribute getAttribute( String name ) {
  59. synchronized( this ) {
  60. return (MonitoredAttribute) monitoredAttributes.get( name );
  61. }
  62. }
  63. public Collection getAttributes( ) {
  64. synchronized( this ) {
  65. return monitoredAttributes.values();
  66. }
  67. }
  68. public void addAttribute( MonitoredAttribute value ) {
  69. if (value != null) {
  70. synchronized( this ) {
  71. monitoredAttributes.put( value.getName(), value );
  72. }
  73. }
  74. }
  75. public void removeAttribute( String name ) {
  76. if (name != null) {
  77. synchronized( this ) {
  78. monitoredAttributes.remove( name );
  79. }
  80. }
  81. }
  82. /**
  83. * calls clearState() on all the registered children MonitoredObjects and
  84. * MonitoredAttributes.
  85. */
  86. public void clearState( ) {
  87. synchronized( this ) {
  88. Iterator i = monitoredAttributes.values().iterator();
  89. // First call clearState on all the local attributes
  90. while( i.hasNext( ) ) {
  91. ((MonitoredAttribute)i.next()).clearState();
  92. }
  93. i = children.values().iterator();
  94. // next call clearState on all the children MonitoredObjects
  95. while( i.hasNext() ) {
  96. ((MonitoredObject)i.next()).clearState();
  97. }
  98. }
  99. }
  100. public String getName( ) {
  101. return name;
  102. }
  103. public String getDescription( ) {
  104. return description;
  105. }
  106. }