当前位置: 首页>>代码示例>>Java>>正文


Java MBeanServerConnection.addNotificationListener方法代码示例

本文整理汇总了Java中javax.management.MBeanServerConnection.addNotificationListener方法的典型用法代码示例。如果您正苦于以下问题:Java MBeanServerConnection.addNotificationListener方法的具体用法?Java MBeanServerConnection.addNotificationListener怎么用?Java MBeanServerConnection.addNotificationListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.management.MBeanServerConnection的用法示例。


在下文中一共展示了MBeanServerConnection.addNotificationListener方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: listenerOp

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static void listenerOp(MBeanServerConnection mserver, NotificationListener listener, boolean adding)
        throws Exception {
    if (adding) {
        mserver.addNotificationListener(delegateName, listener, null, null);
    } else {
        mserver.removeNotificationListener(delegateName, listener);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:ConcurrentModificationTest.java

示例2: FlagJMXProxy

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public FlagJMXProxy(final ObjectName source, final MBeanServerConnection mbsc, final String flagName) throws MalformedObjectNameException {
    ObjectName name = PogamutJMX.getObjectName(source, flagName, PogamutJMX.FLAGS_SUBTYPE);
    try {
        listener = new NotificationListener() {

            @Override
            public void handleNotification(Notification notification, Object handback) {
                if (notification.getSource().equals(source) && notification.getType().equals(flagName)) {
                    setFlag((T) notification.getUserData());
                }
            }
        };
        // get current value of the flag
        T val = (T) mbsc.getAttribute(name, "Flag");
        setFlag(val);

        /* NOTE filters are send over RMI to the server !!! it is better to
         handle filtering in the listener itself.
         
        NotificationFilter nf = new NotificationFilter() {

        @Override
        public boolean isNotificationEnabled(Notification notification) {
        return notification.getSource().equals(source) && notification.getType().equals(flagName);
        }
        };
         */
        mbsc.addNotificationListener(name, listener, null, mbsc);
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex);
    }
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:34,代码来源:FlagJMXProxy.java

示例3: registerAsJMXListener

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static void registerAsJMXListener(final MBeanServerConnection mBeanServerConnection, final NotificationListener listener) {
    LOG.trace("Called registerAsJMXListener");
    try {
        mBeanServerConnection.addNotificationListener(ConfigJMXNotification.OBJECT_NAME, listener, null, null);
    } catch (InstanceNotFoundException | IOException e) {
        throw new IllegalStateException("Cannot register as JMX listener to netconf", e);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:9,代码来源:ConfigPersisterNotificationHandler.java

示例4: receiveLogEventThroughJMX

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
@Test
public void receiveLogEventThroughJMX()
		throws InstanceAlreadyExistsException, MBeanRegistrationException,
		NotCompliantMBeanException, MalformedObjectNameException,
		PogamutException, MalformedURLException, IOException,
		InterruptedException, MBeanException, InstanceNotFoundException,
		AttributeNotFoundException, ReflectionException {
	
	final String testMsg = "TEST LOG MESSAGE FROM receiveLogEventThroughJMX()";
	
	ObjectName parentName = PogamutJMX.getObjectName("testDomain", "root", "test");
	
	
	// export the log on the MBean server
	ILogCategories logCategories = new LogCategories();
	
	String testLogCategoryNameStr = "testLogCategory";
	LogCategory testLog = logCategories.getCategory(testLogCategoryNameStr);
			
	JMXLogCategories jmxLogCategories = new JMXLogCategories(
			logCategories,
			Pogamut.getPlatform().getMBeanServer(),
			parentName
	);

	// connect through RMI and get the proxy
	MBeanServerConnection mbsc = Pogamut.getPlatform().getMBeanServerConnection();
	ObjectName logCatsName = jmxLogCategories.getJMXLogCategoriesName();
	
	// get the name of all log category names
	String[] catNames = (String[]) mbsc.getAttribute(logCatsName, "CategoryNames");		
	boolean found = false;
	for (String catName : catNames) {
		if (catName.equals(testLogCategoryNameStr)) {
			found = true;
			break;
		}
	}
	Assert.assertTrue(testLogCategoryNameStr + " must be among exported log category names", found);
	
	// get the object name for the test log category
	ObjectName testCategoryName = 
		(ObjectName) 
		mbsc.invoke(
			logCatsName, 
			"getJMXLogCategoryName", 
			new Object[]{ testLogCategoryNameStr }, 
			new String[] { "java.lang.String" }
		);
	
	// add the listener
	mbsc.addNotificationListener(testCategoryName,
		new NotificationListener() {

			public void handleNotification(Notification notification,
					Object handback) {
				receivedMessage = notification.getMessage();
				messageReceivedLatch.countDown();
			}
		}, null, this
	);

	// send log event
	if (testLog.isLoggable(Level.INFO)) testLog.info(testMsg);
	// wait
	messageReceivedLatch.await(30000, TimeUnit.MILLISECONDS);
	// compare
	assertTrue("Received message must contain testMsg", receivedMessage.contains(testMsg));
	
	System.out.println("---/// TEST OK ///---");
	
	Pogamut.getPlatform().close();
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:74,代码来源:Test01_JMXLogCategories.java

示例5: main

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
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.");
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:53,代码来源:EmptyDomainNotificationTest.java

示例6: test

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:57,代码来源:NotSerializableNotifTest.java

示例7: test

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:49,代码来源:UnexpectedNotifTest.java

示例8: notifyTest

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
private static boolean notifyTest(JMXConnector client,
                                  MBeanServerConnection mbsc)
        throws Exception {
    System.out.println("Send notifications including unknown ones");
    result = new Result();
    LostListener ll = new LostListener();
    client.addConnectionNotificationListener(ll, null, null);
    TestListener nl = new TestListener(ll);
    mbsc.addNotificationListener(on, nl, new TestFilter(), null);
    mbsc.invoke(on, "sendNotifs", NO_OBJECTS, NO_STRINGS);

    // wait for the listeners to receive all their notifs
    // or to fail
    long deadline = System.currentTimeMillis() + 60000;
    long remain;
    while ((remain = deadline - System.currentTimeMillis()) >= 0) {
        synchronized (result) {
            if (result.failed
                || (result.knownCount >= NNOTIFS
                    && result.lostCount >= NNOTIFS*2))
                break;
            result.wait(remain);
        }
    }
    Thread.sleep(2);  // allow any spurious extra notifs to arrive
    if (result.failed) {
        System.out.println("TEST FAILS: Notification strangeness");
        return false;
    } else if (result.knownCount == NNOTIFS
               && result.lostCount == NNOTIFS*2) {
        System.out.println("Success: received known notifications and " +
                           "got NOTIFS_LOST for unknown and " +
                           "unserializable ones");
        return true;
    } else if (result.knownCount >= NNOTIFS
            || result.lostCount >= NNOTIFS*2) {
        System.out.println("TEST FAILS: Received too many notifs: " +
                "known=" + result.knownCount + "; lost=" + result.lostCount);
        return false;
    } else {
        System.out.println("TEST FAILS: Timed out without receiving " +
                           "all notifs: known=" + result.knownCount +
                           "; lost=" + result.lostCount);
        return false;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:47,代码来源:MissingClassTest.java

示例9: test

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:56,代码来源:RMIExitTest.java

示例10: main

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    Policy.setPolicy(new NoRemovePolicy());
    System.setSecurityManager(new SecurityManager());

    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///");
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = new ObjectName("foo:type=Sender");
    mbs.registerMBean(new Sender(), name);
    JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(
            url, null, mbs);
    cs.start();
    try {
        JMXServiceURL addr = cs.getAddress();
        JMXConnector cc = JMXConnectorFactory.connect(addr);
        MBeanServerConnection mbsc = cc.getMBeanServerConnection();
        SnoopListener listener = new SnoopListener();
        mbsc.addNotificationListener(name, listener, null, null);
        mbsc.invoke(name, "send", null, null);
        if (!listener.waitForNotification(60))
            throw new Exception("Did not receive expected notification");

        try {
            mbsc.removeNotificationListener(name, listener);
            throw new Exception("RemoveNL did not get SecurityException");
        } catch (SecurityException e) {
            System.out.println("removeNL got expected exception: " + e);
        }
        mbsc.invoke(name, "send", null, null);
        if (!listener.waitForNotification(60)) {
            int listenerCount =
                    (Integer) mbsc.getAttribute(name, "ListenerCount");
            System.out.println("Listener count: " + listenerCount);
            if (listenerCount != 0)
                throw new Exception("TEST FAILED");
                /* We did not receive the notification, but the MBean still
                 * has a listener coming from the connector server, which
                 * means the connector server still thinks there is a
                 * listener.  If we retained the listener after the failing
                 * removeNL that would be OK, and if the listener were
                 * dropped by both client and server that would be OK too,
                 * but the inconsistency is not OK.
                 */
        }
        cc.close();
    } finally {
        cs.stop();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:NoPermToRemoveTest.java

示例11: main

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
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.");
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:EmptyDomainNotificationTest.java

示例12: main

import javax.management.MBeanServerConnection; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        String host = args[0];
        String port = args[1];
        String user = args[2];
        String pass = args[3];
        String configFilename = args[4];
        int sleep   = Integer.parseInt(args[5]) * 1000;

        // HashMap<String, String[]> config = readConfig(configFilename);
        List<String> config = readConfig(configFilename);


        HashMap<String, Object> env = new HashMap<String, Object>();
        String[] creds = new String[2];
        creds[0] = user;
        creds[1] = pass;
        env.put(JMXConnector.CREDENTIALS, creds);

        ManagementFactory.getGarbageCollectorMXBeans();

        String urlString = System.getProperty("jmx.service.url","service:jmx:remoting-jmx://" + host + ":" + port);
        System.err.println("URL : " + urlString);
        JMXServiceURL serviceURL = new JMXServiceURL(urlString);
        JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, env);
        try {
            MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

            ClientListener listener = new ClientListener();

            Iterator<String> it = config.iterator();
            while (it.hasNext()) {
                String name = it.next();
                ObjectName mbeanName = new ObjectName(name);
                System.err.printf("Add Listener for %s\n", name);
                connection.addNotificationListener(mbeanName, listener, null, name);
            }

            do {
                System.out.printf("<timestamp>%s</timestamp>\n", DATE_FORMAT.format(Calendar.getInstance().getTime()));
                Thread.sleep(sleep);
            } while (true);

        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            jmxConnector.close();
        }

    }
 
开发者ID:breakEval13,项目名称:rocketmq-flink-plugin,代码行数:53,代码来源:JMXNotificationClient.java


注:本文中的javax.management.MBeanServerConnection.addNotificationListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。