Package mx4j.server.interceptor

Examples of mx4j.server.interceptor.NotificationListenerMBeanServerInterceptor


      {
         ObjectName invokerName = new ObjectName(MBeanServerInterceptorConfigurator.OBJECT_NAME);
         invoker = new MBeanServerInterceptorConfigurator(this);

         ContextClassLoaderMBeanServerInterceptor ccl = new ContextClassLoaderMBeanServerInterceptor();
         NotificationListenerMBeanServerInterceptor notif = new NotificationListenerMBeanServerInterceptor();
         SecurityMBeanServerInterceptor sec = new SecurityMBeanServerInterceptor();
         InvokerMBeanServerInterceptor inv = new InvokerMBeanServerInterceptor(outer == null ? this : outer);

         invoker.addPreInterceptor(ccl);
         invoker.addPreInterceptor(notif);
View Full Code Here


   /**
    * One listener, one MBean, one ObjectName
    */
   public void testAddRemove1() throws Exception
   {
      NotificationListenerMBeanServerInterceptor interceptor = new NotificationListenerMBeanServerInterceptor();
      interceptor.setEnabled(true);
      List chain = new ArrayList();
      chain.add(interceptor);
      chain.add(new NoOpMBeanServerInterceptor());
      interceptor.setChain(chain);

      ObjectName objectName = ObjectName.getInstance(":type=test");
      MBeanMetaData metadata = new NotificationListenerMBeanMetaData(this, objectName);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
         }
      };

      interceptor.addNotificationListener(metadata, listener, null, null);
      assertEquals(1, interceptor.getNotificationListenerWrappers().size());
      Object wrapper = ((Map.Entry)interceptor.getNotificationListenerWrappers().entrySet().iterator().next()).getValue();
      assertEquals(1, interceptor.getNotificationListenerWrapperReferenceCount(wrapper));
      assertEquals(1, interceptor.getObjectNames().size());
      assertEquals(objectName, interceptor.getObjectNames().keySet().iterator().next());

      interceptor.removeNotificationListener(metadata, listener, null, null);
      assertEquals(0, interceptor.getNotificationListenerWrapperReferenceCount(wrapper));
      assertEquals(0, interceptor.getNotificationListenerWrappers().size());
      assertEquals(0, interceptor.getObjectNames().size());
   }
View Full Code Here

   /**
    * One listener thrice, one MBean, one ObjectName
    */
   public void testAddRemove2() throws Exception
   {
      NotificationListenerMBeanServerInterceptor interceptor = new NotificationListenerMBeanServerInterceptor();
      interceptor.setEnabled(true);
      List chain = new ArrayList();
      chain.add(interceptor);
      chain.add(new NoOpMBeanServerInterceptor());
      interceptor.setChain(chain);

      ObjectName objectName = ObjectName.getInstance(":type=test");
      MBeanMetaData metadata = new NotificationListenerMBeanMetaData(this, objectName);
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
         }
      };

      interceptor.addNotificationListener(metadata, listener, null, null);
      interceptor.addNotificationListener(metadata, listener, null, listener);
      Object handback = new Object();
      interceptor.addNotificationListener(metadata, listener, null, handback);

      assertEquals(1, interceptor.getNotificationListenerWrappers().size());
      Object wrapper = ((Map.Entry)interceptor.getNotificationListenerWrappers().entrySet().iterator().next()).getValue();
      assertEquals(3, interceptor.getNotificationListenerWrapperReferenceCount(wrapper));
      assertEquals(1, interceptor.getObjectNames().size());
      assertEquals(objectName, interceptor.getObjectNames().keySet().iterator().next());

      interceptor.removeNotificationListener(metadata, listener, null, handback);
      assertEquals(2, interceptor.getNotificationListenerWrapperReferenceCount(wrapper));
      assertEquals(1, interceptor.getObjectNames().size());

      interceptor.removeNotificationListener(metadata, listener);
      assertEquals(0, interceptor.getNotificationListenerWrapperReferenceCount(wrapper));
      assertEquals(0, interceptor.getNotificationListenerWrappers().size());
      assertEquals(0, interceptor.getObjectNames().size());
   }
View Full Code Here

   /**
    * One listener, one MBean, two ObjectNames
    */
   public void testAddRemove3() throws Exception
   {
      NotificationListenerMBeanServerInterceptor interceptor = new NotificationListenerMBeanServerInterceptor();
      interceptor.setEnabled(true);
      List chain = new ArrayList();
      chain.add(interceptor);
      chain.add(new NoOpMBeanServerInterceptor());
      interceptor.setChain(chain);

      MBeanMetaData metadata1 = new NotificationListenerMBeanMetaData(this, ObjectName.getInstance(":type=test1"));
      MBeanMetaData metadata2 = new NotificationListenerMBeanMetaData(this, ObjectName.getInstance(":type=test2"));
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
         }
      };

      interceptor.addNotificationListener(metadata1, listener, null, null);
      interceptor.addNotificationListener(metadata2, listener, null, null);

      assertEquals(2, interceptor.getNotificationListenerWrappers().size());
      assertEquals(2, interceptor.getObjectNames().size());

      interceptor.removeNotificationListener(metadata1, listener, null, null);
      assertEquals(1, interceptor.getNotificationListenerWrappers().size());
      assertEquals(1, interceptor.getObjectNames().size());

      interceptor.removeNotificationListener(metadata2, listener, null, null);
      assertEquals(0, interceptor.getNotificationListenerWrappers().size());
      assertEquals(0, interceptor.getObjectNames().size());
   }
View Full Code Here

   /**
    * One listener, two MBeans, two ObjectNames
    */
   public void testAddRemove4() throws Exception
   {
      NotificationListenerMBeanServerInterceptor interceptor = new NotificationListenerMBeanServerInterceptor();
      interceptor.setEnabled(true);
      List chain = new ArrayList();
      chain.add(interceptor);
      chain.add(new NoOpMBeanServerInterceptor());
      interceptor.setChain(chain);

      MBeanMetaData metadata1 = new NotificationListenerMBeanMetaData(this, ObjectName.getInstance(":type=test1"));
      MBeanMetaData metadata2 = new NotificationListenerMBeanMetaData(interceptor, ObjectName.getInstance(":type=test2"));
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
         }
      };

      interceptor.addNotificationListener(metadata1, listener, null, null);
      interceptor.addNotificationListener(metadata2, listener, null, null);

      assertEquals(2, interceptor.getNotificationListenerWrappers().size());
      assertEquals(2, interceptor.getObjectNames().size());

      interceptor.removeNotificationListener(metadata1, listener, null, null);
      assertEquals(1, interceptor.getNotificationListenerWrappers().size());
      assertEquals(1, interceptor.getObjectNames().size());

      interceptor.removeNotificationListener(metadata2, listener, null, null);
      assertEquals(0, interceptor.getNotificationListenerWrappers().size());
      assertEquals(0, interceptor.getObjectNames().size());
   }
View Full Code Here

   /**
    * Two listeners, one MBean, one ObjectName
    */
   public void testAddRemove5() throws Exception
   {
      NotificationListenerMBeanServerInterceptor interceptor = new NotificationListenerMBeanServerInterceptor();
      interceptor.setEnabled(true);
      List chain = new ArrayList();
      chain.add(interceptor);
      chain.add(new NoOpMBeanServerInterceptor());
      interceptor.setChain(chain);

      ObjectName objectName = ObjectName.getInstance(":type=test1");
      MBeanMetaData metadata = new NotificationListenerMBeanMetaData(this, objectName);
      NotificationListener listener1 = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
         }
      };
      NotificationListener listener2 = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
         }
      };

      interceptor.addNotificationListener(metadata, listener1, null, null);
      interceptor.addNotificationListener(metadata, listener2, null, null);

      assertEquals(2, interceptor.getNotificationListenerWrappers().size());
      for (Iterator iterator = interceptor.getNotificationListenerWrappers().values().iterator(); iterator.hasNext();)
      {
         Object wrapper = iterator.next();
         assertEquals(1, interceptor.getNotificationListenerWrapperReferenceCount(wrapper));
      }
      assertEquals(1, interceptor.getObjectNames().size());
      assertEquals(objectName, interceptor.getObjectNames().keySet().iterator().next());

      interceptor.removeNotificationListener(metadata, listener1);
      assertEquals(1, interceptor.getNotificationListenerWrappers().size());
      assertEquals(1, interceptor.getObjectNames().size());

      interceptor.removeNotificationListener(metadata, listener2);
      assertEquals(0, interceptor.getNotificationListenerWrappers().size());
      assertEquals(0, interceptor.getObjectNames().size());
   }
View Full Code Here

   /**
    * Two listeners, one MBean, two ObjectNames
    */
   public void testAddRemove6() throws Exception
   {
      NotificationListenerMBeanServerInterceptor interceptor = new NotificationListenerMBeanServerInterceptor();
      interceptor.setEnabled(true);
      List chain = new ArrayList();
      chain.add(interceptor);
      chain.add(new NoOpMBeanServerInterceptor());
      interceptor.setChain(chain);

      MBeanMetaData metadata1 = new NotificationListenerMBeanMetaData(this, ObjectName.getInstance(":type=test1"));
      MBeanMetaData metadata2 = new NotificationListenerMBeanMetaData(this, ObjectName.getInstance(":type=test2"));
      NotificationListener listener1 = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
         }
      };
      NotificationListener listener2 = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
         }
      };

      interceptor.addNotificationListener(metadata1, listener1, null, null);
      interceptor.addNotificationListener(metadata2, listener2, null, null);

      assertEquals(2, interceptor.getNotificationListenerWrappers().size());
      for (Iterator iterator = interceptor.getNotificationListenerWrappers().values().iterator(); iterator.hasNext();)
      {
         Object wrapper = iterator.next();
         assertEquals(1, interceptor.getNotificationListenerWrapperReferenceCount(wrapper));
      }
      assertEquals(2, interceptor.getObjectNames().size());

      interceptor.removeNotificationListener(metadata1, listener1);
      assertEquals(1, interceptor.getNotificationListenerWrappers().size());
      assertEquals(1, interceptor.getObjectNames().size());

      interceptor.removeNotificationListener(metadata2, listener2);
      assertEquals(0, interceptor.getNotificationListenerWrappers().size());
      assertEquals(0, interceptor.getObjectNames().size());
   }
View Full Code Here

   /**
    * One listener, one MBean, one ObjectName
    */
   public void testAddUnregister1() throws Exception
   {
      NotificationListenerMBeanServerInterceptor interceptor = new NotificationListenerMBeanServerInterceptor();
      interceptor.setEnabled(true);
      List chain = new ArrayList();
      chain.add(interceptor);
      chain.add(new NoOpMBeanServerInterceptor());
      interceptor.setChain(chain);

      MBeanMetaData metadata = new NotificationListenerMBeanMetaData(this, ObjectName.getInstance(":type=test1"));
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
         }
      };

      interceptor.addNotificationListener(metadata, listener, null, null);
      interceptor.registration(metadata, MBeanServerInterceptor.POST_DEREGISTER);
      assertEquals(0, interceptor.getNotificationListenerWrappers().size());
      assertEquals(0, interceptor.getObjectNames().size());
   }
View Full Code Here

   /**
    * One listener twice, one MBean, one ObjectName
    */
   public void testAddUnregister2() throws Exception
   {
      NotificationListenerMBeanServerInterceptor interceptor = new NotificationListenerMBeanServerInterceptor();
      interceptor.setEnabled(true);
      List chain = new ArrayList();
      chain.add(interceptor);
      chain.add(new NoOpMBeanServerInterceptor());
      interceptor.setChain(chain);

      MBeanMetaData metadata = new NotificationListenerMBeanMetaData(this, ObjectName.getInstance(":type=test1"));
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
         }
      };

      interceptor.addNotificationListener(metadata, listener, null, null);
      interceptor.addNotificationListener(metadata, listener, null, listener);
      interceptor.registration(metadata, MBeanServerInterceptor.POST_DEREGISTER);
      assertEquals(0, interceptor.getNotificationListenerWrappers().size());
      assertEquals(0, interceptor.getObjectNames().size());
   }
View Full Code Here

   /**
    * One listener, one MBean, two ObjectNames
    */
   public void testAddUnregister3() throws Exception
   {
      NotificationListenerMBeanServerInterceptor interceptor = new NotificationListenerMBeanServerInterceptor();
      interceptor.setEnabled(true);
      List chain = new ArrayList();
      chain.add(interceptor);
      chain.add(new NoOpMBeanServerInterceptor());
      interceptor.setChain(chain);

      MBeanMetaData metadata1 = new NotificationListenerMBeanMetaData(this, ObjectName.getInstance(":type=test1"));
      MBeanMetaData metadata2 = new NotificationListenerMBeanMetaData(this, ObjectName.getInstance(":type=test2"));
      NotificationListener listener = new NotificationListener()
      {
         public void handleNotification(Notification notification, Object handback)
         {
         }
      };

      interceptor.addNotificationListener(metadata1, listener, null, null);
      interceptor.addNotificationListener(metadata2, listener, null, null);
      interceptor.registration(metadata1, MBeanServerInterceptor.POST_DEREGISTER);
      assertEquals(1, interceptor.getNotificationListenerWrappers().size());
      assertEquals(1, interceptor.getObjectNames().size());

      interceptor.registration(metadata2, MBeanServerInterceptor.POST_DEREGISTER);
      assertEquals(0, interceptor.getNotificationListenerWrappers().size());
      assertEquals(0, interceptor.getObjectNames().size());
   }
View Full Code Here

TOP

Related Classes of mx4j.server.interceptor.NotificationListenerMBeanServerInterceptor

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.