1 /* |
|
2 * Copyright 2007-2008 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. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 |
|
26 package com.sun.jmx.event; |
|
27 |
|
28 import com.sun.jmx.remote.util.ClassLogger; |
|
29 import java.util.ArrayList; |
|
30 import java.util.Collections; |
|
31 import java.util.List; |
|
32 import javax.management.remote.NotificationResult; |
|
33 import javax.management.remote.TargetedNotification; |
|
34 |
|
35 |
|
36 public class ReceiverBuffer { |
|
37 public void addNotifs(NotificationResult nr) { |
|
38 if (nr == null) { |
|
39 return; |
|
40 } |
|
41 |
|
42 TargetedNotification[] tns = nr.getTargetedNotifications(); |
|
43 |
|
44 if (logger.traceOn()) { |
|
45 logger.trace("addNotifs", "" + tns.length); |
|
46 } |
|
47 |
|
48 long impliedStart = nr.getEarliestSequenceNumber(); |
|
49 final long missed = impliedStart - start; |
|
50 start = nr.getNextSequenceNumber(); |
|
51 |
|
52 if (missed > 0) { |
|
53 if (logger.traceOn()) { |
|
54 logger.trace("addNotifs", |
|
55 "lost: "+missed); |
|
56 } |
|
57 |
|
58 lost += missed; |
|
59 } |
|
60 |
|
61 Collections.addAll(notifList, nr.getTargetedNotifications()); |
|
62 } |
|
63 |
|
64 public TargetedNotification[] removeNotifs() { |
|
65 if (logger.traceOn()) { |
|
66 logger.trace("removeNotifs", String.valueOf(notifList.size())); |
|
67 } |
|
68 |
|
69 if (notifList.size() == 0) { |
|
70 return null; |
|
71 } |
|
72 |
|
73 TargetedNotification[] ret = notifList.toArray( |
|
74 new TargetedNotification[]{}); |
|
75 notifList.clear(); |
|
76 |
|
77 return ret; |
|
78 } |
|
79 |
|
80 public int size() { |
|
81 return notifList.size(); |
|
82 } |
|
83 |
|
84 public int removeLost() { |
|
85 int ret = lost; |
|
86 lost = 0; |
|
87 return ret; |
|
88 } |
|
89 |
|
90 private List<TargetedNotification> notifList |
|
91 = new ArrayList<TargetedNotification>(); |
|
92 private long start = 0; |
|
93 private int lost = 0; |
|
94 |
|
95 private static final ClassLogger logger = |
|
96 new ClassLogger("javax.management.event", "ReceiverBuffer"); |
|
97 } |
|