[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/multiplexer ...

Brian Stansberry brian.stansberry at jboss.com
Fri Nov 3 16:20:29 EST 2006


  User: bstansberry
  Date: 06/11/03 16:20:29

  Modified:    tests/functional/org/jboss/cache/multiplexer  Tag:
                        Branch_JBossCache_1_4_0 MultiplexerTestHelper.java
  Log:
  Create a separate MuxChannelFactory per cache
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +65 -41    JBossCache/tests/functional/org/jboss/cache/multiplexer/Attic/MultiplexerTestHelper.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MultiplexerTestHelper.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/multiplexer/Attic/MultiplexerTestHelper.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -b -r1.1.2.2 -r1.1.2.3
  --- MultiplexerTestHelper.java	3 Nov 2006 19:17:16 -0000	1.1.2.2
  +++ MultiplexerTestHelper.java	3 Nov 2006 21:20:29 -0000	1.1.2.3
  @@ -8,7 +8,6 @@
   
   import javax.management.MBeanServer;
   import javax.management.MBeanServerFactory;
  -import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
   import javax.xml.parsers.DocumentBuilder;
   import javax.xml.parsers.DocumentBuilderFactory;
  @@ -26,23 +25,12 @@
      private static final Log log = LogFactory.getLog(MultiplexerTestHelper.class);
      
      private static final String MUX_STACK = "jbc-test";
  -   private static final ObjectName FACTORY_OBJECT_NAME;
  +   private static final String FACTORY_OBJECT_NAME_BASE = "jboss.cache:service=MuxChannelFactory,count=";
      
  -   static
  -   {
  -      try
  -      {
  -         FACTORY_OBJECT_NAME = new ObjectName("jboss.cache:service=JChannelFactory");
  -      }
  -      catch (MalformedObjectNameException e)
  -      {
  -         throw new ExceptionInInitializerError(e);
  -      }
  -   }
  -   
  -   private final MBeanServer mbeanServer;
  -   private MuxChannelFactory muxFactory;
  -   private final Set registeredCaches = Collections.synchronizedSet(new HashSet());
  +   private MBeanServer mbeanServer;
  +//   private MuxChannelFactory muxFactory;
  +   private final Set factories = Collections.synchronizedSet(new HashSet());
  +   private final Set caches = Collections.synchronizedSet(new HashSet());
   
      
      public MultiplexerTestHelper() 
  @@ -53,48 +41,59 @@
      
      public void configureCacheForMux(TreeCacheMBean cache) throws Exception
      {
  -      ObjectName on = new ObjectName("jboss.cache:service=TestCache,count=" + registeredCaches.size());
  +      synchronized (caches)
  +      {
  +         ObjectName on = new ObjectName("jboss.cache:service=TestCache,count=" + caches.size());
         configureCacheForMux(cache, on);
      }
  +   }
      
      public void configureCacheForMux(TreeCacheMBean cache, ObjectName cacheObjectName) throws Exception
      {
  -      cache.setMultiplexerService(FACTORY_OBJECT_NAME.getCanonicalName());
  +      ObjectName on = createMuxChannelFactory(cache);
  +      cache.setMultiplexerService(on.getCanonicalName());
         cache.setMultiplexerStack(MUX_STACK);
         
  -      MBeanServer server = getMBeanServerWithMux(cache);
  -      server.registerMBean(cache, cacheObjectName);
  -      registeredCaches.add(cacheObjectName);
  +      mbeanServer.registerMBean(cache, cacheObjectName);
  +      caches.add(cacheObjectName);
      }
      
  -   public MBeanServer getMBeanServerWithMux(TreeCacheMBean cache) throws Exception
  +   public ObjectName createMuxChannelFactory(TreeCacheMBean cache) throws Exception
      {
         String props = cache.getClusterProperties();
         props = props == null ? JChannel.DEFAULT_PROTOCOL_STACK : props;
  -      return getMBeanServerWithMux(getClusterConfigElement(props));
  +      return createMuxChannelFactory(getClusterConfigElement(props));
      }
      
  -   public MBeanServer getMBeanServerWithMux(Element muxConfig) throws Exception
  +   private ObjectName createMuxChannelFactory(Element muxConfig) throws Exception
      { 
  -      if (muxFactory == null)
  +      synchronized (factories)
         {
            JChannelFactory factory = new JChannelFactory();
            factory.setDomain("jbc.mux.test");
  +         factory.setExposeChannels(false);
  +            
  +         MuxChannelFactory muxFactory = new MuxChannelFactory(factory, muxConfig);
  +         ObjectName on = new ObjectName(FACTORY_OBJECT_NAME_BASE + factories.size());
  +         mbeanServer.registerMBean(muxFactory, on);
            
  -         muxFactory = new MuxChannelFactory(factory, muxConfig);
  -         mbeanServer.registerMBean(muxFactory, FACTORY_OBJECT_NAME);
  +         factories.add(on);
            
            muxFactory.create();
            muxFactory.start();
  -      }
  -//      else if (!muxConfig.equals(muxFactory.getMultiplexerConfig()) )
  -//      {
  -//         throw new IllegalStateException("Inconsistent muxConfig");
  -//      }
         
  -      return mbeanServer;      
  +         return on;   
  +      }
      }
      
  +   /**
  +    * Converts an old-style JGroups protocol stack config string to an Element
  +    * that looks like the root element of a multiplexer stacks.xml file.
  +    * 
  +    * @param clusterConfig
  +    * @return
  +    * @throws Exception
  +    */
      public static Element getClusterConfigElement(String clusterConfig) throws Exception
      {
         clusterConfig = clusterConfig.trim();
  @@ -143,7 +142,7 @@
      {
         try
         {
  -         for (Iterator it = registeredCaches.iterator(); it.hasNext(); )
  +         for (Iterator it = caches.iterator(); it.hasNext(); )
            {
               try
               {
  @@ -155,10 +154,16 @@
               }
            }
            
  -         if (muxFactory != null)
  +         for (Iterator it = factories.iterator(); it.hasNext(); )
            {
  -            muxFactory.stop();
  -            muxFactory.destroy();
  +            try
  +            {
  +               mbeanServer.unregisterMBean((ObjectName) it.next());
  +            }
  +            catch (Exception e)
  +            {
  +               log.error(e);
  +            }
            }
         }
         catch (Exception e)
  @@ -167,9 +172,28 @@
         }
         finally
         {
  +         factories.clear();
  +         caches.clear();
  +         
            if (mbeanServer != null)
  +         {
  +            MBeanServerFactory.releaseMBeanServer(mbeanServer);
  +            mbeanServer = null;
  +         }
  +         
  +         
  +      }
  +   }
  +   
  +   
  +   
  +   protected void finalize() throws Throwable
  +   {
  +      if (mbeanServer != null)
  +      {
               MBeanServerFactory.releaseMBeanServer(mbeanServer);
         }
  +      super.finalize();
      }
      
      public static void main(String[] args)
  @@ -177,7 +201,7 @@
         MultiplexerTestHelper helper = new MultiplexerTestHelper();
         try
         {         
  -         helper.getMBeanServerWithMux(getClusterConfigElement(JChannel.DEFAULT_PROTOCOL_STACK));
  +         helper.createMuxChannelFactory(getClusterConfigElement(JChannel.DEFAULT_PROTOCOL_STACK));
         }
         catch (Exception e)
         {
  
  
  



More information about the jboss-cvs-commits mailing list