[jboss-cvs] JBossCache/src/org/jboss/cache ...

Brian Stansberry brian.stansberry at jboss.com
Thu Jul 12 18:36:58 EDT 2007


  User: bstansberry
  Date: 07/07/12 18:36:58

  Modified:    src/org/jboss/cache  Tag: Branch_JBossCache_1_4_0
                        TreeCache.java
  Log:
  [JBCACHE-1048] TreeCache registers channel in JMX if it doesn't get it from ChannelFactory
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.195.2.57 +80 -2     JBossCache/src/org/jboss/cache/Attic/TreeCache.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCache.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/Attic/TreeCache.java,v
  retrieving revision 1.195.2.56
  retrieving revision 1.195.2.57
  diff -u -b -r1.195.2.56 -r1.195.2.57
  --- TreeCache.java	16 Mar 2007 22:07:03 -0000	1.195.2.56
  +++ TreeCache.java	12 Jul 2007 22:36:58 -0000	1.195.2.57
  @@ -56,6 +56,7 @@
   import org.jgroups.blocks.GroupRequest;
   import org.jgroups.blocks.MethodCall;
   import org.jgroups.blocks.RpcDispatcher;
  +import org.jgroups.jmx.JmxConfigurator;
   import org.jgroups.stack.IpAddress;
   import org.jgroups.util.Rsp;
   import org.jgroups.util.RspList;
  @@ -99,7 +100,7 @@
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    * @author Brian Stansberry
    * @author Daniel Huang (dhuang at jboss.org)
  - * @version $Id: TreeCache.java,v 1.195.2.56 2007/03/16 22:07:03 msurtani Exp $
  + * @version $Id: TreeCache.java,v 1.195.2.57 2007/07/12 22:36:58 bstansberry Exp $
    *          <p/>
    * @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
    */
  @@ -108,6 +109,10 @@
      private static final String CREATE_MUX_CHANNEL = "createMultiplexerChannel";
      private static final String[] MUX_TYPES = {"java.lang.String", "java.lang.String"};
      private static final String JBOSS_SERVER_DOMAIN = "jboss";
  +   private static final String JGROUPS_JMX_DOMAIN = "jboss.jgroups";
  +   private static final String CHANNEL_JMX_ATTRIBUTES = "type=channel,cluster=";
  +   private static final String PROTOCOL_JMX_ATTRIBUTES = "type=protocol,cluster=";
  +   
   
      private boolean forceAnycast = false;
      /**
  @@ -437,6 +442,11 @@
       */
      protected Method anycastMethod;
   
  +   /** Did we register our channel in JMX ourself? */
  +   protected boolean channelRegistered;   
  +   /** Did we register our channel's protocols in JMX ourself? */
  +   protected boolean protocolsRegistered;
  +
      /**
       * Creates a channel with the given cluster name, properties, and state fetch timeout.
       */
  @@ -1462,6 +1472,8 @@
                     log.debug("setting cluster properties to default value");
                  }
                  channel = new JChannel(cluster_props);
  +               // JBCACHE-1048 Hack to register the channel
  +               registerChannelInJmx();
                  
                  // Only set GET_STATE_EVENTS if the JGroups version is < 2.3
                  int jgVer= org.jgroups.Version.version;
  @@ -1615,6 +1627,8 @@
         {
            log.info("stopService(): closing the channel");
            channel.close();
  +         // JBCACHE-1048 Hack
  +         unregisterChannelFromJmx();
            channel = null;
         }
         if (disp != null)
  @@ -6649,6 +6663,70 @@
   
      }
   
  +   protected void registerChannelInJmx()
  +   {
  +      if (server != null)
  +      {
  +         try
  +         {
  +            String protocolPrefix = JGROUPS_JMX_DOMAIN + ":" + PROTOCOL_JMX_ATTRIBUTES + getClusterName();
  +            JmxConfigurator.registerProtocols(server, channel, protocolPrefix);
  +            protocolsRegistered = true;
  +            
  +            String name = JGROUPS_JMX_DOMAIN + ":" + CHANNEL_JMX_ATTRIBUTES + getClusterName();
  +            JmxConfigurator.registerChannel(channel, server, name);
  +            channelRegistered = true;
  +         }
  +         catch (Exception e)
  +         {
  +            log.error("Caught exception registering channel in JXM", e);
  +         }
  +      }
  +   }
  +   
  +   protected void unregisterChannelFromJmx()
  +   {
  +      ObjectName on = null;
  +      if (channelRegistered)
  +      {          
  +         // Unregister the channel itself
  +         try
  +         {
  +            on = new ObjectName(JGROUPS_JMX_DOMAIN + ":" + CHANNEL_JMX_ATTRIBUTES + getClusterName());
  +            server.unregisterMBean(on);
  +         }
  +         catch (Exception e)
  +         {
  +            if (on != null)
  +               log.error("Caught exception unregistering channel at " + on, e);
  +            else
  +               log.error("Caught exception unregistering channel", e);
  +         }
  +      }
  +      
  +      if (protocolsRegistered)
  +      {
  +         // Unregister the protocols
  +         try
  +         {
  +            on = new ObjectName(JGROUPS_JMX_DOMAIN + ":*," + PROTOCOL_JMX_ATTRIBUTES + getClusterName());
  +            Set mbeans=server.queryNames(on, null);
  +            if(mbeans != null) {
  +                for(Iterator it=mbeans.iterator(); it.hasNext();) {
  +                    server.unregisterMBean((ObjectName)it.next());
  +                }
  +            }
  +         }
  +         catch (Exception e)
  +         {
  +            if (on != null)
  +               log.error("Caught exception unregistering protocols at " + on, e);
  +            else
  +               log.error("Caught exception unregistering protocols", e);
  +         }
  +      }
  +   }
  +
      static interface TransactionLockStatus extends Status
      {
         public static final int STATUS_BROKEN = Integer.MIN_VALUE;
  
  
  



More information about the jboss-cvs-commits mailing list