activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r467676 - in /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq: command/WireFormatInfo.java openwire/OpenWireFormat.java openwire/OpenWireFormatFactory.java
Date Wed, 25 Oct 2006 15:02:23 GMT
Author: chirino
Date: Wed Oct 25 08:02:22 2006
New Revision: 467676

URL: http://svn.apache.org/viewvc?view=rev&rev=467676
Log:
http://issues.apache.org/activemq/browse/AMQ-1001

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

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/WireFormatInfo.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/WireFormatInfo.java?view=diff&rev=467676&r1=467675&r2=467676
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/WireFormatInfo.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/WireFormatInfo.java
Wed Oct 25 08:02:22 2006
@@ -253,6 +253,18 @@
         setProperty("MaxInactivityDuration", new Long(maxInactivityDuration));
     }
 
+    /**
+     * @throws IOException 
+     */
+    public int getCacheSize() throws IOException {
+        Integer i = (Integer) getProperty("CacheSize");
+        return i == null ? 0 : i.intValue();
+    }
+    public void setCacheSize(int cacheSize) throws IOException {
+        setProperty("CacheSize", new Integer(cacheSize));
+    }
+    
+    
     public Response visit(CommandVisitor visitor) throws Exception {
         return visitor.processWireFormat(this);
     }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java?view=diff&rev=467676&r1=467675&r2=467676
==============================================================================
--- 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
Wed Oct 25 08:02:22 2006
@@ -43,7 +43,7 @@
     
     static final byte NULL_TYPE = CommandTypes.NULL;
     private static final int MARSHAL_CACHE_SIZE = Short.MAX_VALUE/2;
-    private static final int MARSHAL_CACHE_PREFERED_SIZE = MARSHAL_CACHE_SIZE-100;
+    private static final int MARSHAL_CACHE_FREE_SPACE = 100;
     
     private DataStreamMarshaller dataMarshallers[];
     private int version = 2;
@@ -53,12 +53,13 @@
     private boolean tightEncodingEnabled=false;
     private boolean sizePrefixDisabled=false;
 
-    private HashMap marshallCacheMap = new HashMap();
+    // The following fields are used for value caching
     private short nextMarshallCacheIndex=0;    
-    private short nextMarshallCacheEvictionIndex=0;
+    private short nextMarshallCacheEvictionIndex=0;    
+    private HashMap marshallCacheMap = new HashMap();
+    private DataStructure marshallCache[];
+    private DataStructure unmarshallCache[];
     
-    private DataStructure marshallCache[] = new DataStructure[MARSHAL_CACHE_SIZE];
-    private DataStructure unmarshallCache[] = new DataStructure[MARSHAL_CACHE_SIZE];
 	private WireFormatInfo preferedWireFormatInfo;
             
 	public OpenWireFormat() {
@@ -466,13 +467,13 @@
 
     public void runMarshallCacheEvictionSweep() {
         // Do we need to start evicting??
-        while( marshallCacheMap.size() > MARSHAL_CACHE_PREFERED_SIZE ) {
+        while( marshallCacheMap.size() > marshallCache.length - MARSHAL_CACHE_FREE_SPACE
) {
             
             marshallCacheMap.remove(marshallCache[nextMarshallCacheEvictionIndex]);
             marshallCache[nextMarshallCacheEvictionIndex]=null;
 
             nextMarshallCacheEvictionIndex++;
-            if( nextMarshallCacheEvictionIndex >= MARSHAL_CACHE_SIZE ) {
+            if( nextMarshallCacheEvictionIndex >= marshallCache.length ) {
                 nextMarshallCacheEvictionIndex=0;
             }
             
@@ -485,12 +486,12 @@
     
     public Short addToMarshallCache(DataStructure o) {
         short i = nextMarshallCacheIndex++;
-        if( nextMarshallCacheIndex >= MARSHAL_CACHE_SIZE ) {
+        if( nextMarshallCacheIndex >= marshallCache.length ) {
             nextMarshallCacheIndex=0;
         }
         
         // We can only cache that item if there is space left.
-        if( marshallCacheMap.size() < MARSHAL_CACHE_SIZE ) {
+        if( marshallCacheMap.size() < marshallCache.length ) {
             marshallCache[i] = o;
             Short index = new Short(i);
             marshallCacheMap.put(o, index);
@@ -571,6 +572,26 @@
 		this.cacheEnabled = info.isCacheEnabled() && preferedWireFormatInfo.isCacheEnabled();
 		this.tightEncodingEnabled = info.isTightEncodingEnabled() && preferedWireFormatInfo.isTightEncodingEnabled();
 		this.sizePrefixDisabled = info.isSizePrefixDisabled() && preferedWireFormatInfo.isSizePrefixDisabled();
+		
+		if( cacheEnabled ) {
+			
+			int size = Math.min(preferedWireFormatInfo.getCacheSize(), info.getCacheSize());
+			if( size == 0 ) {
+				size = MARSHAL_CACHE_SIZE;
+			}
+			
+		    marshallCache = new DataStructure[size];
+		    unmarshallCache = new DataStructure[size];			
+		    nextMarshallCacheIndex=0;    
+		    nextMarshallCacheEvictionIndex =0;
+		    marshallCacheMap = new HashMap();
+		} else {
+			marshallCache=null;
+			unmarshallCache=null;
+		    nextMarshallCacheIndex=0;    
+		    nextMarshallCacheEvictionIndex=0;    
+		    marshallCacheMap = null;
+		}
 		
 	}
 

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java?view=diff&rev=467676&r1=467675&r2=467676
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java
Wed Oct 25 08:02:22 2006
@@ -37,6 +37,7 @@
     private boolean tightEncodingEnabled=true;
     private boolean sizePrefixDisabled=false;
     private long maxInactivityDuration=30*1000;
+    private int cacheSize=1024;
     
     public WireFormat createWireFormat() {
 		WireFormatInfo info = new WireFormatInfo();
@@ -49,6 +50,7 @@
 			info.setTightEncodingEnabled(tightEncodingEnabled);
 			info.setSizePrefixDisabled(sizePrefixDisabled);
             info.seMaxInactivityDuration(maxInactivityDuration);
+            info.setCacheSize(cacheSize);
 		} catch (Exception e) {
 			IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo");
             ise.initCause(e);
@@ -115,4 +117,12 @@
     public void setMaxInactivityDuration(long maxInactivityDuration) {
         this.maxInactivityDuration = maxInactivityDuration;
     }
+
+	public int getCacheSize() {
+		return cacheSize;
+	}
+
+	public void setCacheSize(int cacheSize) {
+		this.cacheSize = cacheSize;
+	}
 }



Mime
View raw message