java类javax.management.NotificationFilterSupport的实例源码

HierarchyDynamicMBean.java 文件源码 项目:cacheonix-core 阅读 30 收藏 0 点赞 0 评论 0
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;
}
JmxBuilderModelMBean.java 文件源码 项目:groovy 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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);
        }
    }
}
JmxConnection.java 文件源码 项目:eZooKeeper 阅读 37 收藏 0 点赞 0 评论 0
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) {
    }

}
RMIConnector.java 文件源码 项目:OpenJSharp 阅读 23 收藏 0 点赞 0 评论 0
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];
}
RMIConnector.java 文件源码 项目:jdk8u-jdk 阅读 24 收藏 0 点赞 0 评论 0
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];
}
RMIConnector.java 文件源码 项目:openjdk-jdk10 阅读 27 收藏 0 点赞 0 评论 0
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];
}
RMIConnector.java 文件源码 项目:openjdk9 阅读 22 收藏 0 点赞 0 评论 0
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];
}
RMIConnector.java 文件源码 项目:Java8CN 阅读 31 收藏 0 点赞 0 评论 0
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];
}
JMXHelper.java 文件源码 项目:gemfirexd-oss 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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);
}
RMIConnector.java 文件源码 项目:jdk8u_jdk 阅读 23 收藏 0 点赞 0 评论 0
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];
}
RMIConnector.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 40 收藏 0 点赞 0 评论 0
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];
}
JMXHelper.java 文件源码 项目:gemfirexd-oss 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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);
}
JmxBuilderModelMBean.java 文件源码 项目:groovy 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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);
            }
        }
    }
}
RMIConnector.java 文件源码 项目:infobip-open-jdk-8 阅读 22 收藏 0 点赞 0 评论 0
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];
}
RMIConnector.java 文件源码 项目:jdk8u-dev-jdk 阅读 28 收藏 0 点赞 0 评论 0
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];
}
RasLoggingProvider.java 文件源码 项目:rhq-websphere-plugin 阅读 18 收藏 0 点赞 0 评论 0
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);
}
RMIConnector.java 文件源码 项目:jdk7-jdk 阅读 31 收藏 0 点赞 0 评论 0
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];
}
HierarchyDynamicMBean.java 文件源码 项目:nabs 阅读 26 收藏 0 点赞 0 评论 0
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;
}
RMIConnector.java 文件源码 项目:openjdk-source-code-learn 阅读 28 收藏 0 点赞 0 评论 0
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];
}
RMIConnector.java 文件源码 项目:OLD-OpenJDK8 阅读 32 收藏 0 点赞 0 评论 0
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];
}
ModelControllerMBeanTestCase.java 文件源码 项目:wildfly-core 阅读 23 收藏 0 点赞 0 评论 0
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);
}
ModelControllerMBeanTestCase.java 文件源码 项目:wildfly-core 阅读 21 收藏 0 点赞 0 评论 0
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);
}
RMIConnector.java 文件源码 项目:openjdk-jdk7u-jdk 阅读 23 收藏 0 点赞 0 评论 0
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];
}
NotificationFilterSupportTest.java 文件源码 项目:freeVM 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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())));
}
NotificationFilterSupportTest.java 文件源码 项目:freeVM 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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]);
}
NotificationFilterSupportTest.java 文件源码 项目:freeVM 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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"));
}
NotificationFilterSupportTest.java 文件源码 项目:freeVM 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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));
    }
}
NotificationFilterSupportTest.java 文件源码 项目:freeVM 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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));
}
NotificationFilterSupportTest.java 文件源码 项目:freeVM 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 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));
}
NotificationBroadcasterSupportTest.java 文件源码 项目:freeVM 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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);
}


问题


面经


文章

微信
公众号

扫码关注公众号