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

Brian Stansberry brian.stansberry at jboss.com
Wed May 9 14:19:06 EDT 2007


  User: bstansberry
  Date: 07/05/09 14:19:06

  Modified:    src/org/jboss/cache  CacheImpl.java
  Log:
  [JBCACHE-934] Remove ChannelFactory JMX lookup from CacheImpl
  [JBCACHE--1023] Inject preconfigured Channel
  [JBCACHE-1050] Don't throw NPE if getInterceptorChain() invoked before create()
  [JBCACHE-1046] CacheImpl.channel should be type Channel
  
  Revision  Changes    Path
  1.63      +67 -112   JBossCache/src/org/jboss/cache/CacheImpl.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheImpl.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheImpl.java,v
  retrieving revision 1.62
  retrieving revision 1.63
  diff -u -b -r1.62 -r1.63
  --- CacheImpl.java	26 Apr 2007 14:09:51 -0000	1.62
  +++ CacheImpl.java	9 May 2007 18:19:06 -0000	1.63
  @@ -51,6 +51,7 @@
   import org.jgroups.Channel;
   import org.jgroups.ChannelClosedException;
   import org.jgroups.ChannelException;
  +import org.jgroups.ChannelFactory;
   import org.jgroups.ChannelNotConnectedException;
   import org.jgroups.ExtendedMembershipListener;
   import org.jgroups.ExtendedMessageListener;
  @@ -59,14 +60,11 @@
   import org.jgroups.View;
   import org.jgroups.blocks.GroupRequest;
   import org.jgroups.blocks.RpcDispatcher;
  -import org.jgroups.jmx.JChannelFactoryMBean;
   import org.jgroups.stack.IpAddress;
   import org.jgroups.util.Rsp;
   import org.jgroups.util.RspList;
   import org.jgroups.util.Util;
   
  -import javax.management.MBeanServer;
  -import javax.management.ObjectName;
   import javax.transaction.Status;
   import javax.transaction.SystemException;
   import javax.transaction.Transaction;
  @@ -110,10 +108,6 @@
       */
      private Log log = LogFactory.getLog(CacheImpl.class);
   
  -   private static final String CREATE_MUX_CHANNEL = "createMultiplexerChannel";
  -
  -   private static final String[] MUX_TYPES = {"java.lang.String", "java.lang.String"};
  -
      /**
       * Root node.
       */
  @@ -127,7 +121,7 @@
      /**
       * The JGroups JChannel in use.
       */
  -   protected JChannel channel = null;
  +   protected Channel channel = null;
   
      /**
       * True if this CacheImpl is the coordinator.
  @@ -642,73 +636,10 @@
            case REPL_ASYNC:
            case INVALIDATION_ASYNC:
            case INVALIDATION_SYNC:
  -            if (log.isDebugEnabled()) log.debug("cache mode is " + configuration.getCacheMode());
  -            if (channel != null)
  -            {// already started
  -               log.info("channel is already running");
  -               return;
  -            }
  -
  -            // Try to create a multiplexer channel
  -            channel = getMultiplexerChannel();
  -
  -            if (channel != null)
  -            {
  -               configuration.setUsingMultiplexer(true);
  -               if (log.isDebugEnabled())
  -               {
  -                  log.debug("Created Multiplexer Channel for cache cluster " + configuration.getClusterName() +
  -                          " using stack " + configuration.getMultiplexerStack());
  -               }
  -            }
  -            else
  -            {
  -               if (configuration.getClusterConfig() == null)
  -               {
  -                  // BES Jan-9-2007 temp workaround until we decide if we should
  -                  // aggressively throw exceptions from getMultiplexerChannel
  -                  if (configuration.getMultiplexerService() != null
  -                          || configuration.getMultiplexerStack() != null
  -                          || configuration.getRuntimeConfig().getMuxChannelFactory() != null)
  -                  {
  -                     throw new RuntimeException("Unable to start multiplexed Channel and property ClusterConfig not set");
  -                  }
  -                  configuration.setClusterConfig(getDefaultProperties());
  -                  log.debug("setting cluster properties to default value");
  -               }
  -               try
  -               {
  -                  channel = new JChannel(configuration.getClusterConfig());
  -               }
  -               catch (Exception e)
  -               {
  -                  throw new CacheException("Unable to create JGroups channel", e);
  -               }
  -               if (log.isTraceEnabled())
  -               {
  -                  log.trace("cache properties: " + configuration.getClusterConfig());
  -               }
  -            }
  -            channel.setOpt(Channel.AUTO_RECONNECT, true);
  -            channel.setOpt(Channel.AUTO_GETSTATE, true);
  -            channel.setOpt(Channel.BLOCK, true);
  -
  -            /* Used for JMX jconsole for JDK5.0
  -                        ArrayList servers=MBeanServerFactory.findMBeanServer(null);
  -                        if(servers == null || servers.size() == 0) {
  -                            throw new Exception("No MBeanServers found;" +
  -                                                "\nJmxTest needs to be run with an MBeanServer present, or inside JDK 5"); }
  -                        MBeanServer server=(MBeanServer)servers.get(0);
  -                        JmxConfigurator.registerChannel(channel, server, "JGroups:channel=" + channel.getChannelName() , true);
  -            */
   
  -            // always use the InactiveRegionAwareRpcDispatcher - exceptions due to regions not being active should not propagate to remote
  -            // nodes as errors. - Manik
  -            disp = new InactiveRegionAwareRpcDispatcher(channel, ml, new MembershipListenerAdaptor(), this);
  -            //            disp = new RpcDispatcher(channel, ml, this, this);
  +            if (log.isDebugEnabled()) log.debug("cache mode is " + configuration.getCacheMode());
   
  -            disp.setRequestMarshaller(getMarshaller());
  -            disp.setResponseMarshaller(getMarshaller());
  +            initialiseChannelAndRpcDispatcher();
   
               setBuddyReplicationConfig(configuration.getBuddyReplicationConfig());
               break;
  @@ -4008,65 +3939,89 @@
      // END: Methods to provide backward compatibility with older cache loader config settings
      // ---------------------------------------------------------------
   
  -   private JChannel getMultiplexerChannel()
  +   private void initialiseChannelAndRpcDispatcher() throws CacheException
      {
  -      String stackName = configuration.getMultiplexerStack();
  +      channel = configuration.getRuntimeConfig().getChannel();
  +      if (channel == null)
  +      {
  +         // Try to create a multiplexer channel
  +         channel = getMultiplexerChannel();
   
  -      RuntimeConfig rtc = configuration.getRuntimeConfig();
  -      JChannelFactoryMBean channelFactory = rtc.getMuxChannelFactory();
  -      try
  +         if (channel != null)
         {
  -         if (channelFactory != null)
  +            configuration.setUsingMultiplexer(true);
  +            if (log.isDebugEnabled())
            {
  -            return (JChannel) channelFactory.createMultiplexerChannel(stackName, configuration.getClusterName());
  +               log.debug("Created Multiplexer Channel for cache cluster " + configuration.getClusterName() +
  +                       " using stack " + configuration.getMultiplexerStack());
  +            }
            }
            else
            {
  -            // FIXME -- why do we support this?  Move into a specialized JMX class
  -            // meant for dealing with old-style config files
  -            String serviceName = configuration.getMultiplexerService();
  -
  -            if (serviceName == null || serviceName.length() == 0)
  +            if (configuration.getClusterConfig() == null)
               {
  -               return null;
  +               log.debug("setting cluster properties to default value");
  +               configuration.setClusterConfig(getDefaultProperties());
               }
  -
  -            MBeanServer mbserver = rtc.getMbeanServer();
  -            if (mbserver == null)
  +            try
               {
  -               log.warn("Multiplexer service specified but MBean server not found." +
  -                       "  Multiplexer will not be used for cache cluster " + configuration.getClusterName() + ".");
  -               return null;
  +               channel = new JChannel(configuration.getClusterConfig());
               }
  -
  -            ObjectName muxName = new ObjectName(serviceName);
  -
  -            // see if Multiplexer service is registered
  -            if (!mbserver.isRegistered(muxName))
  +            catch (Exception e)
               {
  -               log.warn("Multiplexer service specified but '" + serviceName + "' not registered." +
  -                       "  Multiplexer will not be used for cache cluster " + configuration.getClusterName() + ".");
  -               return null;
  +               throw new CacheException("Unable to create JGroups channel", e);
  +            }
  +            if (log.isTraceEnabled())
  +            {
  +               log.trace("cache properties: " + configuration.getClusterConfig());
  +            }
  +         }
  +         
  +         configuration.getRuntimeConfig().setChannel(channel);
               }
   
  -            // create the multiplexer channel and return as a JChannel instance
  -            Object[] params = {stackName, configuration.getClusterName()};
  -            return (JChannel) mbserver.invoke(muxName, CREATE_MUX_CHANNEL, params, MUX_TYPES);
  +      channel.setOpt(Channel.AUTO_RECONNECT, true);
  +      channel.setOpt(Channel.AUTO_GETSTATE, true);
  +      channel.setOpt(Channel.BLOCK, true);  
  +      
  +      // always use the InactiveRegionAwareRpcDispatcher - exceptions due to regions not being active should not propagate to remote
  +      // nodes as errors. - Manik
  +      disp = new InactiveRegionAwareRpcDispatcher(channel, ml, new MembershipListenerAdaptor(), this);
  +      //            disp = new RpcDispatcher(channel, ml, this, this);
  +
  +      disp.setRequestMarshaller(getMarshaller());
  +      disp.setResponseMarshaller(getMarshaller());
            }
  +
  +   private JChannel getMultiplexerChannel() throws CacheException
  +   {
  +      String stackName = configuration.getMultiplexerStack();
  +
  +      RuntimeConfig rtc = configuration.getRuntimeConfig();
  +      ChannelFactory channelFactory = rtc.getMuxChannelFactory();
  +      JChannel muxchannel = null;
  +
  +      if (channelFactory != null)
  +      {
  +         try
  +         {
  +            muxchannel = (JChannel) channelFactory.createMultiplexerChannel(stackName, configuration.getClusterName());
         }
         catch (Exception e)
         {
  -         log.error("Multiplexer channel creation failed." +
  -                 "  Multiplexer will not be used for cache cluster " + configuration.getClusterName() + ".", e);
  -         return null;
  +            throw new CacheException("Failed to create multiplexed channel using stack " + stackName, e);
  +         }
         }
  +
  +      return muxchannel;
      }
   
      // ================== methods to implement Cache and CacheSPI interfaces ============================
   
      public List<Interceptor> getInterceptorChain()
      {
  -      return Collections.unmodifiableList(getInterceptors());
  +      List<Interceptor> modifiable = getInterceptors();
  +      return modifiable == null ? null : Collections.unmodifiableList(modifiable);
      }
   
      public void addCacheListener(CacheListener l)
  
  
  



More information about the jboss-cvs-commits mailing list