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

Manik Surtani msurtani at jboss.com
Wed Sep 6 11:30:54 EDT 2006


  User: msurtani
  Date: 06/09/06 11:30:54

  Modified:    src/org/jboss/cache/aop    MarshalledTreeCache.java
                        PojoCache.java TreeCacheAopView.java
  Log:
  Removed TreeCache dependency on ServiceMBeanSupport
  
  Revision  Changes    Path
  1.15      +140 -110  JBossCache/src/org/jboss/cache/aop/MarshalledTreeCache.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MarshalledTreeCache.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/aop/MarshalledTreeCache.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- MarshalledTreeCache.java	16 Aug 2006 10:52:50 -0000	1.14
  +++ MarshalledTreeCache.java	6 Sep 2006 15:30:54 -0000	1.15
  @@ -6,11 +6,11 @@
    */
   package org.jboss.cache.aop;
   
  -import org.jboss.cache.TreeCache;
  -import org.jboss.cache.Fqn;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.CacheListener;
   import org.jboss.cache.CacheSPI;
  +import org.jboss.cache.Fqn;
  +import org.jboss.cache.TreeCache;
   import org.jboss.cache.config.Configuration;
   import org.jboss.cache.lock.IsolationLevel;
   import org.jboss.invocation.MarshalledValue;
  @@ -18,9 +18,9 @@
   import org.jgroups.View;
   import org.jgroups.stack.IpAddress;
   
  +import java.io.IOException;
   import java.util.HashMap;
   import java.util.Map;
  -import java.io.IOException;
   
   /**
    * <p>Version of TreeCache that added call to handle marshalling values. You will need marshalling when your application
  @@ -32,9 +32,11 @@
    * with specific modified key, 3) we will also move this to different package.</p>
    * <p>Finally, since the use of in-memory copy, the memory usage is almost doubled since we have one in-memory copy and
    * the marshalled value in the cache store.</p>
  + *
    * @author Ben Wang
    */
  -public class MarshalledTreeCache extends TreeCache implements CacheListener {
  +public class MarshalledTreeCache extends TreeCache implements CacheListener
  +{
      // Store the in-memory copy of the treecache (key, value) pair.
      // This is used for performance reason so there is no need to un-marshall every single operation.
      // In addition, it will support an invalidation mechanism.
  @@ -71,7 +73,8 @@
         this._init();
      }
   
  -   private void _init() throws Exception {
  +   private void _init() throws Exception
  +   {
         localCopy_ = new TreeCache();
         Configuration conf = new Configuration();
         conf.setCacheMode("LOCAL");
  @@ -82,21 +85,21 @@
         tcl_ = null;
      }
   
  -   public void startService() throws Exception
  +   public void start() throws Exception
      {
         super.getNotifier().addCacheListener(this);
  -      super.startService();
  -      if(localCopy_ == null)
  -         throw new RuntimeException("startService(): null localCopy_");
  -      localCopy_.startService();
  +      super.start();
  +      if (localCopy_ == null)
  +         throw new RuntimeException("start(): null localCopy_");
  +      localCopy_.start();
         obtainNodeId();
      }
   
  -   public void stopService()
  +   public void stop()
      {
         nodeId_ = null;
  -      localCopy_.stopService();
  -      super.stopService();
  +      localCopy_.stop();
  +      super.stop();
      }
   
      /**
  @@ -104,8 +107,8 @@
       */
      protected void obtainNodeId()
      {
  -      IpAddress address = (IpAddress)getLocalAddress();
  -      if(address == null)
  +      IpAddress address = (IpAddress) getLocalAddress();
  +      if (address == null)
         {
            log.info("obtainNodeId(): has null IpAddress. Assume it is running in local mode.");
            nodeId_ = "local";
  @@ -125,14 +128,14 @@
      /**
       * DataNode id is a communication id that denotes the cluster node.
       */
  -   public String getNodeId() {
  +   public String getNodeId()
  +   {
         return nodeId_;
      }
   
   
      /**
       * Turn marshalling layer on or off. If off, no marshalling. Default is on.
  -    *
       */
      public void setMarshalling(boolean marshalling)
      {
  @@ -158,7 +161,8 @@
         tcl_ = tcl;
      }
   
  -   public void marshalledPut(String fqn, Object key, Object value) throws CacheException {
  +   public void marshalledPut(String fqn, Object key, Object value) throws CacheException
  +   {
         marshalledPut(Fqn.fromString(fqn), key, value);
      }
   
  @@ -168,10 +172,12 @@
       */
      public void marshalledPut(Fqn fqn, Object key, Object value) throws CacheException
      {
  -      if(marshalling_)
  +      if (marshalling_)
         {
            marshalledPut_(fqn, key, value);
  -      } else {
  +      }
  +      else
  +      {
            put(fqn, key, value);
         }
      }
  @@ -179,11 +185,14 @@
      public void marshalledPut_(Fqn fqn, Object key, Object value) throws CacheException
      {
         MarshalledValue mv = null;
  -      try {
  +      try
  +      {
            mv = new MarshalledValue(value);
  -      } catch (IOException e) {
  +      }
  +      catch (IOException e)
  +      {
            e.printStackTrace();
  -         throw new CacheException("marshalledPut() exception: " +e);
  +         throw new CacheException("marshalledPut() exception: " + e);
         }
   
         // Put into local copy first.
  @@ -195,7 +204,8 @@
         this.put(fqn, map);
      }
   
  -   public Object marshalledGet(String fqn, Object key) throws CacheException {
  +   public Object marshalledGet(String fqn, Object key) throws CacheException
  +   {
         return marshalledGet(Fqn.fromString(fqn), key);
      }
   
  @@ -203,51 +213,61 @@
       * Obtain the value from the marshalled cache. Note that the return value is un-marshalled
       * either from the local copy or from the distributed store.
       */
  -   public Object marshalledGet(Fqn fqn, Object key) throws CacheException {
  -      if(marshalling_)
  +   public Object marshalledGet(Fqn fqn, Object key) throws CacheException
  +   {
  +      if (marshalling_)
         {
            ClassLoader prevTCL = null;
  -         if(tcl_ != null)
  +         if (tcl_ != null)
            {
               prevTCL = Thread.currentThread().getContextClassLoader();
               Thread.currentThread().setContextClassLoader(tcl_);
            }
  -         try {
  +         try
  +         {
               return marshalledGet_(fqn, key);
  -         } finally
  +         }
  +         finally
            {
  -            if(tcl_ != null && prevTCL != null)
  +            if (tcl_ != null && prevTCL != null)
               {
                  Thread.currentThread().setContextClassLoader(prevTCL);
               }
            }
  -      } else
  +      }
  +      else
         {
            return get(fqn, key);
         }
      }
   
  -   public Object marshalledGet_(Fqn fqn, Object key) throws CacheException {
  +   public Object marshalledGet_(Fqn fqn, Object key) throws CacheException
  +   {
         // Check if it is in local copy first.
         Object value;
  -      try {
  -         if( (value = localCopy_.get(fqn, key)) != null)
  +      try
  +      {
  +         if ((value = localCopy_.get(fqn, key)) != null)
               return value;
            else
            {  // get it from cache store
               value = get(fqn, key);
  -            if(value == null) return null;
  +            if (value == null) return null;
               checkValue(value);
  -            MarshalledValue mv = (MarshalledValue)value;
  +            MarshalledValue mv = (MarshalledValue) value;
               value = mv.get();
               // populate the local copy
               localCopy_.put(fqn, key, value);
               return value;
            }
  -      } catch (IOException e) {
  +      }
  +      catch (IOException e)
  +      {
            e.printStackTrace();
            throw new CacheException("marshalledGet(): exception encountered: ", e);
  -      } catch (ClassNotFoundException e) {
  +      }
  +      catch (ClassNotFoundException e)
  +      {
            e.printStackTrace();
            throw new CacheException("marshalledGet(): exception encountered: ", e);
         }
  @@ -264,10 +284,11 @@
       */
      public Object marshalledRemove(Fqn fqn, Object key) throws CacheException
      {
  -      if(marshalling_)
  +      if (marshalling_)
         {
            return marshalledRemove_(fqn, key);
  -      } else
  +      }
  +      else
         {
            return remove(fqn, key);
         }
  @@ -275,21 +296,26 @@
   
      public Object marshalledRemove_(Fqn fqn, Object key) throws CacheException
         {
  -      if( !exists(fqn, key) )
  -         log.warn("marshalledRemove(): fqn: " +fqn + " key: " +key + " not found.");
  +      if (!exists(fqn, key))
  +         log.warn("marshalledRemove(): fqn: " + fqn + " key: " + key + " not found.");
   
         Object value = localCopy_.get(fqn, key);
         localCopy_.remove(fqn);
         remove(fqn, NODEID_KEY);
         Object obj = remove(fqn, key);
  -      if(value != null) return value;
  +      if (value != null) return value;
         checkValue(obj);
  -      try {
  -         return ((MarshalledValue)obj).get();
  -      } catch (IOException e) {
  +      try
  +      {
  +         return ((MarshalledValue) obj).get();
  +      }
  +      catch (IOException e)
  +      {
            e.printStackTrace();
            throw new CacheException("marshalledRemove(): exception encountered: ", e);
  -      } catch (ClassNotFoundException e) {
  +      }
  +      catch (ClassNotFoundException e)
  +      {
            e.printStackTrace();
            throw new CacheException("marshalledRemove(): exception encountered: ", e);
         }
  @@ -344,29 +370,33 @@
   
      protected void checkValue(Object value)
      {
  -      if( value != null && !(value instanceof MarshalledValue))
  -         throw new RuntimeException("checkValue: return object is not instance of MarshalledValue. object: "+value);
  +      if (value != null && !(value instanceof MarshalledValue))
  +         throw new RuntimeException("checkValue: return object is not instance of MarshalledValue. object: " + value);
      }
   
      /**
       * Invalidate the local copy cache. Assumption is invlidation should not happen that often anyway.
       * In addition, we will invalidate the whole thing under the fqn.
  +    *
       * @param fqn
       */
      protected void invalidate(Fqn fqn)
      {
  -      if(!marshalling_) return; // No need if there is no marshalling!
  -      if(fqn.isRoot()) return; // No need to handle root.
  -      if( !localCopy_.exists(fqn)) return; // probably not a mv node anyway.
  -
  -      try {
  -         String eventId = (String)get(fqn, NODEID_KEY);
  -         if(eventId == null)
  -            throw new RuntimeException("invlidate(): fqn to invlidate has null node id. fqn: " +fqn);
  +      if (!marshalling_) return; // No need if there is no marshalling!
  +      if (fqn.isRoot()) return; // No need to handle root.
  +      if (!localCopy_.exists(fqn)) return; // probably not a mv node anyway.
  +
  +      try
  +      {
  +         String eventId = (String) get(fqn, NODEID_KEY);
  +         if (eventId == null)
  +            throw new RuntimeException("invlidate(): fqn to invlidate has null node id. fqn: " + fqn);
   
  -         if( nodeId_.equals(eventId) ) return; // skip since this event is initiated by myself.
  +         if (nodeId_.equals(eventId)) return; // skip since this event is initiated by myself.
            localCopy_.remove(fqn);
  -      } catch (CacheException e) {
  +      }
  +      catch (CacheException e)
  +      {
            e.printStackTrace();
         }
      }
  
  
  
  1.29      +104 -90   JBossCache/src/org/jboss/cache/aop/PojoCache.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PojoCache.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/aop/PojoCache.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -b -r1.28 -r1.29
  --- PojoCache.java	20 Jul 2006 21:58:21 -0000	1.28
  +++ PojoCache.java	6 Sep 2006 15:30:54 -0000	1.29
  @@ -6,33 +6,33 @@
    */
   package org.jboss.cache.aop;
   
  -import org.jboss.cache.xml.XmlHelper;
  -import org.jboss.cache.lock.UpgradeException;
  +import org.jboss.aop.InstanceAdvisor;
  +import org.jboss.cache.CacheException;
  +import org.jboss.cache.Fqn;
  +import org.jboss.cache.NodeImpl;
  +import org.jboss.cache.RegionNotEmptyException;
  +import org.jboss.cache.TreeCache;
   import org.jboss.cache.aop.eviction.AopEvictionPolicy;
   import org.jboss.cache.aop.statetransfer.PojoStateTransferManager;
  +import org.jboss.cache.lock.UpgradeException;
  +import org.jboss.cache.marshall.ObjectSerializationFactory;
   import org.jboss.cache.marshall.Region;
   import org.jboss.cache.marshall.RegionNameConflictException;
  -import org.jboss.cache.marshall.ObjectSerializationFactory;
   import org.jboss.cache.transaction.BatchModeTransactionManager;
  -import org.jboss.cache.TreeCache;
  -import org.jboss.cache.Fqn;
  -import org.jboss.cache.CacheException;
  -import org.jboss.cache.RegionNotEmptyException;
  -import org.jboss.cache.NodeImpl;
  -import org.jboss.aop.InstanceAdvisor;
  +import org.jboss.cache.xml.XmlHelper;
   import org.jgroups.JChannel;
   import org.w3c.dom.Element;
   
  +import javax.transaction.RollbackException;
   import javax.transaction.Status;
   import javax.transaction.SystemException;
  -import javax.transaction.TransactionManager;
  -import javax.transaction.RollbackException;
   import javax.transaction.Transaction;
  +import javax.transaction.TransactionManager;
  +import java.lang.reflect.Field;
  +import java.util.ArrayList;
  +import java.util.List;
   import java.util.Map;
   import java.util.WeakHashMap;
  -import java.util.List;
  -import java.util.ArrayList;
  -import java.lang.reflect.Field;
   
   /**
    * PojoCache implementation class. User should use the {@link PojoCacheIfc} interface directly to
  @@ -89,17 +89,17 @@
         delegate_ = new TreeCacheAopDelegate(this);
      }
   
  -   public void startService() throws Exception
  +   public void start() throws Exception
      {
         // Replace the default state transfer manager
         setStateTransferManager(new PojoStateTransferManager(this));
  -      super.startService();
  +      super.start();
         parseConfig();
      }
   
  -   public void stopService()
  +   public void stop()
      {
  -      super.stopService();
  +      super.stop();
      }
   
      protected void parseConfig()
  @@ -110,7 +110,7 @@
            return;
         }
         marshallNonSerializable_ = XmlHelper.readBooleanContents(config_, "marshallNonSerializable");
  -      log.info("marshallNonSerializable flag is set: " +marshallNonSerializable_);
  +      log.info("marshallNonSerializable flag is set: " + marshallNonSerializable_);
   
   //      detachPojoWhenEvicted_ = XmlHelper.readBooleanContents(config_, "DetachPojoWhenEvicted");
      }
  @@ -145,8 +145,8 @@
   
      public void addUndoInterceptor(InstanceAdvisor advisor, BaseInterceptor interceptor, int op)
      {
  -      List list = (List)undoListLocal_.get();
  -      if(list == null)
  +      List list = (List) undoListLocal_.get();
  +      if (list == null)
         {
            list = new ArrayList();
            undoListLocal_.set(list);
  @@ -157,8 +157,8 @@
   
      public void addUndoCollectionProxy(Field field, Object key, Object oldValue)
      {
  -      List list = (List)undoListLocal_.get();
  -      if(list == null)
  +      List list = (List) undoListLocal_.get();
  +      if (list == null)
         {
            list = new ArrayList();
            undoListLocal_.set(list);
  @@ -169,8 +169,8 @@
   
      public void resetUndoOp()
      {
  -      List list = (List)undoListLocal_.get();
  -      if(list != null)
  +      List list = (List) undoListLocal_.get();
  +      if (list != null)
            list.clear();
         hasSynchronizationHandler_.set(null);
      }
  @@ -178,7 +178,7 @@
      public List getModList()
      {
         // No need to make it unmodifiable since this is thread local
  -      return (List)undoListLocal_.get();
  +      return (List) undoListLocal_.get();
      }
   
      /**
  @@ -313,7 +313,8 @@
            type = new CachedType(clazz);
            cachedTypes.put(clazz, type);
            return type;
  -      } else
  +      }
  +      else
         {
            return type;
         }
  @@ -345,9 +346,9 @@
      public Object putObject(Fqn fqn, Object obj) throws CacheException
      {
         checkFqnValidity(fqn);
  -      if(log.isDebugEnabled())
  +      if (log.isDebugEnabled())
         {
  -         log.debug("putObject(): Fqn:" +fqn);
  +         log.debug("putObject(): Fqn:" + fqn);
         }
   
         Object owner = null;
  @@ -356,9 +357,9 @@
            // Start a new transaction, we need transaction so the operation is batch.
            owner = getOwnerForLock(); // lock it for the whole duration of batch mode.
            // Lock the parent, create and add the child
  -         if(!lockPojo(owner, fqn))
  +         if (!lockPojo(owner, fqn))
            {
  -            throw new CacheException("PojoCache.putObject(): Can't obtain the pojo lock under fqn: "+fqn);
  +            throw new CacheException("PojoCache.putObject(): Can't obtain the pojo lock under fqn: " + fqn);
            }
            return _putObject(fqn, obj);
         }
  @@ -372,16 +373,16 @@
               localTm_.begin();
               owner = getOwnerForLock(); // lock it for the whole duration of batch mode.
               // Lock the parent, create and add the child
  -            if(!lockPojo(owner, fqn))
  +            if (!lockPojo(owner, fqn))
               {
  -               throw new CacheException("PojoCache.putObject(): Can't obtain the pojo lock under fqn: "+fqn);
  +               throw new CacheException("PojoCache.putObject(): Can't obtain the pojo lock under fqn: " + fqn);
               }
               Object objOld = _putObject(fqn, obj);
               return objOld;
            }
            catch (Exception e)
            {
  -            log.warn("putObject(): exception occurred: " +e);
  +            log.warn("putObject(): exception occurred: " + e);
               try
               {
                  localTm_.setRollbackOnly();
  @@ -391,10 +392,10 @@
                  exn.printStackTrace();
               }
   
  -            if(!(e instanceof CacheException))
  -               throw new RuntimeException("PojoCache.putObject(): fqn: " +fqn , e);
  +            if (!(e instanceof CacheException))
  +               throw new RuntimeException("PojoCache.putObject(): fqn: " + fqn, e);
               else
  -               throw (CacheException)e;
  +               throw (CacheException) e;
            }
            finally
            {
  @@ -418,18 +419,18 @@
      {
         checkFqnValidity(fqn);
   
  -      if(log.isDebugEnabled())
  +      if (log.isDebugEnabled())
         {
  -         log.debug("removeObject(): Fqn:" +fqn);
  +         log.debug("removeObject(): Fqn:" + fqn);
         }
   
         Object owner = null;
         if (hasCurrentTransaction())  // We have a transaction context going on now.
         {
            owner = getOwnerForLock();
  -         if(!lockPojo(owner, fqn))
  +         if (!lockPojo(owner, fqn))
            {
  -            throw new CacheException("PojoCache.removeObject(): Can't obtain the pojo lock under fqn: "+fqn);
  +            throw new CacheException("PojoCache.removeObject(): Can't obtain the pojo lock under fqn: " + fqn);
            }
            return _removeObject(fqn, true);
         }
  @@ -440,15 +441,15 @@
            {
               localTm_.begin();
               owner = getOwnerForLock();
  -            if(!lockPojo(owner, fqn))
  +            if (!lockPojo(owner, fqn))
               {
  -               throw new CacheException("PojoCache.removeObject(): Can't obtain the pojo lock under fqn: "+fqn);
  +               throw new CacheException("PojoCache.removeObject(): Can't obtain the pojo lock under fqn: " + fqn);
               }
               return _removeObject(fqn, true);
            }
            catch (Exception e)
            {
  -            log.warn("removeObject(): exception occurred: " +e);
  +            log.warn("removeObject(): exception occurred: " + e);
               try
               {
                  localTm_.setRollbackOnly();
  @@ -458,10 +459,10 @@
                  exn.printStackTrace();
               }
   
  -            if(!(e instanceof CacheException))
  -               throw new RuntimeException("PojoCache.removeObject(): fqn: " +fqn , e);
  +            if (!(e instanceof CacheException))
  +               throw new RuntimeException("PojoCache.removeObject(): fqn: " + fqn, e);
               else
  -               throw (CacheException)e;
  +               throw (CacheException) e;
            }
            finally
            {
  @@ -488,9 +489,9 @@
   
      public void setMarshallNonSerializable(boolean marshall)
      {
  -      if(marshall)
  +      if (marshall)
         {
  -         if(!ObjectSerializationFactory.useJBossSerialization())
  +         if (!ObjectSerializationFactory.useJBossSerialization())
            {
               throw new IllegalStateException("PojoCache.setMarshallNonSerializable(). " +
               "Can't set MarshallNonSerializable to true since useJBossSerialization is false");
  @@ -530,33 +531,38 @@
         }
      }
   
  -   protected boolean lockPojo(Object owner, Fqn fqn) throws CacheException {
  -      if(log.isDebugEnabled())
  +   protected boolean lockPojo(Object owner, Fqn fqn) throws CacheException
  +   {
  +      if (log.isDebugEnabled())
         {
  -         log.debug("lockPojo(): Fqn:" +fqn + " Owner: " +owner);
  +         log.debug("lockPojo(): Fqn:" + fqn + " Owner: " + owner);
         }
   
         boolean isNeeded = true;
         int retry = 0;
  -      while(isNeeded)
  +      while (isNeeded)
         {
            try
            {
               put(fqn, LOCK, "LOCK");
               isNeeded = false;
  -         } catch (UpgradeException upe)
  +         }
  +         catch (UpgradeException upe)
            {
  -            log.warn("lockPojo(): can't upgrade the lock during lockPojo. Will re-try. Fqn: " +fqn
  -                    + " retry times: " +retry);
  +            log.warn("lockPojo(): can't upgrade the lock during lockPojo. Will re-try. Fqn: " + fqn
  +                    + " retry times: " + retry);
               get(fqn).release(owner);
  -            if(retry++ > RETRY)
  +            if (retry++ > RETRY)
               {
                  return false;
               }
               // try to sleep a little as well.
  -            try {
  +            try
  +            {
                  Thread.sleep(10);
  -            } catch (InterruptedException e) {
  +            }
  +            catch (InterruptedException e)
  +            {
                  ;
               }
               continue;
  @@ -566,11 +572,12 @@
         return true;
      }
   
  -   protected void releasePojo(Object owner, Fqn fqn) throws CacheException {
  +   protected void releasePojo(Object owner, Fqn fqn) throws CacheException
  +   {
         NodeImpl node = get(fqn);
  -      if(node == null)
  +      if (node == null)
         {
  -         if(log.isDebugEnabled())
  +         if (log.isDebugEnabled())
            {
               log.debug("releasePojo(): node could have been released already.");
            }
  @@ -589,7 +596,9 @@
               // We have transaction context. Return null to signify don't do anything
               return true;
            }
  -      } catch (SystemException e) {
  +      }
  +      catch (SystemException e)
  +      {
            throw new RuntimeException("PojoCache.hasCurrentTransaction: ", e);
         }
         return false;
  @@ -599,7 +608,7 @@
      {
         if (localTm_ == null)
         {
  -         log.warn("PojoCache.endTransaction(): tm is null for fqn: " +fqn);
  +         log.warn("PojoCache.endTransaction(): tm is null for fqn: " + fqn);
            return;
         }
   
  @@ -610,24 +619,24 @@
            {
               localTm_.commit();
            }
  -         else if(localTm_.getTransaction().getStatus() == Status.STATUS_ROLLEDBACK)
  +         else if (localTm_.getTransaction().getStatus() == Status.STATUS_ROLLEDBACK)
            {
  -            log.info("PojoCache.endTransaction(): has been rolled back for fqn: " +fqn);
  +            log.info("PojoCache.endTransaction(): has been rolled back for fqn: " + fqn);
            }
            else
            {
  -            log.info("PojoCache.endTransaction(): rolling back tx for fqn: " +fqn);
  +            log.info("PojoCache.endTransaction(): rolling back tx for fqn: " + fqn);
               localTm_.rollback();
            }
         }
         catch (RollbackException re)
         {
            // Do nothing here since cache may rollback automatically.
  -         log.warn("PojoCache.endTransaction(): rolling back transaction with exception: " +re);
  +         log.warn("PojoCache.endTransaction(): rolling back transaction with exception: " + re);
         }
         catch (Exception e)
         {
  -         log.warn("PojoCache.endTransaction(): Failed with exception: " +e);
  +         log.warn("PojoCache.endTransaction(): Failed with exception: " + e);
         }
      }
   
  @@ -650,15 +659,16 @@
   
      protected void registerTxHandler() throws CacheException
      {
  -      try {
  +      try
  +      {
            // Need to have this in case of rollback
  -         Boolean isTrue = (Boolean)hasSynchronizationHandler_.get();
  -         if(isTrue == null || !isTrue.booleanValue())
  +         Boolean isTrue = (Boolean) hasSynchronizationHandler_.get();
  +         if (isTrue == null || !isTrue.booleanValue())
            {
               Transaction tx = getLocalTransaction();
  -            if(tx == null) tx = localTm_.getTransaction();
  +            if (tx == null) tx = localTm_.getTransaction();
   
  -            if(tx == null)
  +            if (tx == null)
               {
                  throw new IllegalStateException("PojoCache.registerTxHanlder(). Can't have null tx handle.");
               }
  @@ -667,10 +677,14 @@
   
               hasSynchronizationHandler_.set(Boolean.TRUE);
            }
  -      } catch (RollbackException e) {
  -         throw new CacheException("_putObject(). Exception: " +e);
  -      } catch (SystemException e) {
  -         throw new CacheException("_putObject(). Exception: " +e);
  +      }
  +      catch (RollbackException e)
  +      {
  +         throw new CacheException("_putObject(). Exception: " + e);
  +      }
  +      catch (SystemException e)
  +      {
  +         throw new CacheException("_putObject(). Exception: " + e);
         }
      }
   
  
  
  
  1.15      +226 -146  JBossCache/src/org/jboss/cache/aop/TreeCacheAopView.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCacheAopView.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/aop/TreeCacheAopView.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- TreeCacheAopView.java	16 Aug 2006 10:52:50 -0000	1.14
  +++ TreeCacheAopView.java	6 Sep 2006 15:30:54 -0000	1.15
  @@ -55,14 +55,14 @@
    * data needs to be displayed, the underlying tree will be accessed directly.
    *
    * @author Ben Wang
  + * @version $Revision: 1.15 $
    * @deprecated Not used now. Use TreeCacheView2 directly.
  - * @version $Revision: 1.14 $
    */
   public class TreeCacheAopView
   {
      TreeCacheAopGui gui_ = null;
      PojoCache cache_ = null;
  -   static Log log=LogFactory.getLog(TreeCacheAopView.class.getName());
  +   static Log log = LogFactory.getLog(TreeCacheAopView.class.getName());
   
      public TreeCacheAopView(PojoCache cache) throws Exception
      {
  @@ -71,7 +71,8 @@
   
      public void start() throws Exception
      {
  -      if (gui_ == null) {
  +      if (gui_ == null)
  +      {
            log.info("start(): creating the GUI");
            gui_ = new TreeCacheAopGui(cache_);
         }
  @@ -79,7 +80,8 @@
   
      public void stop()
      {
  -      if (gui_ != null) {
  +      if (gui_ != null)
  +      {
            log.info("stop(): disposing the GUI");
            gui_.dispose();
            gui_ = null;
  @@ -94,9 +96,11 @@
   
         put(dir, null);
   
  -      if (file.isDirectory()) {
  +      if (file.isDirectory())
  +      {
            String[] children = file.list();
  -         if (children != null && children.length > 0) {
  +         if (children != null && children.length > 0)
  +         {
               for (int i = 0; i < children.length; i++)
                  populateTree(dir + "/" + children[i]);
            }
  @@ -105,9 +109,12 @@
   
      void put(String fqn, Map m)
      {
  -      try {
  +      try
  +      {
            cache_.put(fqn, m);
  -      } catch (Throwable t) {
  +      }
  +      catch (Throwable t)
  +      {
            log.error("TreeCacheAopView.put(): " + t);
         }
      }
  @@ -117,11 +124,13 @@
         PojoCache tree = null;
         TreeCacheAopView demo;
         String start_directory = null;
  -      String resource="META-INF/replSync-service.xml";
  +      String resource = "META-INF/replSync-service.xml";
   
  -      for(int i=0; i < args.length; i++) {
  -         if(args[i].equals("-config")) {
  -            resource=args[++i];
  +      for (int i = 0; i < args.length; i++)
  +      {
  +         if (args[i].equals("-config"))
  +         {
  +            resource = args[++i];
               continue;
            }
            help();
  @@ -129,22 +138,26 @@
         }
   
   
  -      try {
  +      try
  +      {
            tree = new PojoCache();
            tree.setConfiguration(new XmlConfigurationParser().parseFile(resource));
   
            tree.getNotifier().addCacheListener(new TreeCacheView.MyListener());
  -         tree.createService();
  -         tree.startService();
  +         tree.create();
  +         tree.start();
   
            Runtime.getRuntime().addShutdownHook(new ShutdownThread(tree));
   
            demo = new TreeCacheAopView(tree);
            demo.start();
  -         if (start_directory != null && start_directory.length() > 0) {
  +         if (start_directory != null && start_directory.length() > 0)
  +         {
               demo.populateTree(start_directory);
            }
  -      } catch (Exception ex) {
  +      }
  +      catch (Exception ex)
  +      {
            ex.printStackTrace();
         }
      }
  @@ -184,7 +197,7 @@
   
      PojoCache cache_;
      DefaultTreeModel tree_model = null;
  -   Log log=LogFactory.getLog(getClass());
  +   Log log = LogFactory.getLog(getClass());
      JTree jtree = null;
      DefaultTableModel table_model = new DefaultTableModel();
      JTable table = new JTable(table_model);
  @@ -247,11 +260,13 @@
            {
               int selRow = jtree.getRowForLocation(e.getX(), e.getY());
               TreePath selPath = jtree.getPathForLocation(e.getX(), e.getY());
  -            if (selRow != -1) {
  +            if (selRow != -1)
  +            {
                  selected_node = makeFQN(selPath.getPath());
                  jtree.setSelectionPath(selPath);
   
  -               if (e.getModifiers() == java.awt.event.InputEvent.BUTTON3_MASK) {
  +               if (e.getModifiers() == java.awt.event.InputEvent.BUTTON3_MASK)
  +               {
                     operationsPopup.show(e.getComponent(),
                           e.getX(), e.getY());
                  }
  @@ -310,26 +325,35 @@
         int row, col;
         String key, val;
   
  -      if (evt.getType() == TableModelEvent.UPDATE) {
  +      if (evt.getType() == TableModelEvent.UPDATE)
  +      {
            row = evt.getFirstRow();
            col = evt.getColumn();
  -         if (col == 0) {  // set()
  +         if (col == 0)
  +         {  // set()
               key = (String) table_model.getValueAt(row, col);
               val = (String) table_model.getValueAt(row, col + 1);
  -            if (key != null && val != null) {
  +            if (key != null && val != null)
  +            {
                  // tree.put(selected_node, key, val);
   
  -               try {
  +               try
  +               {
                     cache_.put(selected_node, key, val);
  -               } catch (Exception e) {
  +               }
  +               catch (Exception e)
  +               {
                     e.printStackTrace();
                  }
   
               }
  -         } else {          // add()
  +         }
  +         else
  +         {          // add()
               key = (String) table_model.getValueAt(row, col - 1);
               val = (String) table.getValueAt(row, col);
  -            if (key != null && val != null) {
  +            if (key != null && val != null)
  +            {
                  put(selected_node, key, val);
               }
            }
  @@ -344,7 +368,8 @@
         String component_name;
         Map data = null;
   
  -      for (int i = 0; i < path.getPathCount(); i++) {
  +      for (int i = 0; i < path.getPathCount(); i++)
  +      {
            component_name = ((MyNode) path.getPathComponent(i)).name;
            if (component_name.equals(SEP))
               continue;
  @@ -355,19 +380,20 @@
         }
         data = getData(fqn);
         System.out.println("valueChanged(): fqn: " + fqn + " data: " + data);
  -      if (data != null) {
  +      if (data != null)
  +      {
            getContentPane().add(tablePanel, BorderLayout.SOUTH);
            populateTable(data);
            validate();
  -      } else {
  +      }
  +      else
  +      {
            clearTable();
            getContentPane().remove(tablePanel);
            validate();
         }
      }
   
  -
  -
      /* ------------------ ReplicatedTree.ReplicatedTreeListener interface ------------ */
   
      public void nodeCreated(Fqn fqn, boolean pre, boolean isLocal)
  @@ -377,7 +403,8 @@
             MyNode n, p;
   
             n = root.add(fqn);
  -          if (n != null) {
  +         if (n != null)
  +         {
                p = (MyNode) n.getParent();
                tree_model.reload(p);
                jtree.scrollPathToVisible(new TreePath(n.getPath()));
  @@ -393,7 +420,8 @@
             TreeNode par;
   
             n = root.findNode(fqn.toString());
  -          if (n != null) {
  +         if (n != null)
  +         {
                n.removeAllChildren();
                par = n.getParent();
                n.removeFromParent();
  @@ -402,7 +430,8 @@
          }
      }
   
  -   public void nodeLoaded(Fqn fqn, boolean pre, Map data) {
  +   public void nodeLoaded(Fqn fqn, boolean pre, Map data)
  +   {
         nodeCreated(fqn, pre, true);
      }
   
  @@ -414,7 +443,8 @@
       {
       }
   
  -    public void nodeEvicted(Fqn fqn, boolean pre, boolean isLocal) {
  +   public void nodeEvicted(Fqn fqn, boolean pre, boolean isLocal)
  +   {
          nodeRemoved(fqn, pre, isLocal, null);
       }
   
  @@ -427,7 +457,8 @@
        // new Thread() {
          //  public void run() {
               Map data;
  -            if (currentNodeSelected != null && !currentNodeSelected.equals(fqn.toString())) return; // DataNode modified is not visible. Continue...
  +         if (currentNodeSelected != null && !currentNodeSelected.equals(fqn.toString()))
  +            return; // DataNode modified is not visible. Continue...
               data = getData(fqn.toString());
               populateTable(data); // REVISIT
         //   }
  @@ -458,7 +489,8 @@
            public void run()
            {
               Vector mbrship;
  -            if (new_view != null && (mbrship = new_view.getMembers()) != null) {
  +            if (new_view != null && (mbrship = new_view.getMembers()) != null)
  +            {
                  _put(SEP, "members", mbrship);
                  _put(SEP, "coordinator", mbrship.firstElement());
               }
  @@ -466,9 +498,6 @@
         }.start();
      }
   
  -
  -
  -
      /* ---------------- End of ReplicatedTree.ReplicatedTreeListener interface -------- */
   
      /*----------------- Runnable implementation to make View change calles in AWT Thread ---*/
  @@ -478,8 +507,6 @@
   
      }
   
  -
  -
      /* ----------------------------- Private Methods ---------------------------------- */
   
      /**
  @@ -492,7 +519,8 @@
         addGuiNode(SEP);
   
         mbrship = getMembers() != null ? (Vector) getMembers().clone() : null;
  -      if (mbrship != null && mbrship.size() > 0) {
  +      if (mbrship != null && mbrship.size() > 0)
  +      {
            _put(SEP, "members", mbrship);
            _put(SEP, "coordinator", mbrship.firstElement());
         }
  @@ -523,8 +551,10 @@
   
         // 2. Then add my children
         children = getChildrenNames(fqn);
  -      if (children != null) {
  -         for (Iterator it = children.iterator(); it.hasNext();) {
  +      if (children != null)
  +      {
  +         for (Iterator it = children.iterator(); it.hasNext();)
  +         {
               child_name = (String) it.next();
               addGuiNode(fqn + SEP + child_name);
            }
  @@ -538,9 +568,11 @@
         String tmp_name;
   
         if (path == null) return null;
  -      for (int i = 0; i < path.length; i++) {
  +      for (int i = 0; i < path.length; i++)
  +      {
            tmp_name = ((MyNode) path[i]).name;
  -         if (tmp_name.equals(SEP)) {
  +         if (tmp_name.equals(SEP))
  +         {
            }
            else
               sb.append(SEP + tmp_name);
  @@ -556,7 +588,8 @@
      {
         int num_rows = table.getRowCount();
   
  -      if (num_rows > 0) {
  +      if (num_rows > 0)
  +      {
            for (int i = 0; i < num_rows; i++)
               table_model.removeRow(0);
            table_model.fireTableRowsDeleted(0, num_rows - 1);
  @@ -576,8 +609,10 @@
         num_rows = data.size();
         clearTable();
   
  -      if (num_rows > 0) {
  -         for (Iterator it = data.entrySet().iterator(); it.hasNext();) {
  +      if (num_rows > 0)
  +      {
  +         for (Iterator it = data.entrySet().iterator(); it.hasNext();)
  +         {
               entry = (Map.Entry) it.next();
               key = (String) entry.getKey();
               val = entry.getValue();
  @@ -633,9 +668,12 @@
   
      Object getLocalAddress()
      {
  -      try {
  +      try
  +      {
            return cache_.getLocalAddress();
  -      } catch (Throwable t) {
  +      }
  +      catch (Throwable t)
  +      {
            log.error("TreeCacheAopGui.getLocalAddress(): " + t);
            return null;
         }
  @@ -659,7 +697,8 @@
         keys = getKeys(node.getFqn());
         if (keys == null) return null;
         data = new HashMap();
  -      for (Iterator it = keys.iterator(); it.hasNext();) {
  +      for (Iterator it = keys.iterator(); it.hasNext();)
  +      {
            key = it.next().toString();
            value = get(node.getFqn(), key);
            if (value != null)
  @@ -671,9 +710,12 @@
   
      void put(String fqn, Map m)
      {
  -      try {
  +      try
  +      {
            cache_.put(fqn, m);
  -      } catch (Throwable t) {
  +      }
  +      catch (Throwable t)
  +      {
            log.error("TreeCacheAopGui.put(): " + t);
         }
      }
  @@ -681,27 +723,36 @@
   
      private void put(String fqn, String key, Object value)
      {
  -      try {
  +      try
  +      {
            cache_.put(fqn, key, value);
  -      } catch (Throwable t) {
  +      }
  +      catch (Throwable t)
  +      {
            log.error("TreeCacheAopGui.put(): " + t);
         }
      }
   
      void _put(String fqn, String key, Object value)
      {
  -      try {
  +      try
  +      {
            cache_._put(null, fqn, key, value, false);
  -      } catch (Throwable t) {
  +      }
  +      catch (Throwable t)
  +      {
            log.error("TreeCacheAopGui._put(): " + t);
         }
      }
   
      Set getKeys(Fqn fqn)
      {
  -      try {
  +      try
  +      {
            return cache_.getKeys(fqn);
  -      } catch (Throwable t) {
  +      }
  +      catch (Throwable t)
  +      {
            t.printStackTrace();
            log.error("TreeCacheAopGui.getKeys(): " + t);
            return null;
  @@ -710,9 +761,12 @@
   
      Object get(Fqn fqn, String key)
      {
  -      try {
  +      try
  +      {
            return cache_.get(fqn, key);
  -      } catch (Throwable t) {
  +      }
  +      catch (Throwable t)
  +      {
            log.error("TreeCacheAopGui.get(): " + t);
            return null;
         }
  @@ -720,9 +774,12 @@
   
      Set getChildrenNames(String fqn)
      {
  -      try {
  +      try
  +      {
            return cache_.getChildrenNames(fqn);
  -      } catch (Throwable t) {
  +      }
  +      catch (Throwable t)
  +      {
            log.error("TreeCacheAopGui.getChildrenNames(): " + t);
            return null;
         }
  @@ -730,21 +787,24 @@
   
      Vector getMembers()
      {
  -      try {
  +      try
  +      {
            return cache_.getMembers();
  -      } catch (Throwable t) {
  +      }
  +      catch (Throwable t)
  +      {
            log.error("TreeCacheAopGui.getMembers(): " + t);
            return null;
         }
      }
   
  -
      /* -------------------------- End of Private Methods ------------------------------ */
   
      /*----------------------- Actions ---------------------------*/
      class ExitAction extends AbstractAction
      {
         private static final long serialVersionUID = 3309349735197545040L;
  +
         public void actionPerformed(ActionEvent e)
         {
            dispose();
  @@ -755,6 +815,7 @@
      class AddNodeAction extends AbstractAction
      {
         private static final long serialVersionUID = -1846726449742865362L;
  +
         public void actionPerformed(ActionEvent e)
         {
            JTextField fqnTextField = new JTextField();
  @@ -773,7 +834,8 @@
                  null,
                  options,
                  options[0]);
  -         if (userChoice == 0) {
  +         if (userChoice == 0)
  +         {
               String userInput = fqnTextField.getText();
               put(userInput, null);
            }
  @@ -784,6 +846,7 @@
      class PrintLockInfoAction extends AbstractAction
      {
         private static final long serialVersionUID = -1547808705937201967L;
  +
         public void actionPerformed(ActionEvent e)
         {
            System.out.println("\n*** lock information ****\n" + cache_.printLockInfo());
  @@ -793,6 +856,7 @@
      class ReleaseAllLocksAction extends AbstractAction
      {
         private static final long serialVersionUID = -856964838566617006L;
  +
         public void actionPerformed(ActionEvent e)
         {
            cache_.releaseAllLocks("/");
  @@ -802,11 +866,15 @@
      class RemoveNodeAction extends AbstractAction
      {
         private static final long serialVersionUID = 116863545772054467L;
  +
         public void actionPerformed(ActionEvent e)
         {
  -         try {
  +         try
  +         {
               cache_.remove(selected_node);
  -         } catch (Throwable t) {
  +         }
  +         catch (Throwable t)
  +         {
               log.error("RemoveNodeAction.actionPerformed(): " + t);
            }
         }
  @@ -815,11 +883,15 @@
      class AddModifyDataForNodeAction extends AbstractAction
      {
         private static final long serialVersionUID = 8035968024123769723L;
  +
         public void actionPerformed(ActionEvent e)
         {
            Map data = getData(selected_node);
  -         if (data != null) {
  -         } else {
  +         if (data != null)
  +         {
  +         }
  +         else
  +         {
               clearTable();
               data = new HashMap();
               data.put("Add Key", "Add Value");
  @@ -866,10 +938,12 @@
            tok = new StringTokenizer(fqnStr, TreeCacheAopGui.SEP);
   
            int i = 0;
  -         while (tok.hasMoreTokens()) {
  +         while (tok.hasMoreTokens())
  +         {
               child_name = tok.nextToken();
               n = curr.findChild(child_name);
  -            if (n == null) {
  +            if (n == null)
  +            {
                  n = new MyNode(child_name, fqn.getFqnChild(i + 1));
                  if (ret == null) ret = n;
                  curr.add(n);
  @@ -900,7 +974,8 @@
            curr = this;
            tok = new StringTokenizer(fqn, TreeCacheAopGui.SEP);
   
  -         while (tok.hasMoreTokens()) {
  +         while (tok.hasMoreTokens())
  +         {
               child_name = tok.nextToken();
               n = curr.findChild(child_name);
               if (n == null)
  @@ -917,9 +992,11 @@
   
            if (relative_name == null || getChildCount() == 0)
               return null;
  -         for (int i = 0; i < getChildCount(); i++) {
  +         for (int i = 0; i < getChildCount(); i++)
  +         {
               child = (MyNode) getChildAt(i);
  -            if (child.name == null) {
  +            if (child.name == null)
  +            {
                  continue;
               }
   
  @@ -936,15 +1013,18 @@
   
            for (int i = 0; i < indent; i++)
               sb.append(" ");
  -         if (!isRoot()) {
  +         if (!isRoot())
  +         {
               if (name == null)
                  sb.append("/<unnamed>");
  -            else {
  +            else
  +            {
                  sb.append(TreeCacheAopGui.SEP + name);
               }
            }
            sb.append("\n");
  -         if (getChildCount() > 0) {
  +         if (getChildCount() > 0)
  +         {
               if (isRoot())
                  indent = 0;
               else
  
  
  



More information about the jboss-cvs-commits mailing list