[jbosscache-commits] JBoss Cache SVN: r4923 - in core/trunk/src: main/java/org/jboss/cache/config and 2 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Dec 28 08:38:10 EST 2007


Author: manik.surtani at jboss.com
Date: 2007-12-28 08:38:10 -0500 (Fri, 28 Dec 2007)
New Revision: 4923

Modified:
   core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
   core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java
   core/trunk/src/main/java/org/jboss/cache/notifications/event/EventImpl.java
   core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java
Log:
Better cache impl logging and more accurate cloning of runtime configs

Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2007-12-28 12:17:28 UTC (rev 4922)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2007-12-28 13:38:10 UTC (rev 4923)
@@ -681,6 +681,8 @@
                {
                   long start = System.currentTimeMillis();
                   channel.connect(configuration.getClusterName(), null, null, configuration.getStateRetrievalTimeout());
+                  // reconfigure log category so that the instance name is reflected as well.
+                  configureLogCategory();
                   //if I am not the only and the first member than wait for a state to arrive
                   if (getMembers().size() > 1)
                   {
@@ -716,6 +718,8 @@
                try
                {
                   channel.connect(configuration.getClusterName());
+                  // reconfigure log category so that the instance name is reflected as well.
+                  configureLogCategory();
                }
                catch (ChannelException e)
                {
@@ -3133,7 +3137,7 @@
     */
    private void configureLogCategory()
    {
-      StringBuffer category = new StringBuffer(getClass().getName());
+      StringBuilder category = new StringBuilder(getClass().getSimpleName());
       if (configuration != null)
       {
          String clusterName = configuration.getClusterName();
@@ -3141,10 +3145,15 @@
          {
             category.append('.');
             category.append(clusterName);
+            if (channel != null && channel.getLocalAddress() != null)
+            {
+               category.append('.');
+               category.append(channel.getLocalAddress());
+            }
          }
       }
-
-      log = LogFactory.getLog(category.toString());
+      // replace .s with _s otherwise Log4J will strip them out
+      log = LogFactory.getLog(category.toString().replace('.', '_'));
    }
 
    /**

Modified: core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java	2007-12-28 12:17:28 UTC (rev 4922)
+++ core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java	2007-12-28 13:38:10 UTC (rev 4923)
@@ -36,6 +36,7 @@
       // only reset the node factory and channel for now.
       nodeFactory = null;
       channel = null;
+      rpcManager = null;
    }
 
 

Modified: core/trunk/src/main/java/org/jboss/cache/notifications/event/EventImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/event/EventImpl.java	2007-12-28 12:17:28 UTC (rev 4922)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/event/EventImpl.java	2007-12-28 13:38:10 UTC (rev 4923)
@@ -14,9 +14,9 @@
  * @since 2.0.0
  */
 public class EventImpl implements CacheBlockedEvent, CacheUnblockedEvent, CacheStartedEvent, CacheStoppedEvent,
-        NodeActivatedEvent, NodeCreatedEvent, NodeEvictedEvent, NodeLoadedEvent, NodeModifiedEvent, NodeMovedEvent,
-        NodePassivatedEvent, NodeRemovedEvent, NodeVisitedEvent, TransactionCompletedEvent, TransactionRegisteredEvent,
-        ViewChangedEvent
+      NodeActivatedEvent, NodeCreatedEvent, NodeEvictedEvent, NodeLoadedEvent, NodeModifiedEvent, NodeMovedEvent,
+      NodePassivatedEvent, NodeRemovedEvent, NodeVisitedEvent, TransactionCompletedEvent, TransactionRegisteredEvent,
+      ViewChangedEvent
 {
    private boolean pre = false; // by default events are after the fact
    private Cache cache;
@@ -206,18 +206,18 @@
    public String toString()
    {
       return "EventImpl{" +
-              "pre=" + pre +
-              ", cache=" + cache +
-              ", modificationType=" + modificationType +
-              ", data=" + data +
-              ", fqn=" + fqn +
-              ", transaction=" + transaction +
-              ", originLocal=" + originLocal +
-              ", targetFqn=" + targetFqn +
-              ", successful=" + successful +
-              ", newView=" + newView +
-              ", type=" + type +
-              '}';
+            "type=" + type +
+            ",pre=" + pre +
+            ", cache=" + cache +
+            ", modificationType=" + modificationType +
+            ", data=" + data +
+            ", fqn=" + fqn +
+            ", transaction=" + transaction +
+            ", originLocal=" + originLocal +
+            ", targetFqn=" + targetFqn +
+            ", successful=" + successful +
+            ", newView=" + newView +
+            '}';
    }
 
 }

Modified: core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java	2007-12-28 12:17:28 UTC (rev 4922)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java	2007-12-28 13:38:10 UTC (rev 4923)
@@ -24,10 +24,12 @@
 
 import org.jboss.cache.Cache;
 import org.jboss.cache.CacheFactory;
+import org.jboss.cache.CacheSPI;
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Node;
 import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.ComponentRegistry;
 import org.jboss.cache.lock.IsolationLevel;
 import org.jboss.cache.misc.TestingUtil;
 import org.jboss.cache.notifications.event.Event;
@@ -99,40 +101,28 @@
    @AfterMethod(alwaysRun = true)
    public void tearDown() throws Exception
    {
-      TransactionManager tm;
-      if ((tm = cache1.getConfiguration().getRuntimeConfig().getTransactionManager()) != null)
-      {
-         if (tm.getTransaction() != null)
-         {
-            try
-            {
-               tm.rollback();
-            }
-            catch (Exception e)
-            {
-               // do nothing
-            }
-         }
-      }
-      if ((tm = cache2.getConfiguration().getRuntimeConfig().getTransactionManager()) != null)
-      {
-         if (tm.getTransaction() != null)
-         {
-            try
-            {
-               tm.rollback();
-            }
-            catch (Exception e)
-            {
-               // do nothing
-            }
-         }
-      }
+      TestingUtil.killCaches(cache1, cache2);
+   }
 
-      cache1.stop();
-      cache1.destroy();
-      cache2.stop();
-      cache2.destroy();
+   /**
+    * Make sure the 2 caches have different component instances
+    */
+   public void testSeparateNotifiersAndListeners()
+   {
+      assert cache1 != cache2;
+      ComponentRegistry cr1, cr2;
+      cr1 = TestingUtil.extractComponentRegistry(cache1);
+      cr2 = TestingUtil.extractComponentRegistry(cache2);
+      assert cr1 != cr2;
+      assert cr1.getComponent(Notifier.class) != cr2.getComponent(Notifier.class);
+      assert eventLog1 != eventLog2;
+      assert cache1.getLocalAddress() != cache2.getLocalAddress();
+      CacheSPI spi1, spi2;
+      spi1 = (CacheSPI) cache1;
+      spi2 = (CacheSPI) cache2;
+
+      assert spi1.getRPCManager() != spi2.getRPCManager();
+      assert TestingUtil.extractField(spi1.getRPCManager(), "c") != TestingUtil.extractField(spi2.getRPCManager(), "c");
    }
 
    // simple tests first




More information about the jbosscache-commits mailing list