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