1 22 package org.jboss.management.mejb; 23 24 import javax.management.JMException ; 25 import javax.management.Notification ; 26 import javax.management.NotificationFilter ; 27 import javax.management.NotificationListener ; 28 import javax.management.ObjectName ; 29 import java.rmi.RemoteException ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 33 39 public class PollingClientNotificationListener 40 extends ClientNotificationListener 41 implements Runnable 42 { 43 44 private MEJB mConnector; 45 private int mSleepingPeriod = 2000; 46 47 public PollingClientNotificationListener(ObjectName pSender, 48 NotificationListener pClientListener, 49 Object pHandback, 50 NotificationFilter pFilter, 51 int pSleepingPeriod, 52 int pMaximumListSize, 53 MEJB pConnector) throws 54 JMException , 55 RemoteException 56 { 57 super(pSender, pClientListener, pHandback); 58 if (pSleepingPeriod > 0) 59 { 60 mSleepingPeriod = pSleepingPeriod; 61 } 62 mConnector = pConnector; 63 createListener(pConnector, 65 "org.jboss.management.mejb.PollingNotificationListener", 66 new Object []{new Integer (pMaximumListSize), new Integer (pMaximumListSize)}, 67 new String []{Integer.TYPE.getName(), Integer.TYPE.getName()}); 68 addNotificationListener(pConnector, pFilter); 69 new Thread (this).start(); 70 } 71 72 public void run() 73 { 74 while (true) 75 { 76 try 77 { 78 try 79 { 80 List lNotifications = (List ) mConnector.invoke(getRemoteListenerName(), 81 "getNotifications", 82 new Object []{}, 83 new String []{}); 84 Iterator i = lNotifications.iterator(); 85 while (i.hasNext()) 86 { 87 Notification lNotification = (Notification ) i.next(); 88 mClientListener.handleNotification(lNotification, 89 mHandback); 90 } 91 } 92 catch (Exception e) 93 { 94 log.error("PollingClientNotificationListener.getNotifications() failed", e); 95 } 96 Thread.sleep(mSleepingPeriod); 97 } 98 catch (InterruptedException e) 99 { 100 } 101 } 102 } 103 } 104 | Popular Tags |