KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > management > mejb > PollingNotificationListener


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.management.mejb;
23
24 import javax.management.Notification JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27
28 /**
29  * Remote Listener using Polling to send the event
30  *
31  * @author ???
32  * @version $Revision: 37459 $
33  * @jmx:mbean extends="org.jboss.management.mejb.ListenerMBean"
34  */

35 public class PollingNotificationListener
36         implements PollingNotificationListenerMBean
37 {
38    private List JavaDoc 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 JavaDoc(pListSize);
48       if (pMaximumListSize > 0 && pMaximumListSize > pListSize)
49       {
50          mMaximumSize = pMaximumListSize;
51       }
52    }
53
54    /**
55     * Handles the given notification by sending this to the remote
56     * client listener
57     *
58     * @param pNotification Notification to be send
59     * @param pHandback Handback object
60     */

61    public void handleNotification(Notification JavaDoc pNotification, Object JavaDoc pHandback)
62    {
63       synchronized (mList)
64       {
65          if (mList.size() <= mMaximumSize)
66          {
67             mList.add(pNotification);
68          }
69       }
70    }
71
72    //
73
// jason: this is illegal usage of attributes, drop the no-args version
74
//
75

76    /**
77     * @jmx:managed-attribute
78     */

79    public List JavaDoc getNotifications()
80    {
81       return getNotifications(mMaximumSize);
82    }
83
84    /**
85     * @jmx:managed-attribute
86     */

87    public List JavaDoc getNotifications(int pMaxiumSize)
88    {
89       List JavaDoc lReturn = null;
90       synchronized (mList)
91       {
92          pMaxiumSize = pMaxiumSize > mList.size() ? mList.size() : pMaxiumSize;
93          lReturn = new ArrayList JavaDoc(mList.subList(0, pMaxiumSize));
94          mList.removeAll(lReturn);
95       }
96
97       return lReturn;
98    }
99
100 }
101
Popular Tags