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

Brian Stansberry brian.stansberry at jboss.com
Tue May 22 16:12:40 EDT 2007


  User: bstansberry
  Date: 07/05/22 16:12:40

  Modified:    src/org/jboss/cache/loader/tcp   TcpCacheServer.java
                        TcpCacheServerMBean.java
  Log:
  [JBCACHE-1053] Remove unused mbean attribs from when we did JMX lookup
  [JBCACHE-1069] Support injection of CacheJmxWrapper
  [JBCACHE-1068] Get rid of LifeCycle interface.
  
  Revision  Changes    Path
  1.29      +41 -37    JBossCache/src/org/jboss/cache/loader/tcp/TcpCacheServer.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TcpCacheServer.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/tcp/TcpCacheServer.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -b -r1.28 -r1.29
  --- TcpCacheServer.java	21 May 2007 10:30:55 -0000	1.28
  +++ TcpCacheServer.java	22 May 2007 20:12:40 -0000	1.29
  @@ -10,10 +10,9 @@
   import org.jboss.cache.Modification;
   import org.jboss.cache.Node;
   import org.jboss.cache.NodeSPI;
  +import org.jboss.cache.jmx.CacheJmxWrapperMBean;
   import org.jboss.cache.loader.DelegatingCacheLoader;
   
  -import javax.management.MalformedObjectNameException;
  -import javax.management.ObjectName;
   import java.io.BufferedInputStream;
   import java.io.BufferedOutputStream;
   import java.io.IOException;
  @@ -36,7 +35,8 @@
    * TCP-IP based CacheServer, setCache TcpDelegatingCacheLoader with host and port of this server
    *
    * @author Bela Ban
  - * @version $Id: TcpCacheServer.java,v 1.28 2007/05/21 10:30:55 msurtani Exp $
  + * @author Brian Stansberry
  + * @version $Id: TcpCacheServer.java,v 1.29 2007/05/22 20:12:40 bstansberry Exp $
    */
   public class TcpCacheServer implements TcpCacheServerMBean
   {
  @@ -44,11 +44,10 @@
      private InetAddress bind_addr = null;
      private int port = 7500;
      private CacheSPI cache;
  -   private ObjectName cache_name;
  +   private CacheJmxWrapperMBean wrapper;
      private String config;
      private boolean running = true;
  -   private final List<Connection> conns = new LinkedList<Connection>();
  -   private String agendId;
  +   private final List<Connection> conns = Collections.synchronizedList(new LinkedList<Connection>());
      /**
       * whether or not to start the server thread as a daemon.  Should be false if started from the command line, true if started as an MBean.
       */
  @@ -83,16 +82,6 @@
         this.port = port;
      }
   
  -   public String getMBeanServerName()
  -   {
  -      return agendId;
  -   }
  -
  -   public void setMBeanServerName(String name)
  -   {
  -      agendId = name;
  -   }
  -
      public String getConfig()
      {
         return config;
  @@ -113,21 +102,28 @@
         this.cache = cache;
      }
   
  -   public String getCacheName()
  +   public void setCacheJmxWrapper(CacheJmxWrapperMBean wrapper)
      {
  -      return cache_name != null ? cache_name.toString() : "n/a";
  -   }
  -
  -   public void setCacheName(String cache_name) throws MalformedObjectNameException
  -   {
  -      this.cache_name = new ObjectName(cache_name);
  +      this.wrapper = wrapper;
      }
   
      public void start() throws Exception
      {
         if (cache == null)
  -      {// still not set
  -         if (config != null)
  +      {  
  +         // cache not directly set; get from wrapper or create from config
  +         if (wrapper != null)
  +         {
  +            cache = (CacheSPI) wrapper.getCache();
  +
  +            if (cache == null)
  +            {
  +               throw new CacheException("cache cannot be obtained from CacheJmxWrapperMBean;" +
  +                    " be sure start() is invoked on wrapper before it is invoked on the" +
  +                    " TcpCacheServer");
  +            }
  +         }
  +         else if (config != null)
            {
               cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(this.config);
            }
  @@ -140,7 +136,6 @@
   
   
         srv_sock = new ServerSocket(port, 10, bind_addr);
  -      System.out.println("TcpCacheServer listening on : " + srv_sock.getInetAddress() + ":" + srv_sock.getLocalPort());
         log.info("TcpCacheServer listening on : " + srv_sock.getInetAddress() + ":" + srv_sock.getLocalPort());
   
         running = true;
  @@ -186,11 +181,17 @@
      public void stop()
      {
         running = false;
  -      for (Connection conn : conns)
  +      synchronized(conns)
  +      {
  +         // Connection.close() removes conn from the list,
  +         // so copy off the list first to avoid ConcurrentModificationException
  +         List<Connection> copy = new ArrayList<Connection>(conns);
  +         for (Connection conn : copy)
         {
            conn.close();
         }
         conns.clear();
  +      }
   
         if (srv_sock != null)
         {
  @@ -209,6 +210,8 @@
   
      public String getConnections()
      {
  +      synchronized(conns)
  +      {
         StringBuffer sb = new StringBuffer();
         sb.append(conns.size()).append(" connections:\n");
         for (Connection c : conns)
  @@ -217,6 +220,7 @@
         }
         return sb.toString();
      }
  +   }
   
   
      public void create()
  
  
  
  1.7       +22 -12    JBossCache/src/org/jboss/cache/loader/tcp/TcpCacheServerMBean.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TcpCacheServerMBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/tcp/TcpCacheServerMBean.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- TcpCacheServerMBean.java	21 May 2007 10:30:55 -0000	1.6
  +++ TcpCacheServerMBean.java	22 May 2007 20:12:40 -0000	1.7
  @@ -2,17 +2,27 @@
   
   import org.jboss.cache.Cache;
   import org.jboss.cache.CacheSPI;
  -import org.jboss.cache.jmx.LifeCycle;
  +import org.jboss.cache.jmx.CacheJmxWrapperMBean;
   
  -import javax.management.MalformedObjectNameException;
   import java.net.UnknownHostException;
   
   /**
  + * StandardMBean interface for {@link TcpCacheServer}.
  + * 
    * @author Bela Ban
  - * @version $Id: TcpCacheServerMBean.java,v 1.6 2007/05/21 10:30:55 msurtani Exp $
  + * @author Brian Stansberry
  + * @version $Id: TcpCacheServerMBean.java,v 1.7 2007/05/22 20:12:40 bstansberry Exp $
    */
  -public interface TcpCacheServerMBean extends LifeCycle
  +public interface TcpCacheServerMBean
   {
  +   void create() throws Exception;
  +
  +   void start() throws Exception;
  +
  +   void stop();
  +
  +   void destroy();
  +   
      String getBindAddress();
   
      void setBindAddress(String bind_addr) throws UnknownHostException;
  @@ -21,10 +31,6 @@
   
      void setPort(int port);
   
  -   String getMBeanServerName();
  -
  -   void setMBeanServerName(String name);
  -
      String getConfig();
   
      void setConfig(String config);
  @@ -33,9 +39,13 @@
   
      void setCache(CacheSPI cache);
   
  -   String getCacheName();
  -
  -   void setCacheName(String cache_name) throws MalformedObjectNameException;
  +   /**
  +    * Allows {@link #setCache(CacheSPI) injection of the CacheSPI} via
  +    * a {@link CacheJmxWrapperMBean}.
  +    * 
  +    * @param wrapper
  +    */
  +   void setCacheJmxWrapper(CacheJmxWrapperMBean wrapper);
   
      String getConnections();
   }
  
  
  



More information about the jboss-cvs-commits mailing list