KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > modules > weblogic > WLServerConnection


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.jmanage.core.modules.weblogic;
17
18 import org.jmanage.core.management.*;
19 import org.jmanage.core.management.ObjectName;
20 import org.jmanage.core.modules.JMXServerConnection;
21
22 import javax.management.*;
23 import java.util.*;
24
25 import weblogic.management.RemoteNotificationListener;
26 import weblogic.management.RemoteMBeanServer;
27
28 /**
29  *
30  * date: Aug 12, 2004
31  * @author Rakesh Kalra, Shashank Bellary
32  */

33 public class WLServerConnection extends JMXServerConnection{
34
35     private final RemoteMBeanServer mbeanServer;
36
37     public WLServerConnection(MBeanServer mbeanServer){
38         super(mbeanServer, MBeanServer.class);
39         assert mbeanServer != null;
40         this.mbeanServer = (RemoteMBeanServer)mbeanServer;
41     }
42
43     public void addNotificationListener(ObjectName objectName,
44                                         ObjectNotificationListener listener,
45                                         ObjectNotificationFilter filter,
46                                         Object JavaDoc handback){
47
48         NotificationListener notifListener =
49                 toRemoteNotificationListener(listener);
50         notifications.put(listener, notifListener);
51         NotificationFilter notifFilter =
52                 toJMXNotificationFilter(filter);
53         try {
54             mbeanServer.addNotificationListener(toJMXObjectName(objectName),
55                     notifListener, notifFilter, handback);
56         } catch (InstanceNotFoundException e) {
57             throw new RuntimeException JavaDoc(e);
58         }
59     }
60
61     private static NotificationListener toRemoteNotificationListener(
62             final ObjectNotificationListener listener){
63
64         return new RemoteNotificationListener(){
65             public void handleNotification(Notification notification,
66                                        Object JavaDoc handback) {
67                 listener.handleNotification(toObjectNotification(notification),
68                         handback);
69             }
70         };
71     }
72
73     public void removeNotificationListener(ObjectName objectName,
74                                            ObjectNotificationListener listener,
75                                            ObjectNotificationFilter filter,
76                                            Object JavaDoc handback){
77
78         NotificationListener notifListener =
79                 (NotificationListener)notifications.remove(listener);
80         assert notifListener != null;
81
82         try {
83             mbeanServer.removeNotificationListener(toJMXObjectName(objectName),
84                     notifListener);
85         } catch (InstanceNotFoundException e) {
86             throw new RuntimeException JavaDoc(e);
87         } catch (ListenerNotFoundException e) {
88             throw new RuntimeException JavaDoc(e);
89         }
90     }
91 }
Popular Tags