J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * build @BUILD_TAG_PLACEHOLDER@ |
| 26 | * |
| 27 | * @COPYRIGHT_MINI_LEGAL_NOTICE_PLACEHOLDER@ |
| 28 | */ |
| 29 | |
| 30 | import javax.management.ListenerNotFoundException; |
| 31 | import javax.management.Notification; |
| 32 | import javax.management.NotificationBroadcasterSupport; |
| 33 | import javax.management.NotificationFilter; |
| 34 | import javax.management.NotificationListener; |
| 35 | |
| 36 | public class NotificationSender |
| 37 | extends NotificationBroadcasterSupport |
| 38 | implements NotificationSenderMBean { |
| 39 | |
| 40 | public void sendNotifs(String type, int count) { |
| 41 | for (int i = 0; i < count; i++) { |
| 42 | Notification n = new Notification(type, this, newSeqNo()); |
| 43 | sendNotification(n); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public int getListenerCount() { |
| 48 | return listenerCount; |
| 49 | } |
| 50 | |
| 51 | public void addNotificationListener(NotificationListener l, |
| 52 | NotificationFilter f, |
| 53 | Object h) { |
| 54 | super.addNotificationListener(l, f, h); |
| 55 | listenerCount++; |
| 56 | } |
| 57 | |
| 58 | public void removeNotificationListener(NotificationListener l) |
| 59 | throws ListenerNotFoundException { |
| 60 | super.removeNotificationListener(l); |
| 61 | listenerCount--; |
| 62 | } |
| 63 | |
| 64 | public void removeNotificationListener(NotificationListener l, |
| 65 | NotificationFilter f, |
| 66 | Object h) |
| 67 | throws ListenerNotFoundException { |
| 68 | super.removeNotificationListener(l, f, h); |
| 69 | listenerCount--; |
| 70 | } |
| 71 | |
| 72 | private static long newSeqNo() { |
| 73 | return ++seqNo; |
| 74 | } |
| 75 | |
| 76 | private static long seqNo = 0; |
| 77 | private int listenerCount = 0; |
| 78 | } |