01: /**
02: * Copyright 2004-2005 jManage.org
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */package org.jmanage.core.modules.weblogic;
16:
17: import org.jmanage.core.management.*;
18: import org.jmanage.core.management.ObjectName;
19: import org.jmanage.core.modules.JMXServerConnection;
20:
21: import javax.management.*;
22: import java.util.*;
23:
24: import weblogic.management.RemoteNotificationListener;
25: import weblogic.management.RemoteMBeanServer;
26:
27: /**
28: *
29: * date: Aug 12, 2004
30: * @author Rakesh Kalra, Shashank Bellary
31: */
32: public class WLServerConnection extends JMXServerConnection {
33:
34: private final RemoteMBeanServer mbeanServer;
35:
36: public WLServerConnection(MBeanServer mbeanServer) {
37: super (mbeanServer, MBeanServer.class);
38: assert mbeanServer != null;
39: this .mbeanServer = (RemoteMBeanServer) mbeanServer;
40: }
41:
42: public void addNotificationListener(ObjectName objectName,
43: ObjectNotificationListener listener,
44: ObjectNotificationFilter filter, Object handback) {
45:
46: NotificationListener notifListener = toRemoteNotificationListener(listener);
47: notifications.put(listener, notifListener);
48: NotificationFilter notifFilter = toJMXNotificationFilter(filter);
49: try {
50: mbeanServer.addNotificationListener(
51: toJMXObjectName(objectName), notifListener,
52: notifFilter, handback);
53: } catch (InstanceNotFoundException e) {
54: throw new RuntimeException(e);
55: }
56: }
57:
58: private static NotificationListener toRemoteNotificationListener(
59: final ObjectNotificationListener listener) {
60:
61: return new RemoteNotificationListener() {
62: public void handleNotification(Notification notification,
63: Object handback) {
64: listener.handleNotification(
65: toObjectNotification(notification), handback);
66: }
67: };
68: }
69:
70: public void removeNotificationListener(ObjectName objectName,
71: ObjectNotificationListener listener,
72: ObjectNotificationFilter filter, Object handback) {
73:
74: NotificationListener notifListener = (NotificationListener) notifications
75: .remove(listener);
76: assert notifListener != null;
77:
78: try {
79: mbeanServer.removeNotificationListener(
80: toJMXObjectName(objectName), notifListener);
81: } catch (InstanceNotFoundException e) {
82: throw new RuntimeException(e);
83: } catch (ListenerNotFoundException e) {
84: throw new RuntimeException(e);
85: }
86: }
87: }
|