[jbosscache-commits] JBoss Cache SVN: r5675 - in core/trunk/src/main/java/org/jboss/cache: notifications and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Apr 24 12:16:46 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-04-24 12:16:46 -0400 (Thu, 24 Apr 2008)
New Revision: 5675

Modified:
   core/trunk/src/main/java/org/jboss/cache/commands/cachedata/PutDataMapCommand.java
   core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
Log:
Fixed notifications

Modified: core/trunk/src/main/java/org/jboss/cache/commands/cachedata/PutDataMapCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/cachedata/PutDataMapCommand.java	2008-04-24 16:00:12 UTC (rev 5674)
+++ core/trunk/src/main/java/org/jboss/cache/commands/cachedata/PutDataMapCommand.java	2008-04-24 16:16:46 UTC (rev 5675)
@@ -13,6 +13,7 @@
 import org.jboss.cache.optimistic.DataVersion;
 import org.jboss.cache.transaction.GlobalTransaction;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -68,7 +69,7 @@
       {
          oldData = new HashMap(dataDirect); // defensive copy
       }
-      notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_MAP, oldData, ctx);
+      notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_MAP, oldData == null ? Collections.emptyMap() : oldData, ctx);
 
       if (eraseContents) nodeSPI.clearDataDirect();
 

Modified: core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java	2008-04-24 16:00:12 UTC (rev 5674)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java	2008-04-24 16:16:46 UTC (rev 5675)
@@ -14,8 +14,10 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.InvocationContext;
 import org.jboss.cache.buddyreplication.BuddyGroup;
+import org.jboss.cache.config.Configuration;
 import org.jboss.cache.factories.annotations.Destroy;
 import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
 import org.jboss.cache.marshall.MarshalledValueMap;
 import org.jboss.cache.notifications.annotation.*;
 import org.jboss.cache.notifications.event.*;
@@ -61,6 +63,8 @@
 
    final Map<Class, List<ListenerInvocation>> listenerInvocations = new ConcurrentHashMap<Class, List<ListenerInvocation>>();
    private Cache cache;
+   private boolean useMarshalledValueMaps;
+   private Configuration config;
 
    public Notifier()
    {
@@ -72,9 +76,10 @@
    }
 
    @Inject
-   private void injectDependencies(CacheSPI cache)
+   private void injectDependencies(CacheSPI cache, Configuration config)
    {
       this.cache = cache;
+      this.config = config;
    }
 
    @Destroy
@@ -83,6 +88,12 @@
       listenerInvocations.clear();
    }
 
+   @Start
+   protected void start()
+   {
+      useMarshalledValueMaps = config.isUseLazyDeserialization();
+   }
+
    /**
     * Loops through all valid methods on the object passed in, and caches the relevant methods as {@link org.jboss.cache.notifications.Notifier.ListenerInvocation}
     * for invocation by reflection.
@@ -260,7 +271,7 @@
       if (listeners != null && !listeners.isEmpty())
       {
          boolean originLocal = ctx.isOriginLocal();
-         Map dataCopy = copy(data);
+         Map dataCopy = copy(data, useMarshalledValueMaps);
          Transaction tx = ctx.getTransaction();
          InvocationContext backup = resetInvocationContext(ctx);
          EventImpl e = new EventImpl();
@@ -292,7 +303,7 @@
       if (listeners != null && !listeners.isEmpty())
       {
          boolean originLocal = ctx.isOriginLocal();
-         Map dataCopy = copy(data);
+         Map dataCopy = copy(data, useMarshalledValueMaps);
          Transaction tx = ctx.getTransaction();
          InvocationContext backup = resetInvocationContext(ctx);
          EventImpl e = new EventImpl();
@@ -400,7 +411,7 @@
       if (listeners != null && !listeners.isEmpty())
       {
          boolean originLocal = ctx.isOriginLocal();
-         Map dataCopy = copy(data);
+         Map dataCopy = copy(data, useMarshalledValueMaps);
          Transaction tx = ctx.getTransaction();
          InvocationContext backup = resetInvocationContext(ctx);
          EventImpl e = new EventImpl();
@@ -431,7 +442,7 @@
       if (listeners != null && !listeners.isEmpty())
       {
          boolean originLocal = ctx.isOriginLocal();
-         Map dataCopy = copy(data);
+         Map dataCopy = copy(data, useMarshalledValueMaps);
          Transaction tx = ctx.getTransaction();
          InvocationContext backup = resetInvocationContext(ctx);
          EventImpl e = new EventImpl();
@@ -461,7 +472,7 @@
 
       if (listeners != null && !listeners.isEmpty())
       {
-         Map dataCopy = copy(data);
+         Map dataCopy = copy(data, useMarshalledValueMaps);
          Transaction tx = ctx.getTransaction();
          InvocationContext backup = resetInvocationContext(ctx);
          EventImpl e = new EventImpl();
@@ -631,13 +642,13 @@
       }
    }
 
-
-   private static Map copy(Map data)
+   private static Map copy(Map data, boolean useMarshalledValueMaps)
    {
       if (data == null) return null;
       if (data.isEmpty()) return Collections.emptyMap();
-      if (safe(data)) return new MarshalledValueMap(data);
-      return new MarshalledValueMap(new MapCopy(data));
+      if (safe(data)) return useMarshalledValueMaps ? new MarshalledValueMap(data) : data;
+      Map defensivelyCopiedData = new MapCopy(data);
+      return useMarshalledValueMaps ? new MarshalledValueMap(defensivelyCopiedData) : defensivelyCopiedData;
    }
 
    private void restoreInvocationContext(InvocationContext backup)




More information about the jbosscache-commits mailing list