KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > RegistrationListener


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.management;
24
25 import java.io.IOException JavaDoc;
26
27 import java.util.Set JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Collections JavaDoc;
30
31 import javax.management.ObjectName JavaDoc;
32 import javax.management.MBeanServerConnection JavaDoc;
33 import javax.management.InstanceNotFoundException JavaDoc;
34
35 import com.sun.appserv.management.base.AMX;
36 import com.sun.appserv.management.base.Util;
37
38 import com.sun.appserv.management.util.jmx.MBeanRegistrationListener;
39 import com.sun.appserv.management.util.jmx.JMXUtil;
40     
41 /**
42     A NotificationListener which tracks registration of MBeans.
43  */

44 public class RegistrationListener extends MBeanRegistrationListener
45 {
46     private final MBeanServerConnection JavaDoc mConn;
47     
48     private Set JavaDoc<ObjectName JavaDoc> mRegistered;
49     private Set JavaDoc<ObjectName JavaDoc> mUnregistered;
50     private Set JavaDoc<ObjectName JavaDoc> mCurrentlyRegistered;
51     
52         public
53     RegistrationListener( final MBeanServerConnection JavaDoc conn )
54         throws InstanceNotFoundException JavaDoc, java.io.IOException JavaDoc
55     {
56         super( conn, null );
57         
58         mConn = conn;
59         
60         mRegistered = new HashSet JavaDoc<ObjectName JavaDoc>();
61         mUnregistered = new HashSet JavaDoc<ObjectName JavaDoc>();
62         mCurrentlyRegistered = new HashSet JavaDoc<ObjectName JavaDoc>();
63         JMXUtil.listenToMBeanServerDelegate( conn, this, null, null );
64         
65         queryAllAMX();
66     }
67     
68         private void
69     queryAllAMX()
70     {
71         try
72         {
73         final ObjectName JavaDoc pat = Util.newObjectNamePattern( AMX.JMX_DOMAIN, "*" );
74         final Set JavaDoc<ObjectName JavaDoc> all = JMXUtil.queryNames( mConn, pat, null );
75         
76         mCurrentlyRegistered.addAll( all );
77         }
78         catch( IOException JavaDoc e )
79         {
80         }
81     }
82
83         public void
84     notifsLost()
85     {
86         queryAllAMX();
87     }
88     
89         private boolean
90     isAMX( final ObjectName JavaDoc objectName )
91     {
92         return objectName.getDomain().equals( AMX.JMX_DOMAIN );
93     }
94     
95         protected synchronized void
96     mbeanRegistered( final ObjectName JavaDoc objectName )
97     {
98         if ( isAMX( objectName ) )
99         {
100             mRegistered.add( objectName );
101             mCurrentlyRegistered.add( objectName );
102         }
103     }
104     
105         protected synchronized void
106     mbeanUnregistered( final ObjectName JavaDoc objectName )
107     {
108         if ( isAMX( objectName ) )
109         {
110             mUnregistered.add( objectName );
111             mCurrentlyRegistered.remove( objectName );
112         }
113     }
114     
115         public Set JavaDoc<ObjectName JavaDoc>
116     getRegistered()
117     {
118         return Collections.unmodifiableSet( mRegistered );
119     }
120     
121         public Set JavaDoc<ObjectName JavaDoc>
122     getUnregistered()
123     {
124         return Collections.unmodifiableSet( mUnregistered );
125     }
126     
127         public synchronized Set JavaDoc<ObjectName JavaDoc>
128     getCurrentlyRegistered()
129     {
130         final Set JavaDoc<ObjectName JavaDoc> all = new HashSet JavaDoc<ObjectName JavaDoc>( mCurrentlyRegistered );
131         
132         return all;
133     }
134     
135 }
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Popular Tags