Package javax.management

Examples of javax.management.NotificationFilterSupport


   public void testRemoveTripletErrors()
      throws Exception
   {
      NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport();
      Object handback = new Object();
      NotificationFilterSupport filter = new NotificationFilterSupport();
      filter.enableType(DEFAULT_TYPE);

      Listener listener = new Listener();

      boolean caught = false;
      try
      {
         broadcaster.removeNotificationListener(null, null, null);
      }
      catch (ListenerNotFoundException e)
      {
         caught = true;
      }
      assertTrue("Expected ListenerNotFoundException for null listener", caught);

      caught = false;
      try
      {
         broadcaster.removeNotificationListener(listener, null, null);
      }
      catch (ListenerNotFoundException e)
      {
         caught = true;
      }
      assertTrue("Expected ListenerNotFoundException for listener never added", caught);

      caught = false;
      try
      {
         broadcaster.addNotificationListener(listener, null, null);
         broadcaster.removeNotificationListener(listener, null, null);
         broadcaster.removeNotificationListener(listener, null, null);
      }
      catch (ListenerNotFoundException e)
      {
         caught = true;
      }
      assertTrue("Expected ListenerNotFoundException for listener remove twice", caught);

      caught = false;
      try
      {
         broadcaster.addNotificationListener(listener, filter, null);
         broadcaster.removeNotificationListener(listener, new NotificationFilterSupport(), null);
      }
      catch (ListenerNotFoundException e)
      {
         caught = true;
         broadcaster.removeNotificationListener(listener, filter, null);
      }
      assertTrue("Expected ListenerNotFoundException for wrong filter", caught);

      caught = false;
      try
      {
         broadcaster.addNotificationListener(listener, null, handback);
         broadcaster.removeNotificationListener(listener, null, new Object());
      }
      catch (ListenerNotFoundException e)
      {
         caught = true;
         broadcaster.removeNotificationListener(listener, null, handback);
      }
      assertTrue("Expected ListenerNotFoundException for wrong handback", caught);

      caught = false;
      try
      {
         broadcaster.addNotificationListener(listener, filter, handback);
         broadcaster.removeNotificationListener(listener, new NotificationFilterSupport(), new Object());
      }
      catch (ListenerNotFoundException e)
      {
         caught = true;
         broadcaster.removeNotificationListener(listener, filter, handback);
View Full Code Here


  /**
   * By default all types are disabled.
   */
  public void testDefault()
  {
    NotificationFilterSupport nfs = new NotificationFilterSupport();
    assertEquals(false, nfs.isNotificationEnabled(n1));
    assertEquals(false, nfs.isNotificationEnabled(n2));
    assertEquals(false, nfs.isNotificationEnabled(n3));
    assertEquals(false, nfs.isNotificationEnabled(n4));
    assertEquals(false, nfs.isNotificationEnabled(n5));
  }
View Full Code Here

  /**
   * Enable a single type, all others should be disabled.
   */
  public void testEnableType()
  {
    NotificationFilterSupport nfs = new NotificationFilterSupport();
    nfs.enableType("type1plus");
    assertEquals(false, nfs.isNotificationEnabled(n1));
    assertEquals(false, nfs.isNotificationEnabled(n2));
    assertEquals(true, nfs.isNotificationEnabled(n3));
    assertEquals(false, nfs.isNotificationEnabled(n4));
    assertEquals(false, nfs.isNotificationEnabled(n5));
  }
View Full Code Here

        }
    }

    private void init() {
        MyListener listener = new MyListener();
        NotificationFilterSupport filter = null;

        try {
            // get reference to MBean server
            Context ic = new InitialContext();
            MBeanServerConnection server = (MBeanServerConnection) ic.lookup("jmx/invoker/RMIAdaptor");

            // get reference to CacheMgmtInterceptor MBean
            String cacheName = "rhq.cache:subsystem=alerts,service=cache";
            ObjectName mgmt_name = new ObjectName(cacheName);

            // configure a filter to only receive node created and removed events
            filter = new NotificationFilterSupport();
            filter.disableAllTypes();
            filter.enableType(CacheMgmtInterceptor.NOTIF_NODE_CREATED);
            filter.enableType(CacheMgmtInterceptor.NOTIF_NODE_REMOVED);
            filter.enableType(CacheMgmtInterceptor.NOTIF_NODE_MODIFIED);

            // register the listener with a filter
            // leave the filter null to receive all cache events
            server.addNotificationListener(mgmt_name, listener, filter, null);
        } catch (Exception e) {
View Full Code Here

        }
        RMIServerSocketFactory serverSocketFactory = new GeronimoRMIServerSocketFactory(host);
        env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, serverSocketFactory);
       
        server = JMXConnectorServerFactory.newJMXConnectorServer(jmxServiceURL, env, mbeanServer);
        NotificationFilterSupport filter = new NotificationFilterSupport();
        filter.enableType(JMXConnectionNotification.OPENED);
        filter.enableType(JMXConnectionNotification.CLOSED);
        filter.enableType(JMXConnectionNotification.FAILED);
        server.addNotificationListener(authenticator, filter, null);
       
        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        try {
View Full Code Here

    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);
View Full Code Here

      return new NotificationBroadcasterSupport();
   }

   public NotificationFilterSupport createNotificationFilterSupport()
   {
      NotificationFilterSupport filter = new NotificationFilterSupport();
      filter.enableType("notif-type");
      return filter;
   }
View Full Code Here

        //Add the custom invoker as an MBeanServerForwarder, and start the RMIConnectorServer.
        MBeanServerForwarder mbsf = MBeanInvocationHandlerImpl.newProxyInstance();
        _cs.setMBeanServerForwarder(mbsf);

        NotificationFilterSupport filter = new NotificationFilterSupport();
        filter.enableType(JMXConnectionNotification.OPENED);
        filter.enableType(JMXConnectionNotification.CLOSED);
        filter.enableType(JMXConnectionNotification.FAILED);
        // Get the handler that is used by the above MBInvocationHandler Proxy.
        // which is the MBeanInvocationHandlerImpl and so also a NotificationListener
        _cs.addNotificationListener((NotificationListener) Proxy.getInvocationHandler(mbsf), filter, null);

        _cs.start();
View Full Code Here

            throw org;
        }

        protected Integer addListenerForMBeanRemovedNotif()
        throws IOException, InstanceNotFoundException {
            NotificationFilterSupport clientFilter =
                    new NotificationFilterSupport();
            clientFilter.enableType(
                    MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
            MarshalledObject<NotificationFilter> sFilter =
                new MarshalledObject<NotificationFilter>(clientFilter);

            Integer[] listenerIDs;
View Full Code Here

  /**
   * By default all types are disabled.
   */
  public void testDefault()
  {
    NotificationFilterSupport nfs = new NotificationFilterSupport();
    assertEquals(false, nfs.isNotificationEnabled(n1));
    assertEquals(false, nfs.isNotificationEnabled(n2));
    assertEquals(false, nfs.isNotificationEnabled(n3));
    assertEquals(false, nfs.isNotificationEnabled(n4));
    assertEquals(false, nfs.isNotificationEnabled(n5));
  }
View Full Code Here

TOP

Related Classes of javax.management.NotificationFilterSupport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.