1 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 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 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 (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 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 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 (e); 87 } catch (ListenerNotFoundException e) { 88 throw new RuntimeException (e); 89 } 90 } 91 } | Popular Tags |