jdk/test/javax/management/remote/mandatory/notif/NotificationBufferTest.java
author dfuchs
Thu, 02 Feb 2017 16:50:46 +0000
changeset 43503 bc7f8619ab70
parent 30376 2ccf2cf7ea48
permissions -rw-r--r--
8173607: JMX RMI connector should be in its own module Summary: The JMX RMI connector is moved to a new java.management.rmi module. Reviewed-by: mchung, erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 7654321
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Tests the NotificationBuffer class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Eamonn McManus
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
    29
 * @modules java.management/com.sun.jmx.remote.internal
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
    30
 *          java.management/com.sun.jmx.remote.util
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run clean NotificationBufferTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run build NotificationBufferTest NotificationSender NotificationSenderMBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @run main NotificationBufferTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.MBeanServerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.MBeanServerInvocationHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.management.MBeanServerNotification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.Notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.NotificationFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.management.NotificationFilterSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.management.loading.MLet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.management.remote.NotificationResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.management.remote.TargetedNotification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import com.sun.jmx.remote.internal.ArrayNotificationBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import com.sun.jmx.remote.internal.NotificationBufferFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import com.sun.jmx.remote.internal.NotificationBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class NotificationBufferTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
//      System.setProperty("java.util.logging.config.file",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
//                         "../../../../logging.properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
//      // we are in <workspace>/build/test/JTwork/scratch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
//          java.util.logging.LogManager.getLogManager().readConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            boolean ok = test();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            if (ok) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                System.out.println("Test completed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                System.out.println("Test failed!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            System.err.println("Unexpected exception: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static boolean test() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        Integer queuesize = new Integer(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        HashMap env = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        env.put(com.sun.jmx.remote.util.EnvHelp.BUFFER_SIZE_PROPERTY, queuesize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        final NotificationBuffer nb =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            ArrayNotificationBuffer.getNotificationBuffer(mbs, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        final ObjectName senderName = new ObjectName("dom:type=sender");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        final ObjectName wildcardName = new ObjectName("*:*");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        final String notifType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            MBeanServerNotification.REGISTRATION_NOTIFICATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        Integer allListenerId = new Integer(99);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        NotificationBufferFilter allListenerFilter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                makeFilter(allListenerId, wildcardName, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        NotificationFilterSupport regFilter = new NotificationFilterSupport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        regFilter.enableType(notifType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        // Get initial sequence number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        NotificationResult nr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            nb.fetchNotifications(allListenerFilter, 0, 0L, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        int nnotifs = nr.getTargetedNotifications().length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (nnotifs > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            System.out.println("Expected 0 notifs for initial fetch, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                               "got " + nnotifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        System.out.println("Got 0 notifs for initial fetch, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        long earliest = nr.getEarliestSequenceNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        long next = nr.getNextSequenceNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (earliest != next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            System.out.println("Expected earliest==next in initial fetch, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                               "earliest=" + earliest + "; next=" + next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        System.out.println("Got earliest==next in initial fetch, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        mbs.createMBean(MLet.class.getName(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        mbs.createMBean(NotificationSender.class.getName(), senderName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        NotificationSenderMBean sender = (NotificationSenderMBean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            MBeanServerInvocationHandler.newProxyInstance(mbs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                                          senderName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                                          NotificationSenderMBean.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                                          false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        /* We test here that MBeans already present when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
           NotificationBuffer was created get a listener for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
           buffer, as do MBeans created later.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
           MBeanServerDelegate was already present, while the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
           NotificationSender was created later.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // Check that the NotificationSender does indeed have a listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        /* Note we are dependent on the specifics of our JMX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
           implementation here.  There is no guarantee that the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
           creation listeners will have run to completion when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
           creation of the MBean returns.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        int nlisteners = sender.getListenerCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (nlisteners != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            System.out.println("Notification sender should have 1 listener, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                               "has " + nlisteners);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        System.out.println("Notification sender has 1 listener, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // Now we should see two creation notifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        nr = nb.fetchNotifications(allListenerFilter, next, 0L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                   Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        TargetedNotification[] tns = nr.getTargetedNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (tns.length != 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            System.out.println("Expected 2 notifs, got: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                               Arrays.asList(tns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (!(tns[0].getNotification() instanceof MBeanServerNotification)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            || !(tns[1].getNotification() instanceof MBeanServerNotification))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            System.out.println("Expected 2 MBeanServerNotifications, got: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                               Arrays.asList(tns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (!tns[0].getListenerID().equals(tns[1].getListenerID())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            || !tns[0].getListenerID().equals(allListenerId)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            System.out.println("Bad listener IDs: " + Arrays.asList(tns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        System.out.println("Got 2 different MBeanServerNotifications, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        // If we ask for max 1 notifs, we should only get one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        nr = nb.fetchNotifications(allListenerFilter, next, 0L, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        tns = nr.getTargetedNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (tns.length != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            System.out.println("Expected 1 notif, got: " + Arrays.asList(tns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        TargetedNotification tn1 = tns[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        System.out.println("Got 1 notif when asked for 1, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        // Now we should get the other one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        nr = nb.fetchNotifications(allListenerFilter, nr.getNextSequenceNumber(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                   0L, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        tns = nr.getTargetedNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (tns.length != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            System.out.println("Expected 1 notif, got: " + Arrays.asList(tns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        TargetedNotification tn2 = tns[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        System.out.println("Got 1 notif when asked for 1 again, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (tn1.getNotification() == tn2.getNotification()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            System.out.println("Returned same notif twice: " + tn1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        System.out.println("2 creation notifs are different, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        // Now we should get none (timeout is 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        long oldNext = nr.getNextSequenceNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        nr = nb.fetchNotifications(allListenerFilter, oldNext, 0L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                   Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        tns = nr.getTargetedNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (tns.length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            System.out.println("Expected 0 notifs, got: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                               Arrays.asList(tns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        System.out.println("Got 0 notifs with 0 timeout, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (nr.getNextSequenceNumber() != oldNext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            System.out.println("Sequence number changed: " + oldNext + " -> " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                               nr.getNextSequenceNumber());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        System.out.println("Next seqno unchanged with 0 timeout, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // Check that timeouts work
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        long startTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        nr = nb.fetchNotifications(allListenerFilter, oldNext, 250L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                   Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        tns = nr.getTargetedNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (tns.length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            System.out.println("Expected 0 notifs, got: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                               Arrays.asList(tns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        long endTime = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        long elapsed = endTime - startTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (elapsed < 250L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            System.out.println("Elapsed time shorter than timeout: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                               elapsed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        System.out.println("Timeout worked, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        // Check that notification filtering works
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        NotificationFilter senderFilter = new NotificationFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            public boolean isNotificationEnabled(Notification n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                if (!(n instanceof MBeanServerNotification))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                MBeanServerNotification mbsn = (MBeanServerNotification) n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                return (mbsn.getMBeanName().equals(senderName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        Integer senderListenerId = new Integer(88);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        NotificationBufferFilter senderListenerFilter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                makeFilter(senderListenerId, wildcardName, senderFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        nr = nb.fetchNotifications(senderListenerFilter, 0, 1000L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                   Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        tns = nr.getTargetedNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (tns.length != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            System.out.println("Expected 1 notif, got: " + Arrays.asList(tns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        MBeanServerNotification mbsn =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            (MBeanServerNotification) tns[0].getNotification();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (!mbsn.getMBeanName().equals(senderName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            System.out.println("Expected notif with senderName, got: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                               mbsn + " (" + mbsn.getMBeanName() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        System.out.println("Successfully applied NotificationFilter, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // Now send 8 notifs to fill up our 10-element buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        sender.sendNotifs("tiddly.pom", 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        nr = nb.fetchNotifications(allListenerFilter, 0, 1000L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                   Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        tns = nr.getTargetedNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (tns.length != 10) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            System.out.println("Expected 10 notifs, got: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                               Arrays.asList(tns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        System.out.println("Got full buffer of 10 notifications, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        // Check that the 10 notifs are the ones we expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        for (int i = 0; i < 10; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            String expected =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                (i < 2) ? notifType : "tiddly.pom";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            String found = tns[i].getNotification().getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            if (!found.equals(expected)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                System.out.println("Notif " + i + " bad type: expected <" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                                   expected + ">, found <" + found + ">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        System.out.println("Notifs have right types, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        // Check that ObjectName filtering works
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        NotificationBufferFilter senderNameFilter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                makeFilter(new Integer(66), senderName, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        nr = nb.fetchNotifications(senderNameFilter, 0, 0L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                                   Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        tns = nr.getTargetedNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        if (tns.length != 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            System.out.println("Bad result from ObjectName filtering: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                               Arrays.asList(tns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        System.out.println("ObjectName filtering works, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        // Send one more notif, which should cause the oldest one to drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        sender.sendNotifs("foo.bar", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        nr = nb.fetchNotifications(allListenerFilter, 0, 1000L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                   Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (nr.getEarliestSequenceNumber() <= earliest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            System.out.println("Expected earliest to increase: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                               nr.getEarliestSequenceNumber() + " should be > "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                               + earliest);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        System.out.println("Earliest notif dropped, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        // Check that the 10 notifs are the ones we expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        tns = nr.getTargetedNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        for (int i = 0; i < 10; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            String expected =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                (i < 1) ? notifType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                        : (i < 9) ? "tiddly.pom" : "foo.bar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            String found = tns[i].getNotification().getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            if (!found.equals(expected)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                System.out.println("Notif " + i + " bad type: expected <" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                   expected + ">, found <" + found + ">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        System.out.println("Notifs have right types, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        // Apply a filter that only selects the first notif, with max notifs 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        // then check that it skipped past the others even though it already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        // had its 1 notif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        NotificationBufferFilter firstFilter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                makeFilter(new Integer(55), wildcardName, regFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        nr = nb.fetchNotifications(firstFilter, 0, 1000L, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        tns = nr.getTargetedNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (tns.length != 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            || !tns[0].getNotification().getType().equals(notifType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            System.out.println("Unexpected return from filtered call: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                               Arrays.asList(tns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        nr = nb.fetchNotifications(allListenerFilter, nr.getNextSequenceNumber(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                                   0L, 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        tns = nr.getTargetedNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (tns.length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            System.out.println("Expected 0 notifs, got: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                               Arrays.asList(tns));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        // Create a second, larger buffer, which should share the same notifs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        nr = nb.fetchNotifications(allListenerFilter, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                   1000L, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        queuesize = new Integer(20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        env.put(com.sun.jmx.remote.util.EnvHelp.BUFFER_SIZE_PROPERTY, queuesize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        NotificationBuffer nb2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            ArrayNotificationBuffer.getNotificationBuffer(mbs, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        NotificationResult nr2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            nb2.fetchNotifications(allListenerFilter, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                   1000L, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (nr.getEarliestSequenceNumber() != nr2.getEarliestSequenceNumber()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            || nr.getNextSequenceNumber() != nr2.getNextSequenceNumber()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            || !sameTargetedNotifs(nr.getTargetedNotifications(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                   nr2.getTargetedNotifications()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        System.out.println("Adding second buffer preserved notif list, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        // Check that the capacity is now 20
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        sender.sendNotifs("propter.hoc", 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        nr2 = nb2.fetchNotifications(allListenerFilter, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                     1000L, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (nr.getEarliestSequenceNumber() !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            nr2.getEarliestSequenceNumber()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            System.out.println("Earliest seq number changed after notifs " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                               "that should have fit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        TargetedNotification[] tns2 = new TargetedNotification[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        Arrays.asList(nr2.getTargetedNotifications()).subList(0, 10).toArray(tns2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (!sameTargetedNotifs(nr.getTargetedNotifications(), tns2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            System.out.println("Early notifs changed after notifs " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                               "that should have fit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        System.out.println("New notifications fit in now-larger buffer, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        // Drop the second buffer and check that the capacity shrinks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        nb2.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        NotificationResult nr3 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            nb.fetchNotifications(allListenerFilter, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                                  1000L, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (nr3.getEarliestSequenceNumber() != nr.getNextSequenceNumber()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            System.out.println("After shrink, notifs not dropped as expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (nr3.getNextSequenceNumber() != nr2.getNextSequenceNumber()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            System.out.println("After shrink, next seq no does not match");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        tns2 = new TargetedNotification[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        Arrays.asList(nr2.getTargetedNotifications()).subList(10, 20).toArray(tns2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        if (!sameTargetedNotifs(nr3.getTargetedNotifications(), tns2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            System.out.println("Later notifs not preserved after shrink");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        System.out.println("Dropping second buffer shrank capacity, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        // Final test: check that destroying the final shared buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // removes its listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        nb.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        nlisteners = sender.getListenerCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (nlisteners != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            System.out.println("Disposing buffer should leave 0 listeners, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                               "but notification sender has " + nlisteners);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        System.out.println("Dropping first buffer drops listeners, OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    private static boolean sameTargetedNotifs(TargetedNotification[] tn1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                              TargetedNotification[] tn2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (tn1.length != tn2.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            System.out.println("Not same length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        for (int i = 0; i < tn1.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            TargetedNotification n1 = tn1[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            TargetedNotification n2 = tn2[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            if (n1.getNotification() != n2.getNotification()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                || !n1.getListenerID().equals(n2.getListenerID()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    private static NotificationBufferFilter makeFilter(final Integer id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                                                       final ObjectName pattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                                                       final NotificationFilter filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        return new NotificationBufferFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            public void apply(List<TargetedNotification> notifs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                              ObjectName source, Notification notif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                if (pattern.apply(source)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    if (filter == null || filter.isNotificationEnabled(notif))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        notifs.add(new TargetedNotification(notif, id));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
}