类javax.management.NotificationFilterSupport源码实例Demo

下面列出了怎么用javax.management.NotificationFilterSupport的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: groovy   文件: JmxBuilderModelMBean.java
/**
 * Sets up event listeners for this MBean as described in the descriptor.
 * The descriptor contains a map with layout
 * {item -> Map[event:"...", from:ObjectName, callback:&Closure],...,}
 *
 * @param server     the MBeanServer is to be registered.
 * @param descriptor a map containing info about the event
 */
public void addEventListeners(MBeanServer server, Map<String, Map<String, Object>> descriptor) {
    for (Map.Entry<String, Map<String, Object>> item : descriptor.entrySet()) {
        Map<String, Object> listener = item.getValue();

        // register with server
        ObjectName broadcaster = (ObjectName) listener.get("from");
        try {
            String eventType = (String) listener.get("event");

            if (eventType != null) {
                NotificationFilterSupport filter = new NotificationFilterSupport();
                filter.enableType(eventType);
                server.addNotificationListener(broadcaster, JmxEventListener.getListener(), filter, listener);
            } else {
                server.addNotificationListener(broadcaster, JmxEventListener.getListener(), null, listener);
            }
        } catch (InstanceNotFoundException e) {
            throw new JmxBuilderException(e);
        }
    }
}
 
@Test
public void testNotificationTccl() throws Exception {
    ObjectName objName = createName("test.domain:bean=test-tccl");
    server.registerMBean(new TestBean(objName), objName);
    ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    ClassLoader newOutTccl = new URLClassLoader(new URL[]{}, oldTccl); // creating a new class loader here
    WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(newOutTccl);
    try {
        final AtomicBoolean differ = new AtomicBoolean(false);
        NotificationFilterSupport filter = new NotificationFilterSupport();
        filter.enableType("testtccl");
        server.addNotificationListener(objName, new NotificationListener() {
            @Override
            public void handleNotification(Notification notification, Object handback) {
                Assert.assertEquals("callback", handback.toString());
                ClassLoader newInTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
                Assert.assertNotEquals(newInTccl, newOutTccl);
                differ.set(true);
            }
        }, filter, "callback");
        server.invoke(objName, "proceed", null, null);
        Assert.assertTrue(differ.get());
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
    }
}
 
源代码3 项目: jdk1.8-source-analysis   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码4 项目: dragonwell8_jdk   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码5 项目: TencentKona-8   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码6 项目: jdk8u60   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码7 项目: JDKSourceCode1.8   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码8 项目: openjdk-jdk8u   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码10 项目: openjdk-jdk9   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码11 项目: jdk8u-jdk   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码12 项目: Java8CN   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码13 项目: hottub   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码14 项目: openjdk-8-source   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码15 项目: gemfirexd-oss   文件: JMXHelper.java
/**
 * the INITTASKS calling connectToDS across ThreadGroups 
 * should be executed with the keyword SEQUENTIAL
 * <p>
 * Must be invoked after the JMX agents have been created, started, and
 * connected using {@link hydra.AgentHelper}.
 */
public static void connectToDS() throws Exception
{
  // Connect To DS
  connectToDSButDoNotAttachListeners();

  //Register the stat alert notification listener as well.
  listener = new StatAlertNotificationListener(40);
  NotificationFilterSupport support = new NotificationFilterSupport();
  support.enableType(AdminDistributedSystemJmxImpl.NOTIF_STAT_ALERT);
  mbsc.addNotificationListener(distributedSys, listener, support, new Object());
  
  logger.info("Connected to JMX ADS " + distributedSys);
}
 
源代码16 项目: openjdk-8   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码17 项目: jdk8u_jdk   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码18 项目: gemfirexd-oss   文件: JMXHelper.java
/**
 * the INITTASKS calling connectToDS across ThreadGroups 
 * should be executed with the keyword SEQUENTIAL
 * <p>
 * Must be invoked after the JMX agents have been created, started, and
 * connected using {@link hydra.AgentHelper}.
 */
public static void connectToDS() throws Exception
{
  // Connect To DS
  connectToDSButDoNotAttachListeners();

  //Register the stat alert notification listener as well.
  listener = new StatAlertNotificationListener(40);
  NotificationFilterSupport support = new NotificationFilterSupport();
  support.enableType(AdminDistributedSystemJmxImpl.NOTIF_STAT_ALERT);
  mbsc.addNotificationListener(distributedSys, listener, support, new Object());
  
  logger.info("Connected to JMX ADS " + distributedSys);
}
 
源代码19 项目: groovy   文件: JmxBuilderModelMBean.java
/**
 * Registers listeners for operation calls (i.e. method, getter, and setter calls) when
 * invoked on this bean from the MBeanServer.  Descriptor should contain a map with layout
 * {@code item -> [Map[methodListener:[target:"", tpe:"", callback:&Closure], ... ,]]}
 *
 * @param descriptor MetaMap descriptor containing description of operation call listeners
 */
public void addOperationCallListeners(Map<String, Map<String, Map<String, Object>>> descriptor) {
    if (descriptor == null) return;
    for (Map.Entry<String, Map<String, Map<String, Object>>> item : descriptor.entrySet()) {
        // set up method listeners (such as attributeListener and Operation Listeners)
        // item -> [Map[methodListener:[target:"", tpe:"", callback:&Closure], ... ,]]
        if (item.getValue().containsKey("methodListener")) {
            Map<String, Object> listener = item.getValue().get("methodListener");
            String target = (String) listener.get("target");
            methodListeners.add(target);
            String listenerType = (String) listener.get("type");
            listener.put("managedObject", this.managedObject);
            // register an attribute change notification listener with model mbean
            if (listenerType.equals("attributeChangeListener")) {
                try {
                    this.addAttributeChangeNotificationListener(
                            AttributeChangedListener.getListener(), (String) listener.get("attribute"), listener
                    );
                } catch (MBeanException e) {
                    throw new JmxBuilderException(e);
                }
            }
            if (listenerType.equals("operationCallListener")) {
                String eventType = "jmx.operation.call." + target;
                NotificationFilterSupport filter = new NotificationFilterSupport();
                filter.enableType(eventType);
                this.addNotificationListener(JmxEventListener.getListener(), filter, listener);
            }
        }
    }
}
 
源代码20 项目: jdk8u-jdk   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码21 项目: jdk8u-dev-jdk   文件: RMIConnector.java
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
    NotificationFilterSupport clientFilter =
            new NotificationFilterSupport();
    clientFilter.enableType(
            MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
    MarshalledObject<NotificationFilter> sFilter =
        new MarshalledObject<NotificationFilter>(clientFilter);

    Integer[] listenerIDs;
    final ObjectName[] names =
        new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
    final MarshalledObject<NotificationFilter>[] filters =
        Util.cast(new MarshalledObject<?>[] {sFilter});
    final Subject[] subjects = new Subject[] {null};
    try {
        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);

    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        listenerIDs =
                connection.addNotificationListeners(names,
                filters,
                subjects);
    }
    return listenerIDs[0];
}
 
源代码22 项目: brooklyn-server   文件: JmxNotificationFilters.java
/**
 * Matches any of the given notification types.
 * @see {@link NotificationFilterSupport#enableType(String)}
 */
public static NotificationFilter matchesTypes(String... types) {
    NotificationFilterSupport result = new NotificationFilterSupport();
    for (String type : types) {
        result.enableType(type);
    }
    return result;
}
 
public void doTestMBeanServerNotification_REGISTRATION_NOTIFICATION(MBeanServerConnection connection, boolean mustReceiveNotification) throws Exception {
    final ObjectName testObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test");
    final ObjectName childObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test,single=only");

    final CountDownLatch notificationEmitted = new CountDownLatch(1);
    final AtomicReference<Notification> notification = new AtomicReference<>();
    NotificationListener listener = new MbeanServerNotificationListener(notification, notificationEmitted, LEGACY_DOMAIN);
    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION);

    connection.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null);

    // add a management resource
    connection.invoke(testObjectName, "addSingleOnly", new Object[]{123}, new String[]{String.class.getName()});

    if (mustReceiveNotification) {
        Assert.assertTrue("Did not receive expected notification", notificationEmitted.await(1, TimeUnit.SECONDS));
        Notification notif = notification.get();
        Assert.assertNotNull(notif);
        Assert.assertTrue(notif instanceof MBeanServerNotification);
        MBeanServerNotification mBeanServerNotification = (MBeanServerNotification) notif;
        Assert.assertEquals(MBeanServerNotification.REGISTRATION_NOTIFICATION, notif.getType());
        Assert.assertEquals(childObjectName, mBeanServerNotification.getMBeanName());
    } else {
        Assert.assertFalse("Did receive unexpected notification", notificationEmitted.await(500, TimeUnit.MILLISECONDS));
    }

    connection.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null);
}
 
private void doTestMBeanServerNotification_UNREGISTRATION_NOTIFICATION(MBeanServerConnection connection, boolean mustReceiveNotification) throws Exception {
    final ObjectName testObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test");
    final ObjectName childObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test,single=only");

    final CountDownLatch notificationEmitted = new CountDownLatch(1);
    final AtomicReference<Notification> notification = new AtomicReference<>();

    NotificationListener listener = new MbeanServerNotificationListener(notification, notificationEmitted, LEGACY_DOMAIN);
    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION);

    connection.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null);

    // add a management resource
    connection.invoke(testObjectName, "addSingleOnly", new Object[]{123}, new String[]{String.class.getName()});
    // and remove it
    connection.invoke(childObjectName, "remove", new Object[0], new String[0]);

    if (mustReceiveNotification) {
        Assert.assertTrue("Did not receive expected notification", notificationEmitted.await(1, TimeUnit.SECONDS));
        Notification notif = notification.get();
        Assert.assertNotNull(notif);
        Assert.assertTrue(notif instanceof MBeanServerNotification);
        MBeanServerNotification mBeanServerNotification = (MBeanServerNotification) notif;
        Assert.assertEquals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION, mBeanServerNotification.getType());
        Assert.assertEquals(childObjectName, mBeanServerNotification.getMBeanName());
    } else {
        Assert.assertFalse("Did receive unexpected notification", notificationEmitted.await(500, TimeUnit.MILLISECONDS));
    }

    connection.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null);
}
 
源代码25 项目: logging-log4j2   文件: ClientGui.java
public ClientGui(final Client client) throws IOException, JMException {
    this.client = Objects.requireNonNull(client, "client");
    createWidgets();
    populateWidgets();

    // register for Notifications if LoggerContext MBean was added/removed
    final ObjectName addRemoveNotifs = MBeanServerDelegate.DELEGATE_NAME;
    final NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(Server.DOMAIN); // only interested in Log4J2 MBeans
    client.getConnection().addNotificationListener(addRemoveNotifs, this, null, null);
}
 
源代码26 项目: logging-log4j2   文件: ClientGui.java
private void registerListeners(final StatusLoggerAdminMBean status) throws InstanceNotFoundException,
        MalformedObjectNameException, IOException {
    final NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(StatusLoggerAdminMBean.NOTIF_TYPE_MESSAGE);
    final ObjectName objName = status.getObjectName();
    // System.out.println("Add listener for " + objName);
    client.getConnection().addNotificationListener(objName, this, filter, status.getContextName());
}
 
 类所在包
 类方法
 同包方法