1 22 package org.jboss.management.mejb; 23 24 import javax.management.Notification ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 35 public class PollingNotificationListener 36 implements PollingNotificationListenerMBean 37 { 38 private List mList; 39 private int mMaximumSize = 1000; 40 41 public PollingNotificationListener(int pListSize, int pMaximumListSize) 42 { 43 if (pListSize <= 0) 44 { 45 pListSize = 1000; 46 } 47 mList = new ArrayList (pListSize); 48 if (pMaximumListSize > 0 && pMaximumListSize > pListSize) 49 { 50 mMaximumSize = pMaximumListSize; 51 } 52 } 53 54 61 public void handleNotification(Notification pNotification, Object pHandback) 62 { 63 synchronized (mList) 64 { 65 if (mList.size() <= mMaximumSize) 66 { 67 mList.add(pNotification); 68 } 69 } 70 } 71 72 76 79 public List getNotifications() 80 { 81 return getNotifications(mMaximumSize); 82 } 83 84 87 public List getNotifications(int pMaxiumSize) 88 { 89 List lReturn = null; 90 synchronized (mList) 91 { 92 pMaxiumSize = pMaxiumSize > mList.size() ? mList.size() : pMaxiumSize; 93 lReturn = new ArrayList (mList.subList(0, pMaxiumSize)); 94 mList.removeAll(lReturn); 95 } 96 97 return lReturn; 98 } 99 100 } 101 | Popular Tags |