1 22 package org.jboss.management.mejb; 23 24 import org.jboss.logging.Logger; 25 26 import javax.management.*; 27 import java.rmi.RemoteException ; 28 import java.util.Random ; 29 30 36 public abstract class ClientNotificationListener 37 { 38 private ObjectName mSender; 39 private ObjectName mRemoteListener; 40 protected NotificationListener mClientListener; 41 protected Object mHandback; 42 private Random mRandom = new Random (); 43 44 protected Logger log = Logger.getLogger(this.getClass()); 45 46 public ClientNotificationListener(ObjectName pSender, 47 NotificationListener pClientListener, 48 Object pHandback) 49 { 50 mSender = pSender; 51 mClientListener = pClientListener; 52 mHandback = pHandback; 53 } 54 55 public ObjectName createListener(MEJB pConnector, 56 String pClass, 57 Object [] pParameters, 58 String [] pSignatures) throws 59 MalformedObjectNameException, 60 ReflectionException, 61 MBeanRegistrationException, 62 MBeanException, 63 NotCompliantMBeanException, 64 RemoteException 65 { 66 ObjectName lName = null; 67 while (lName == null) 68 { 69 try 70 { 71 lName = new ObjectName("JMX:type=listener,id=" + mRandom.nextLong()); 72 ObjectInstance lInstance = pConnector.createMBean(pClass, 73 lName, 74 pParameters, 75 pSignatures); 76 lName = lInstance.getObjectName(); 77 } 78 catch (InstanceAlreadyExistsException iaee) 79 { 80 lName = null; 81 } 82 87 } 88 mRemoteListener = lName; 89 return lName; 90 } 91 92 public void addNotificationListener(MEJB pConnector, 93 NotificationFilter pFilter) throws 94 InstanceNotFoundException, 95 RemoteException 96 { 97 pConnector.addNotificationListener(mSender, 98 mRemoteListener, 99 pFilter, 100 null); 101 } 102 103 public void removeNotificationListener(MEJB pConnector) throws 104 InstanceNotFoundException, 105 RemoteException 106 { 107 try 108 { 109 pConnector.removeNotificationListener(mSender, 110 mRemoteListener); 111 } 112 catch (JMException jme) 113 { 114 } 115 try 116 { 117 pConnector.unregisterMBean(mRemoteListener); 118 } 119 catch (JMException jme) 120 { 121 } 122 } 123 124 public ObjectName getSenderMBean() 125 { 126 return mSender; 127 } 128 129 public ObjectName getRemoteListenerName() 130 { 131 return mRemoteListener; 132 } 133 134 public boolean equals(Object pTest) 135 { 136 if (pTest instanceof ClientNotificationListener) 137 { 138 ClientNotificationListener lListener = (ClientNotificationListener) pTest; 139 return 140 mSender.equals(lListener.mSender) && 141 mClientListener.equals(lListener.mClientListener); 142 } 143 return false; 144 } 145 146 } 147 | Popular Tags |