Return-Path: Delivered-To: apmail-geronimo-activemq-commits-archive@www.apache.org Received: (qmail 16202 invoked from network); 6 Mar 2006 14:07:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Mar 2006 14:07:07 -0000 Received: (qmail 72824 invoked by uid 500); 6 Mar 2006 14:07:51 -0000 Delivered-To: apmail-geronimo-activemq-commits-archive@geronimo.apache.org Received: (qmail 72773 invoked by uid 500); 6 Mar 2006 14:07:50 -0000 Mailing-List: contact activemq-commits-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-commits@geronimo.apache.org Received: (qmail 72748 invoked by uid 99); 6 Mar 2006 14:07:50 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Mar 2006 06:07:50 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 06 Mar 2006 06:07:47 -0800 Received: (qmail 15914 invoked by uid 65534); 6 Mar 2006 14:06:28 -0000 Message-ID: <20060306140628.15843.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r383544 - in /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire: OpenWireFormat.java OpenWireFormatFactory.java Date: Mon, 06 Mar 2006 14:06:15 -0000 To: activemq-commits@geronimo.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: chirino Date: Mon Mar 6 06:06:13 2006 New Revision: 383544 URL: http://svn.apache.org/viewcvs?rev=383544&view=rev Log: Better cache eviction in place. Modified: 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/openwire/OpenWireFormat.java URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java?rev=383544&r1=383543&r2=383544&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:06:13 2006 @@ -42,6 +42,8 @@ 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 DataStreamMarshaller dataMarshallers[]; private int version; private boolean stackTraceEnabled=true; @@ -52,7 +54,8 @@ private HashMap marshallCacheMap = new HashMap(); private short nextMarshallCacheIndex=0; - private short lasMarshallCacheEvictionIndex=100; + private short nextMarshallCacheEvictionIndex=0; + private DataStructure marshallCache[] = new DataStructure[MARSHAL_CACHE_SIZE]; private DataStructure unmarshallCache[] = new DataStructure[MARSHAL_CACHE_SIZE]; @@ -92,6 +95,10 @@ public Packet marshal(Object command) throws IOException { + if( cacheEnabled ) { + runMarshallCacheEvictionSweep(); + } + MarshallAware ma=null; // If not using value caching, then the marshaled form is always the same if( !cacheEnabled && ((DataStructure)command).isMarshallAware() ) { @@ -187,6 +194,11 @@ } public void marshal(Object o, DataOutputStream ds) throws IOException { + + if( cacheEnabled ) { + runMarshallCacheEvictionSweep(); + } + int size=1; if( o != null) { DataStructure c = (DataStructure) o; @@ -202,7 +214,7 @@ ds.writeInt(size); ds.writeByte(type); bs.marshal(ds); - dsm.tightMarshal2(this, c, ds, bs); + dsm.tightMarshal2(this, c, ds, bs); } else { ds.writeInt(size); ds.writeByte(NULL_TYPE); @@ -359,26 +371,33 @@ } } + public void runMarshallCacheEvictionSweep() { + // Do we need to start evicting?? + while( marshallCacheMap.size() > MARSHAL_CACHE_PREFERED_SIZE ) { + + marshallCacheMap.remove(marshallCache[nextMarshallCacheEvictionIndex]); + marshallCache[nextMarshallCacheEvictionIndex]=null; + + nextMarshallCacheEvictionIndex++; + if( nextMarshallCacheEvictionIndex >= MARSHAL_CACHE_SIZE ) { + nextMarshallCacheEvictionIndex=0; + } + + } + } - public Short getMarshallCacheIndex(Object o) { + public Short getMarshallCacheIndex(DataStructure o) { return (Short) marshallCacheMap.get(o); } - public Short addToMarshallCache(Object o) { - nextMarshallCacheIndex++; + public Short addToMarshallCache(DataStructure o) { + short i = nextMarshallCacheIndex++; if( nextMarshallCacheIndex >= MARSHAL_CACHE_SIZE ) { nextMarshallCacheIndex=0; } - lasMarshallCacheEvictionIndex++; - if( lasMarshallCacheEvictionIndex >= MARSHAL_CACHE_SIZE ) { - lasMarshallCacheEvictionIndex=0; - } - if( marshallCache[lasMarshallCacheEvictionIndex]!=null ) { - marshallCacheMap.remove(marshallCache[lasMarshallCacheEvictionIndex]); - marshallCache[lasMarshallCacheEvictionIndex]=null; - } - marshallCache[nextMarshallCacheIndex] = (DataStructure) o; - Short index = new Short(nextMarshallCacheIndex); + + marshallCache[i] = o; + Short index = new Short(i); marshallCacheMap.put(o, index); return index; } Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java?rev=383544&r1=383543&r2=383544&view=diff ============================================================================== --- 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 Mon Mar 6 06:06:13 2006 @@ -28,6 +28,8 @@ private boolean stackTraceEnabled=true; private boolean tcpNoDelayEnabled=false; private boolean cacheEnabled=true; + private boolean tightEncodingEnabled=true; + private boolean prefixPacketSize=true; public WireFormat createWireFormat() { OpenWireFormat format = new OpenWireFormat(); @@ -35,6 +37,8 @@ format.setStackTraceEnabled(stackTraceEnabled); format.setCacheEnabled(cacheEnabled); format.setTcpNoDelayEnabled(tcpNoDelayEnabled); + format.setTightEncodingEnabled(tightEncodingEnabled); + format.setPrefixPacketSize(prefixPacketSize); return format; } @@ -68,5 +72,21 @@ public void setCacheEnabled(boolean cacheEnabled) { this.cacheEnabled = cacheEnabled; + } + + public boolean isTightEncodingEnabled() { + return tightEncodingEnabled; + } + + public void setTightEncodingEnabled(boolean tightEncodingEnabled) { + this.tightEncodingEnabled = tightEncodingEnabled; + } + + public boolean isPrefixPacketSize() { + return prefixPacketSize; + } + + public void setPrefixPacketSize(boolean prefixPacketSize) { + this.prefixPacketSize = prefixPacketSize; } }