javax.management.MBeanServerConnection#removeNotificationListener ( )源码实例Demo

下面列出了javax.management.MBeanServerConnection#removeNotificationListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter,
    Object handback) throws InstanceNotFoundException, ListenerNotFoundException, IOException {
  
  //throw new UnsupportedOperationException("GemfireMBeanServerConnection does not implement this opeation ");
  MBeanServerConnection server = ManagementUtil.getPlatformMBeanServer();
  server.removeNotificationListener(name,listener,filter,handback);
  
}
 
@Override
public void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter,
    Object handback) throws InstanceNotFoundException, ListenerNotFoundException, IOException {
  //throw new UnsupportedOperationException("GemfireMBeanServerConnection does not implement this opeation ");
  MBeanServerConnection server = ManagementUtil.getPlatformMBeanServer();
  server.removeNotificationListener(name, listener,filter,handback);
}
 
@Override
public void removeNotificationListener(ObjectName name, ObjectName listener) throws InstanceNotFoundException,
    ListenerNotFoundException, IOException {
  //throw new UnsupportedOperationException("GemfireMBeanServerConnection does not implement this opeation ");
  MBeanServerConnection server = ManagementUtil.getPlatformMBeanServer();
  server.removeNotificationListener(name, listener);
  
}
 
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);
}
 
@Override
public void removeNotificationListener(ObjectName name, ObjectName listener) throws InstanceNotFoundException,
    ListenerNotFoundException, IOException {
  //throw new UnsupportedOperationException("GemfireMBeanServerConnection does not implement this opeation ");
  MBeanServerConnection server = ManagementUtil.getPlatformMBeanServer();
  server.removeNotificationListener(name, listener);
  
}
 
源代码6 项目: jdk8u-jdk   文件: EmptyDomainNotificationTest.java
public static void main(String[] args) throws Exception {

        final MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");

        JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
        server.start();

        JMXConnector client = JMXConnectorFactory.connect(server.getAddress(), null);

        final MBeanServerConnection mbsc = client.getMBeanServerConnection();

        final ObjectName mbean = ObjectName.getInstance(":type=Simple");
        mbsc.createMBean(Simple.class.getName(), mbean);

        System.out.println("EmptyDomainNotificationTest-main: add a listener ...");
        final Listener li = new Listener();
        mbsc.addNotificationListener(mbean, li, null, null);

        System.out.println("EmptyDomainNotificationTest-main: ask to send a notif ...");
        mbsc.invoke(mbean, "emitNotification", null, null);

        System.out.println("EmptyDomainNotificationTest-main: waiting notif...");
        final long stopTime = System.currentTimeMillis() + 2000;
        synchronized(li) {
            long toWait = stopTime - System.currentTimeMillis();

            while (li.received < 1 && toWait > 0) {
                li.wait(toWait);

                toWait = stopTime - System.currentTimeMillis();
            }
        }

        if (li.received < 1) {
            throw new RuntimeException("No notif received!");
        } else if (li.received > 1) {
            throw new RuntimeException("Wait one notif but got: "+li.received);
        }

        System.out.println("EmptyDomainNotificationTest-main: Got the expected notif!");

        System.out.println("EmptyDomainNotificationTest-main: remove the listener.");
        mbsc.removeNotificationListener(mbean, li);

        // clean
        client.close();
        server.stop();

        System.out.println("EmptyDomainNotificationTest-main: Bye.");
    }
 
源代码7 项目: openjdk-8-source   文件: RMIExitTest.java
private static void test() {
    try {
        JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer server;
        JMXServiceURL addr;
        JMXConnector client;
        MBeanServerConnection mserver;

        final ObjectName delegateName =
            new ObjectName("JMImplementation:type=MBeanServerDelegate");
        final NotificationListener dummyListener =
            new NotificationListener() {
                    public void handleNotification(Notification n,
                                                   Object o) {
                        // do nothing
                        return;
                    }
                };

        server = JMXConnectorServerFactory.newJMXConnectorServer(u,
                                                                 null,
                                                                 mbs);
        server.start();

        addr = server.getAddress();
        client = JMXConnectorFactory.newJMXConnector(addr, null);
        client.connect(null);

        mserver = client.getMBeanServerConnection();
        String s1 = "1";
        String s2 = "2";
        String s3 = "3";

        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s1);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s2);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s3);

        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s3);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s2);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s1);
        client.close();

        server.stop();
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
    }
}
 
源代码8 项目: jdk8u-jdk   文件: UnexpectedNotifTest.java
private static void test() throws Exception {
    // Create client
    //
    JMXConnector connector = JMXConnectorFactory.connect(url);
    MBeanServerConnection client = connector.getMBeanServerConnection();

    // Add listener at the client side
    //
    client.addNotificationListener(mbean, listener, null, null);

    // Cleanup
    //
    receivedNotifs = 0;

    // Ask to send notifs
    //
    Object[] params = new Object[] {new Integer(nb)};
    String[] signatures = new String[] {"java.lang.Integer"};

    client.invoke(mbean, "sendNotifications", params, signatures);

    // Waiting...
    //
    synchronized (lock) {
        for (int i = 0; i < 10; i++) {
            if (receivedNotifs < nb) {
                lock.wait(1000);
            }
        }
    }

    // Waiting again to ensure no more notifs
    //
    Thread.sleep(3000);

    synchronized (lock) {
        if (receivedNotifs != nb) {
            throw new Exception("The client expected to receive " +
                                nb + " notifs, but got " + receivedNotifs);
        }
    }

    // Remove listener
    //
    client.removeNotificationListener(mbean, listener);

    connector.close();
}
 
public static void main(String[] args) throws Exception {

        final MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");

        JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
        server.start();

        JMXConnector client = JMXConnectorFactory.connect(server.getAddress(), null);

        final MBeanServerConnection mbsc = client.getMBeanServerConnection();

        final ObjectName mbean = ObjectName.getInstance(":type=Simple");
        mbsc.createMBean(Simple.class.getName(), mbean);

        System.out.println("EmptyDomainNotificationTest-main: add a listener ...");
        final Listener li = new Listener();
        mbsc.addNotificationListener(mbean, li, null, null);

        System.out.println("EmptyDomainNotificationTest-main: ask to send a notif ...");
        mbsc.invoke(mbean, "emitNotification", null, null);

        System.out.println("EmptyDomainNotificationTest-main: waiting notif...");
        synchronized(li) {
            while (li.received < 1) {
                li.wait();
            }
        }

        if (li.received != 1) {
            throw new RuntimeException("Wait one notif but got: "+li.received);
        }

        System.out.println("EmptyDomainNotificationTest-main: Got the expected notif!");

        System.out.println("EmptyDomainNotificationTest-main: remove the listener.");
        mbsc.removeNotificationListener(mbean, li);

        // clean
        client.close();
        server.stop();

        System.out.println("EmptyDomainNotificationTest-main: Bye.");
    }
 
源代码10 项目: hottub   文件: UnexpectedNotifTest.java
private static void test() throws Exception {
    // Create client
    //
    JMXConnector connector = JMXConnectorFactory.connect(url);
    MBeanServerConnection client = connector.getMBeanServerConnection();

    // Add listener at the client side
    //
    client.addNotificationListener(mbean, listener, null, null);

    // Cleanup
    //
    receivedNotifs = 0;

    // Ask to send notifs
    //
    Object[] params = new Object[] {new Integer(nb)};
    String[] signatures = new String[] {"java.lang.Integer"};

    client.invoke(mbean, "sendNotifications", params, signatures);

    // Waiting...
    //
    synchronized (lock) {
        for (int i = 0; i < 10; i++) {
            if (receivedNotifs < nb) {
                lock.wait(1000);
            }
        }
    }

    // Waiting again to ensure no more notifs
    //
    Thread.sleep(3000);

    synchronized (lock) {
        if (receivedNotifs != nb) {
            throw new Exception("The client expected to receive " +
                                nb + " notifs, but got " + receivedNotifs);
        }
    }

    // Remove listener
    //
    client.removeNotificationListener(mbean, listener);

    connector.close();
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: RMIExitTest.java
private static void test() {
    try {
        JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer server;
        JMXServiceURL addr;
        JMXConnector client;
        MBeanServerConnection mserver;

        final ObjectName delegateName =
            new ObjectName("JMImplementation:type=MBeanServerDelegate");
        final NotificationListener dummyListener =
            new NotificationListener() {
                    public void handleNotification(Notification n,
                                                   Object o) {
                        // do nothing
                        return;
                    }
                };

        server = JMXConnectorServerFactory.newJMXConnectorServer(u,
                                                                 null,
                                                                 mbs);
        server.start();

        addr = server.getAddress();
        client = JMXConnectorFactory.newJMXConnector(addr, null);
        client.connect(null);

        mserver = client.getMBeanServerConnection();
        String s1 = "1";
        String s2 = "2";
        String s3 = "3";

        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s1);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s2);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s3);

        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s3);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s2);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s1);
        client.close();

        server.stop();
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
    }
}
 
源代码12 项目: openjdk-8   文件: UnexpectedNotifTest.java
private static void test() throws Exception {
    // Create client
    //
    JMXConnector connector = JMXConnectorFactory.connect(url);
    MBeanServerConnection client = connector.getMBeanServerConnection();

    // Add listener at the client side
    //
    client.addNotificationListener(mbean, listener, null, null);

    // Cleanup
    //
    receivedNotifs = 0;

    // Ask to send notifs
    //
    Object[] params = new Object[] {new Integer(nb)};
    String[] signatures = new String[] {"java.lang.Integer"};

    client.invoke(mbean, "sendNotifications", params, signatures);

    // Waiting...
    //
    synchronized (lock) {
        for (int i = 0; i < 10; i++) {
            if (receivedNotifs < nb) {
                lock.wait(1000);
            }
        }
    }

    // Waiting again to ensure no more notifs
    //
    Thread.sleep(3000);

    synchronized (lock) {
        if (receivedNotifs != nb) {
            throw new Exception("The client expected to receive " +
                                nb + " notifs, but got " + receivedNotifs);
        }
    }

    // Remove listener
    //
    client.removeNotificationListener(mbean, listener);

    connector.close();
}
 
源代码13 项目: jdk8u60   文件: EmptyDomainNotificationTest.java
public static void main(String[] args) throws Exception {

        final MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");

        JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
        server.start();

        JMXConnector client = JMXConnectorFactory.connect(server.getAddress(), null);

        final MBeanServerConnection mbsc = client.getMBeanServerConnection();

        final ObjectName mbean = ObjectName.getInstance(":type=Simple");
        mbsc.createMBean(Simple.class.getName(), mbean);

        System.out.println("EmptyDomainNotificationTest-main: add a listener ...");
        final Listener li = new Listener();
        mbsc.addNotificationListener(mbean, li, null, null);

        System.out.println("EmptyDomainNotificationTest-main: ask to send a notif ...");
        mbsc.invoke(mbean, "emitNotification", null, null);

        System.out.println("EmptyDomainNotificationTest-main: waiting notif...");
        final long stopTime = System.currentTimeMillis() + 2000;
        synchronized(li) {
            long toWait = stopTime - System.currentTimeMillis();

            while (li.received < 1 && toWait > 0) {
                li.wait(toWait);

                toWait = stopTime - System.currentTimeMillis();
            }
        }

        if (li.received < 1) {
            throw new RuntimeException("No notif received!");
        } else if (li.received > 1) {
            throw new RuntimeException("Wait one notif but got: "+li.received);
        }

        System.out.println("EmptyDomainNotificationTest-main: Got the expected notif!");

        System.out.println("EmptyDomainNotificationTest-main: remove the listener.");
        mbsc.removeNotificationListener(mbean, li);

        // clean
        client.close();
        server.stop();

        System.out.println("EmptyDomainNotificationTest-main: Bye.");
    }
 
源代码14 项目: jdk8u60   文件: NotSerializableNotifTest.java
private static void test(String proto) throws Exception {
    System.out.println("\n>>> Test for protocol " + proto);

    JMXServiceURL url = new JMXServiceURL(proto, null, 0);

    System.out.println(">>> Create a server: "+url);

    JMXConnectorServer server = null;
    try {
        server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbeanServer);
    } catch (MalformedURLException e) {
        System.out.println("System does not recognize URL: " + url +
                           "; ignoring");
        return;
    }

    server.start();

    url = server.getAddress();

    System.out.println(">>> Creating a client connectint to: "+url);
    JMXConnector conn = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection client = conn.getMBeanServerConnection();

    // add listener from the client side
    Listener listener = new Listener();
    client.addNotificationListener(emitter, listener, null, null);

    // ask to send one not serializable notif
    Object[] params = new Object[] {new Integer(1)};
    String[] signatures = new String[] {"java.lang.Integer"};
    client.invoke(emitter, "sendNotserializableNotifs", params, signatures);

    // listener clean
    client.removeNotificationListener(emitter, listener);
    listener = new Listener();
    client.addNotificationListener(emitter, listener, null, null);

    //ask to send serializable notifs
    params = new Object[] {new Integer(sentNotifs)};
    client.invoke(emitter, "sendNotifications", params, signatures);

    // waiting ...
    synchronized (listener) {
        while (listener.received() < sentNotifs) {
            listener.wait(); // either pass or test timeout (killed by test harness)

        }
    }

    // clean
    client.removeNotificationListener(emitter, listener);

    conn.close();
    server.stop();
}
 
源代码15 项目: jdk8u-jdk   文件: NotSerializableNotifTest.java
private static void test(String proto) throws Exception {
    System.out.println("\n>>> Test for protocol " + proto);

    JMXServiceURL url = new JMXServiceURL(proto, null, 0);

    System.out.println(">>> Create a server: "+url);

    JMXConnectorServer server = null;
    try {
        server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbeanServer);
    } catch (MalformedURLException e) {
        System.out.println("System does not recognize URL: " + url +
                           "; ignoring");
        return;
    }

    server.start();

    url = server.getAddress();

    System.out.println(">>> Creating a client connectint to: "+url);
    JMXConnector conn = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection client = conn.getMBeanServerConnection();

    // add listener from the client side
    Listener listener = new Listener();
    client.addNotificationListener(emitter, listener, null, null);

    // ask to send one not serializable notif
    Object[] params = new Object[] {new Integer(1)};
    String[] signatures = new String[] {"java.lang.Integer"};
    client.invoke(emitter, "sendNotserializableNotifs", params, signatures);

    // listener clean
    client.removeNotificationListener(emitter, listener);
    listener = new Listener();
    client.addNotificationListener(emitter, listener, null, null);

    //ask to send serializable notifs
    params = new Object[] {new Integer(sentNotifs)};
    client.invoke(emitter, "sendNotifications", params, signatures);

    // waiting ...
    synchronized (listener) {
        while (listener.received() < sentNotifs) {
            listener.wait(); // either pass or test timeout (killed by test harness)

        }
    }

    // clean
    client.removeNotificationListener(emitter, listener);

    conn.close();
    server.stop();
}
 
源代码16 项目: jdk8u60   文件: UnexpectedNotifTest.java
private static void test() throws Exception {
    // Create client
    //
    JMXConnector connector = JMXConnectorFactory.connect(url);
    MBeanServerConnection client = connector.getMBeanServerConnection();

    // Add listener at the client side
    //
    client.addNotificationListener(mbean, listener, null, null);

    // Cleanup
    //
    receivedNotifs = 0;

    // Ask to send notifs
    //
    Object[] params = new Object[] {new Integer(nb)};
    String[] signatures = new String[] {"java.lang.Integer"};

    client.invoke(mbean, "sendNotifications", params, signatures);

    // Waiting...
    //
    synchronized (lock) {
        for (int i = 0; i < 10; i++) {
            if (receivedNotifs < nb) {
                lock.wait(1000);
            }
        }
    }

    // Waiting again to ensure no more notifs
    //
    Thread.sleep(3000);

    synchronized (lock) {
        if (receivedNotifs != nb) {
            throw new Exception("The client expected to receive " +
                                nb + " notifs, but got " + receivedNotifs);
        }
    }

    // Remove listener
    //
    client.removeNotificationListener(mbean, listener);

    connector.close();
}
 
public static void main(String[] args) throws Exception {

        final MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");

        JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
        server.start();

        JMXConnector client = JMXConnectorFactory.connect(server.getAddress(), null);

        final MBeanServerConnection mbsc = client.getMBeanServerConnection();

        final ObjectName mbean = ObjectName.getInstance(":type=Simple");
        mbsc.createMBean(Simple.class.getName(), mbean);

        System.out.println("EmptyDomainNotificationTest-main: add a listener ...");
        final Listener li = new Listener();
        mbsc.addNotificationListener(mbean, li, null, null);

        System.out.println("EmptyDomainNotificationTest-main: ask to send a notif ...");
        mbsc.invoke(mbean, "emitNotification", null, null);

        System.out.println("EmptyDomainNotificationTest-main: waiting notif...");
        final long stopTime = System.currentTimeMillis() + 2000;
        synchronized(li) {
            long toWait = stopTime - System.currentTimeMillis();

            while (li.received < 1 && toWait > 0) {
                li.wait(toWait);

                toWait = stopTime - System.currentTimeMillis();
            }
        }

        if (li.received < 1) {
            throw new RuntimeException("No notif received!");
        } else if (li.received > 1) {
            throw new RuntimeException("Wait one notif but got: "+li.received);
        }

        System.out.println("EmptyDomainNotificationTest-main: Got the expected notif!");

        System.out.println("EmptyDomainNotificationTest-main: remove the listener.");
        mbsc.removeNotificationListener(mbean, li);

        // clean
        client.close();
        server.stop();

        System.out.println("EmptyDomainNotificationTest-main: Bye.");
    }
 
private static void test(String proto) throws Exception {
    System.out.println("\n>>> Test for protocol " + proto);

    JMXServiceURL url = new JMXServiceURL(proto, null, 0);

    System.out.println(">>> Create a server: "+url);

    JMXConnectorServer server = null;
    try {
        server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbeanServer);
    } catch (MalformedURLException e) {
        System.out.println("System does not recognize URL: " + url +
                           "; ignoring");
        return;
    }

    server.start();

    url = server.getAddress();

    System.out.println(">>> Creating a client connectint to: "+url);
    JMXConnector conn = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection client = conn.getMBeanServerConnection();

    // add listener from the client side
    Listener listener = new Listener();
    client.addNotificationListener(emitter, listener, null, null);

    // ask to send one not serializable notif
    Object[] params = new Object[] {new Integer(1)};
    String[] signatures = new String[] {"java.lang.Integer"};
    client.invoke(emitter, "sendNotserializableNotifs", params, signatures);

    // listener clean
    client.removeNotificationListener(emitter, listener);
    listener = new Listener();
    client.addNotificationListener(emitter, listener, null, null);

    //ask to send serializable notifs
    params = new Object[] {new Integer(sentNotifs)};
    client.invoke(emitter, "sendNotifications", params, signatures);

    // waiting ...
    synchronized (listener) {
        while (listener.received() < sentNotifs) {
            listener.wait(); // either pass or test timeout (killed by test harness)

        }
    }

    // clean
    client.removeNotificationListener(emitter, listener);

    conn.close();
    server.stop();
}
 
源代码19 项目: openjdk-jdk8u   文件: UnexpectedNotifTest.java
private static void test() throws Exception {
    // Create client
    //
    JMXConnector connector = JMXConnectorFactory.connect(url);
    MBeanServerConnection client = connector.getMBeanServerConnection();

    // Add listener at the client side
    //
    client.addNotificationListener(mbean, listener, null, null);

    // Cleanup
    //
    receivedNotifs = 0;

    // Ask to send notifs
    //
    Object[] params = new Object[] {new Integer(nb)};
    String[] signatures = new String[] {"java.lang.Integer"};

    client.invoke(mbean, "sendNotifications", params, signatures);

    // Waiting...
    //
    synchronized (lock) {
        for (int i = 0; i < 10; i++) {
            if (receivedNotifs < nb) {
                lock.wait(1000);
            }
        }
    }

    // Waiting again to ensure no more notifs
    //
    Thread.sleep(3000);

    synchronized (lock) {
        if (receivedNotifs != nb) {
            throw new Exception("The client expected to receive " +
                                nb + " notifs, but got " + receivedNotifs);
        }
    }

    // Remove listener
    //
    client.removeNotificationListener(mbean, listener);

    connector.close();
}
 
源代码20 项目: openjdk-jdk8u   文件: RMIExitTest.java
private static void test() {
    try {
        JMXServiceURL u = new JMXServiceURL("rmi", null, 0);
        JMXConnectorServer server;
        JMXServiceURL addr;
        JMXConnector client;
        MBeanServerConnection mserver;

        final ObjectName delegateName =
            new ObjectName("JMImplementation:type=MBeanServerDelegate");
        final NotificationListener dummyListener =
            new NotificationListener() {
                    public void handleNotification(Notification n,
                                                   Object o) {
                        // do nothing
                        return;
                    }
                };

        server = JMXConnectorServerFactory.newJMXConnectorServer(u,
                                                                 null,
                                                                 mbs);
        server.start();

        addr = server.getAddress();
        client = JMXConnectorFactory.newJMXConnector(addr, null);
        client.connect(null);

        mserver = client.getMBeanServerConnection();
        String s1 = "1";
        String s2 = "2";
        String s3 = "3";

        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s1);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s2);
        mserver.addNotificationListener(delegateName,
                                        dummyListener, null, s3);

        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s3);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s2);
        mserver.removeNotificationListener(delegateName,
                                           dummyListener, null, s1);
        client.close();

        server.stop();
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        System.exit(1);
    }
}