Java 类javax.management.NotificationFilterSupport 实例源码

项目:cacheonix-core    文件:HierarchyDynamicMBean.java   
ObjectName addLoggerMBean(Logger logger) {
  String name = logger.getName();
  ObjectName objectName = null;
  try {
    LoggerDynamicMBean loggerMBean = new LoggerDynamicMBean(logger);
    objectName = new ObjectName("log4j", "logger", name);

    if (!server.isRegistered(objectName)) {
      server.registerMBean(loggerMBean, objectName);
      NotificationFilterSupport nfs = new NotificationFilterSupport();
      nfs.enableType(ADD_APPENDER + logger.getName());
      log.debug("---Adding logger [" + name + "] as listener.");
      nbs.addNotificationListener(loggerMBean, nfs, null);
      vAttributes.add(new MBeanAttributeInfo("logger=" + name, "javax.management.ObjectName",
              "The " + name + " logger.", true, true, // this makes the object
              // clickable
              false));

    }

  } catch(Exception e) {
    log.error("Could not add loggerMBean for ["+name+"].", e);
  }
  return objectName;
}
项目: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);
        }
    }
}
项目:eZooKeeper    文件:JmxConnection.java   
private void addMBeanServerDelegateListener() {

    _MBeanServerDelegateNotificationListener = new MBeanServerDelegateNotificationListener();
    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION);
    filter.enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION);

    try {
        _MBeanServerConnection.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
                _MBeanServerDelegateNotificationListener, filter, null);
    }
    catch (Exception e) {
    }

}
项目:OpenJSharp    文件: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];
}
项目: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];
}
项目:openjdk-jdk10    文件: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];
}
项目:openjdk9    文件: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];
}
项目: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];
}
项目: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);
}
项目: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];
}
项目:lookaside_java-1.8.0-openjdk    文件: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];
}
项目: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);
}
项目: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
 * item -> [Map[methodListener:[target:"", tpe:"", callback:&amp;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);
            }
        }
    }
}
项目:infobip-open-jdk-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];
}
项目: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];
}
项目:rhq-websphere-plugin    文件:RasLoggingProvider.java   
public void start(ApplicationServer server, EventContext defaultEventContext, EventPublisher eventPublisher, String state) {
    NotificationFilterSupport filter = new NotificationFilterSupport();
    // TODO: use constants from NotificationConstants here
    filter.enableType("websphere.ras.audit");
    filter.enableType("websphere.ras.warning");
    filter.enableType("websphere.ras.error");
    filter.enableType("websphere.ras.fatal");
    registration = server.addNotificationListener(Utils.createObjectName("WebSphere:type=RasLoggingService,*"), new RasLoggingNotificationListener(defaultEventContext, eventPublisher), filter, null, true);
}
项目:jdk7-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];
}
项目:nabs    文件:HierarchyDynamicMBean.java   
ObjectName addLoggerMBean(Logger logger) {
  String name = logger.getName();
  ObjectName objectName = null;
  try {
    LoggerDynamicMBean loggerMBean = new LoggerDynamicMBean(logger);
    objectName = new ObjectName("log4j", "logger", name);
    server.registerMBean(loggerMBean, objectName);

    NotificationFilterSupport nfs = new NotificationFilterSupport();
    nfs.enableType(ADD_APPENDER+logger.getName());

    log.debug("---Adding logger ["+name+"] as listener.");

    nbs.addNotificationListener(loggerMBean, nfs, null);


    vAttributes.add(new MBeanAttributeInfo("logger="+name,
                 "javax.management.ObjectName",
                 "The "+name+" logger.",
                 true,
                 true, // this makes the object
                 // clickable
                 false));

  } catch(Exception e) {
    log.error("Could not add loggerMBean for ["+name+"].", e);
  }
  return objectName;
}
项目:openjdk-source-code-learn    文件: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];
}
项目:OLD-OpenJDK8    文件: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];
}
项目:wildfly-core    文件:ModelControllerMBeanTestCase.java   
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);
}
项目:wildfly-core    文件:ModelControllerMBeanTestCase.java   
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);
}
项目:openjdk-jdk7u-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];
}
项目:freeVM    文件:NotificationFilterSupportTest.java   
/**
 * Test for the constructor NotificationFilterSupport()
 * 
 * @see javax.management.NotificationFilterSupport#NotificationFilterSupport()
 */
public final void testNotificationFilterSupport() {
    NotificationFilterSupport f = new NotificationFilterSupport();
    assertEquals("No one notification type should be enabled!", 0, f
        .getEnabledTypes().size());
    assertTrue("The instance should be serializable!",
        (Serializable.class
        .isAssignableFrom(f.getClass())));
}
项目:freeVM    文件:NotificationFilterSupportTest.java   
/**
 * Disable all types, change attribute1, invoke sayHello.
 */
public final void setUpDisableAllTypes()
    throws InstanceNotFoundException, AttributeNotFoundException,
    InvalidAttributeValueException, MBeanException, ReflectionException {
    NotificationFilterSupport f = new NotificationFilterSupport();
    f.enableType(AttributeChangeNotification.ATTRIBUTE_CHANGE);
    f.enableType(Hello.SAY_HELLO_INVOKED);
    f.disableAllTypes();
    mbs.addNotificationListener(name, this, f, null);
    freeze(300);
    mbs.setAttribute(name, new Attribute("Attribute1", "New value"));
    mbs.invoke(name, "sayHello", new Object[0], new String[0]);
}
项目:freeVM    文件:NotificationFilterSupportTest.java   
/**
 * Disable ATTRIBUTE_CHANGE type, change attribute1.
 */
public final void setUpDisableType() throws InstanceNotFoundException,
    AttributeNotFoundException, InvalidAttributeValueException,
    MBeanException, ReflectionException {
    NotificationFilterSupport f = new NotificationFilterSupport();
    f.enableType(AttributeChangeNotification.ATTRIBUTE_CHANGE);
    f.disableType(AttributeChangeNotification.ATTRIBUTE_CHANGE);
    mbs.addNotificationListener(name, this, f, null);
    freeze(300);
    mbs.setAttribute(name, new Attribute("Attribute1", "New value"));
}
项目:freeVM    文件:NotificationFilterSupportTest.java   
/**
 * Test for the method enableType(java.lang.String)
 * 
 * @see javax.management.NotificationFilterSupport#enableType(java.lang.String)
 */
public final void testEnableType() {
    assertNotNull("Notification has not been received!", n);

    // Test exception.
    NotificationFilterSupport f = new NotificationFilterSupport();
    try {
        f.enableType(null);
        fail("IllegalArgumentException not thrown!");
    } catch (Throwable ex) {
        assertTrue("Wrong exception thrown: " + ex,
            (ex instanceof IllegalArgumentException));
    }
}
项目:freeVM    文件:NotificationFilterSupportTest.java   
/**
 * Test for the method getEnabledTypes()
 * 
 * @see javax.management.NotificationFilterSupport#getEnabledTypes()
 */
public final void testGetEnabledTypes() {
    NotificationFilterSupport f = new NotificationFilterSupport();
    f.enableType(AttributeChangeNotification.ATTRIBUTE_CHANGE);
    f.enableType(Hello.SAY_HELLO_INVOKED);
    Vector v = f.getEnabledTypes();

    assertTrue("The ATTRIBUTE_CHANGE notification should be enabled!", v
        .contains(AttributeChangeNotification.ATTRIBUTE_CHANGE));
    assertTrue("The SAY_HELLO_INVOKED notification should be enabled!", v
        .contains(Hello.SAY_HELLO_INVOKED));
}
项目:freeVM    文件:NotificationFilterSupportTest.java   
/**
 * Test for the method
 * isNotificationEnabled(javax.management.Notification)
 * 
 * @see javax.management.NotificationFilterSupport#isNotificationEnabled(javax.management.Notification)
 */
public final void testIsNotificationEnabled() {
    Notification n1 = new AttributeChangeNotification(hello, 1, 1, null,
        null, null, null, null);
    Notification n2 = new Notification(Hello.SAY_HELLO_INVOKED, "src", 1);
    NotificationFilterSupport f = new NotificationFilterSupport();
    f.enableType(Hello.SAY_HELLO_INVOKED);

    assertFalse("The AttributeChangeNotification should be disabled!", f
        .isNotificationEnabled(n1));
    assertTrue("The SAY_HELLO_INVOKED notification should be enabled!", f
        .isNotificationEnabled(n2));
}
项目:freeVM    文件:NotificationBroadcasterSupportTest.java   
/**
 * Test for the method
 * addNotificationListener(javax.management.NotificationListener,
 * javax.management.NotificationFilter, java.lang.Object)
 * 
 * @see javax.management.NotificationBroadcasterSupport#addNotificationListener(javax.management.NotificationListener,
 *      javax.management.NotificationFilter, java.lang.Object)
 */
public final void testAddNotificationListener() {
    Hello h = new Hello();
    // Test exception.
    try {
        h.addNotificationListener(null, null, null);
        fail("IllegalArgumentException not thrown!");
    } catch (Throwable ex) {
        assertTrue("Wrong exception thrown: " + ex,
            (ex instanceof IllegalArgumentException));
    }

    h.addNotificationListener(this, null, handback);
    h.sayHello();
    assertNotNull("Notification has not been received!", n);
    assertEquals("Wrong handback object received!", handback, receivedHB);

    n = null;
    receivedHB = null;
    h = new Hello();
    NotificationFilterSupport f = new NotificationFilterSupport();
    f.enableType(AttributeChangeNotification.ATTRIBUTE_CHANGE);
    h.addNotificationListener(this, f, null);
    h.setName("New name");
    assertNotNull("Notification has not been received!", n);
    assertTrue("Wrong handback object received!", receivedHB == null);
}
项目:freeVM    文件:NotificationBroadcasterSupportTest.java   
/**
 * Test for the method
 * removeNotificationListener(javax.management.NotificationListener,
 * javax.management.NotificationFilter, java.lang.Object)
 * 
 * @see javax.management.NotificationBroadcasterSupport#removeNotificationListener(javax.management.NotificationListener,
 *      javax.management.NotificationFilter, java.lang.Object)
 */
public final void testRemoveNotificationListenerNotificationListenerNotificationFilterObject() {
    Hello h = new Hello();
    // Test exception.
    try {
        h.removeNotificationListener(this, null, null);
        fail("ListenerNotFoundException not thrown!");
    } catch (Throwable ex) {
        assertTrue("Wrong exception thrown: " + ex,
            (ex instanceof ListenerNotFoundException));
    }

    h.addNotificationListener(this, null, null);
    h.addNotificationListener(this, null, null);
    removeNL(h, null, null);
    h.sayHello();
    assertNotNull("Notification has not been received!", n);
    removeNL(h, null, null);
    n = null;
    h.sayHello();
    assertNull("Notification has been received!", n);

    AttributeChangeNotificationFilter acf = new AttributeChangeNotificationFilter();
    acf.enableAttribute("Name");
    NotificationFilterSupport f = new NotificationFilterSupport();
    f.enableType(Hello.SAY_HELLO_INVOKED);
    h.addNotificationListener(this, acf, "handback1");
    h.addNotificationListener(this, f, handback);

    removeNL(h, f, handback);
    n = null;
    h.setName("New name");
    assertNotNull("Notification has not been received!", n);
    assertTrue("Wrong notification received: " + n,
        (n instanceof AttributeChangeNotification));
}
项目:openjdk-icedtea7    文件: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];
}
项目:log4j2    文件:ClientGUI.java   
private void registerListeners() throws InstanceNotFoundException,
        MalformedObjectNameException, IOException {
    final NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(StatusLoggerAdminMBean.NOTIF_TYPE_MESSAGE);
    final ObjectName objName = new ObjectName(StatusLoggerAdminMBean.NAME);
    client.getConnection().addNotificationListener(objName, this, filter,
            null);
}
项目: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);
}
项目: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());
}
项目:cn1    文件:MemoryMXBeanImplTest.java   
public final void testRemoveNotificationListenerNotificationListenerNotificationFilterObject()
        throws Exception {
    // Register a listener
    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED);
    SimpleTestListener listener = new SimpleTestListener();
    notifierBean.addNotificationListener(listener, filter, null);

    // Fire off a notification and ensure that the listener receives it.
    MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
    MemoryNotificationInfo info = new MemoryNotificationInfo("Tim", mu, 42);
    CompositeData cd = ManagementUtils
            .toMemoryNotificationInfoCompositeData(info);
    Notification notification = new Notification(
            MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
            new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
    notification.setUserData(cd);
    notifierBean.sendNotification(notification);
    assertEquals(1, listener.getNotificationsReceivedCount());

    // Remove the listener
    notifierBean.removeNotificationListener(listener, filter, null);

    // Fire off a notification and ensure that the listener does
    // *not* receive it.
    listener.resetNotificationsReceivedCount();
    notification = new Notification(
            MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
            new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
    notification.setUserData(cd);
    notifierBean.sendNotification(notification);
    assertEquals(0, listener.getNotificationsReceivedCount());

    // Try and remove the listener one more time. Should result in a
    // ListenerNotFoundException being thrown.
    try {
        notifierBean.removeNotificationListener(listener, filter, null);
        fail("Should have thrown a ListenerNotFoundException!");
    } catch (ListenerNotFoundException e) {
    }
}
项目:freeVM    文件:MemoryMXBeanImplTest.java   
public final void testRemoveNotificationListenerNotificationListenerNotificationFilterObject()
        throws Exception {
    // Register a listener
    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED);
    SimpleTestListener listener = new SimpleTestListener();
    notifierBean.addNotificationListener(listener, filter, null);

    // Fire off a notification and ensure that the listener receives it.
    MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
    MemoryNotificationInfo info = new MemoryNotificationInfo("Tim", mu, 42);
    CompositeData cd = ManagementUtils
            .toMemoryNotificationInfoCompositeData(info);
    Notification notification = new Notification(
            MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
            new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
    notification.setUserData(cd);
    notifierBean.sendNotification(notification);
    assertEquals(1, listener.getNotificationsReceivedCount());

    // Remove the listener
    notifierBean.removeNotificationListener(listener, filter, null);

    // Fire off a notification and ensure that the listener does
    // *not* receive it.
    listener.resetNotificationsReceivedCount();
    notification = new Notification(
            MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
            new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
    notification.setUserData(cd);
    notifierBean.sendNotification(notification);
    assertEquals(0, listener.getNotificationsReceivedCount());

    // Try and remove the listener one more time. Should result in a
    // ListenerNotFoundException being thrown.
    try {
        notifierBean.removeNotificationListener(listener, filter, null);
        fail("Should have thrown a ListenerNotFoundException!");
    } catch (ListenerNotFoundException e) {
    }
}
项目:freeVM    文件:MemoryMXBeanImplTest.java   
public final void testRemoveNotificationListenerNotificationListenerNotificationFilterObject()
        throws Exception {
    // Register a listener
    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED);
    SimpleTestListener listener = new SimpleTestListener();
    notifierBean.addNotificationListener(listener, filter, null);

    // Fire off a notification and ensure that the listener receives it.
    MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
    MemoryNotificationInfo info = new MemoryNotificationInfo("Tim", mu, 42);
    CompositeData cd = ManagementUtils
            .toMemoryNotificationInfoCompositeData(info);
    Notification notification = new Notification(
            MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
            new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
    notification.setUserData(cd);
    notifierBean.sendNotification(notification);
    assertEquals(1, listener.getNotificationsReceivedCount());

    // Remove the listener
    notifierBean.removeNotificationListener(listener, filter, null);

    // Fire off a notification and ensure that the listener does
    // *not* receive it.
    listener.resetNotificationsReceivedCount();
    notification = new Notification(
            MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
            new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
    notification.setUserData(cd);
    notifierBean.sendNotification(notification);
    assertEquals(0, listener.getNotificationsReceivedCount());

    // Try and remove the listener one more time. Should result in a
    // ListenerNotFoundException being thrown.
    try {
        notifierBean.removeNotificationListener(listener, filter, null);
        fail("Should have thrown a ListenerNotFoundException!");
    } catch (ListenerNotFoundException e) {
    }
}
项目:freeVM    文件:StructureTest.java   
/**
 * This testcase verifies MBeanToUnregister field in notifications.
 */

public Result testRemovalNotification() throws Exception {

    incorrectNotificationFlag = false;

    MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();

    RelationService relationService = new RelationService(true);
    ObjectName relationServiceName = new ObjectName(
            "mBeanServer:type=RelationService,name=rs");
    mBeanServer.registerMBean(relationService, relationServiceName);

    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType("jmx.relation");
    relationService.addNotificationListener(this, filter, null);
    checkNotifications = true;

    RoleInfo[] roleInfo = new RoleInfo[1];
    roleInfo[0] = new RoleInfo("unitRole", classPath, true, true, 1, 2,
            "Unit role");

    // Creating an Internal Relation Type
    relationService.createRelationType("internalRelationType", roleInfo);

    UnitMBean unit = new Unit();
    ObjectName unitName = new ObjectName("mBeanServer:type=Unit,name=Unit");
    mBeanServer.registerMBean(unit, unitName);

    ArrayList unitList = new ArrayList();
    unitList.add(unitName);

    Role unitRole = new Role("unitRole", unitList);
    RoleList unitRoles = new RoleList();
    unitRoles.add(unitRole);

    // Now Create relations between unit MBeans

    // Notification Data
    relationNotification = new RelationNotificationForCompare(
            "jmx.relation.creation.basic", relationService, 1, 10,
            "Creation of relation internalRelation", "internalRelation",
            "internalRelationType", null, null);

    relationService.createRelation("internalRelation",
            "internalRelationType", unitRoles);

    // Notification Data
    relationNotification = new RelationNotificationForCompare(
            "jmx.relation.removal.basic", relationService, 2, 10,
            "Removal of relation internalRelation", "internalRelation",
            "internalRelationType", null, new ArrayList());

    relationService.removeRelation("internalRelation");

    if (incorrectNotificationFlag) {
        return failed("IncorrectNotifications (see log for more information)");
    }
    return passed();
}
项目:freeVM    文件:ConnectorClientTest.java   
/**
 * Test perfom operation with connector client through RMI protocol
 */
public Result testRMIConnectorClient() throws Exception {
    try {

        log.info("Create JMX Service URL");
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");

        // Create a JMXConnectorServer
        log.info("Create JMXConnectorServer");
        JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, enviroment, mbeanServer);

        log.info("Start the server");
        server.start();
        JMXConnector client = server.toJMXConnector(enviroment);

        log.info("Connect client to the server");
        client.connect(enviroment);
        client.getClass();
        log.info("Connection id - " + client.getConnectionId());
        MBeanServerConnection mbsc = client.getMBeanServerConnection();

         //Add than remove notification listener on MBean
        log.info("Add than remove notification listener on MBean");
        Listener listener = new Listener();
        Object obj = new Object();
        NotificationFilterSupport filter = new NotificationFilterSupport();
        client.addConnectionNotificationListener(listener,filter,obj );
        client.removeConnectionNotificationListener(listener);
        client.addConnectionNotificationListener(listener,filter,obj );
        client.removeConnectionNotificationListener(listener,filter,obj );

        log.info("Close client connection");
        client.close();
        log.info("Stop the server");
        server.stop();

    } catch (Exception e) {
        e.printStackTrace();
        return failed("Unexpected exception");
    }

    return result();
}