KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > monitoring > MonitoredObjectImpl


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

106     public void clearState( ) {
107         synchronized( this ) {
108             Iterator JavaDoc i = monitoredAttributes.values().iterator();
109             // First call clearState on all the local attributes
110
while( i.hasNext( ) ) {
111                 ((MonitoredAttribute)i.next()).clearState();
112             }
113             i = children.values().iterator();
114             // next call clearState on all the children MonitoredObjects
115
while( i.hasNext() ) {
116                 ((MonitoredObject)i.next()).clearState();
117            }
118         }
119     }
120
121     public String JavaDoc getName( ) {
122         return name;
123     }
124
125     public String JavaDoc getDescription( ) {
126         return description;
127     }
128 }
129         
130     
131
132    
133
134
Popular Tags