You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2006/03/06 15:26:00 UTC

svn commit: r383546 - /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java

Author: chirino
Date: Mon Mar  6 06:25:36 2006
New Revision: 383546

URL: http://svn.apache.org/viewcvs?rev=383546&view=rev
Log:
Protect against cache overwrites.

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java?rev=383546&r1=383545&r2=383546&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java Mon Mar  6 06:25:36 2006
@@ -400,13 +400,25 @@
             nextMarshallCacheIndex=0;
         }
         
-        marshallCache[i] = o;
-        Short index = new Short(i);
-        marshallCacheMap.put(o, index);
-        return index;
+        // We can only cache that item if there is space left.
+        if( marshallCacheMap.size() < MARSHAL_CACHE_SIZE ) {
+            marshallCache[i] = o;
+            Short index = new Short(i);
+            marshallCacheMap.put(o, index);
+            return index;
+        } else {
+            // Use -1 to indicate that the value was not cached due to cache being full.
+            return new Short((short)-1);
+        }
     }
     
     public void setInUnmarshallCache(short index, DataStructure o) {
+        
+        // There was no space left in the cache, so we can't
+        // put this in the cache.
+        if( index == -1 )
+            return;
+        
         unmarshallCache[index]=o;
     }