Author: chirino
Date: Sat Feb 18 14:49:07 2012
New Revision: 1245932

URL: http://svn.apache.org/viewvc?rev=1245932&view=rev
Log:
When delivering a message that is not tight, and cache encoded, then we can 
avoid re-encoding when we deliver it to a subscription.

Added:
    
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/CachedEncodingTrait.java
Modified:
    
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireCodec.scala
    
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/codec/OpenWireFormat.java
    
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/Message.java

Modified: 
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireCodec.scala
URL: 
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireCodec.scala?rev=1245932&r1=1245931&r2=1245932&view=diff
==============================================================================
--- 
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireCodec.scala
 (original)
+++ 
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireCodec.scala
 Sat Feb 18 14:49:07 2012
@@ -29,7 +29,7 @@ import org.apache.activemq.apollo.openwi
 import org.apache.activemq.apollo.broker.BufferConversions._
 import org.fusesource.hawtbuf.{DataByteArrayInputStream, 
DataByteArrayOutputStream, AbstractVarIntSupport, Buffer}
 
-case class CachedEncoding(tight:Boolean, version:Int, buffer:Buffer) 
+case class CachedEncoding(tight:Boolean, version:Int, buffer:Buffer) extends 
CachedEncodingTrait
 
 /**
  * <p>

Modified: 
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/codec/OpenWireFormat.java
URL: 
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/codec/OpenWireFormat.java?rev=1245932&r1=1245931&r2=1245932&view=diff
==============================================================================
--- 
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/codec/OpenWireFormat.java
 (original)
+++ 
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/codec/OpenWireFormat.java
 Sat Feb 18 14:49:07 2012
@@ -16,9 +16,7 @@
  */
 package org.apache.activemq.apollo.openwire.codec;
 
-import org.apache.activemq.apollo.openwire.command.CommandTypes;
-import org.apache.activemq.apollo.openwire.command.DataStructure;
-import org.apache.activemq.apollo.openwire.command.WireFormatInfo;
+import org.apache.activemq.apollo.openwire.command.*;
 import org.fusesource.hawtbuf.Buffer;
 import org.fusesource.hawtbuf.BufferEditor;
 import org.fusesource.hawtbuf.DataByteArrayInputStream;
@@ -490,6 +488,16 @@ public final class OpenWireFormat {
     public void looseMarshalNestedObject(DataStructure o, 
DataByteArrayOutputStream dataOut) throws IOException {
         dataOut.writeBoolean(o != null);
         if (o != null) {
+            if( o instanceof Message ) {
+                if( !isTightEncodingEnabled() && !isCacheEnabled() ) {
+                    CachedEncodingTrait encoding = ((Message) 
o).getCachedEncoding();
+                    if( encoding !=null && !encoding.tight() && 
encoding.version()==getVersion()) {
+                        Buffer buffer = encoding.buffer();
+                        dataOut.write(buffer.data, buffer.offset + 4, 
buffer.length() - 4);
+                        return;
+                    }
+                }
+            }
             byte type = o.getDataStructureType();
             dataOut.writeByte(type);
             DataStreamMarshaller dsm = (DataStreamMarshaller) 
dataMarshallers[type & 0xFF];

Added: 
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/CachedEncodingTrait.java
URL: 
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/CachedEncodingTrait.java?rev=1245932&view=auto
==============================================================================
--- 
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/CachedEncodingTrait.java
 (added)
+++ 
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/CachedEncodingTrait.java
 Sat Feb 18 14:49:07 2012
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.apollo.openwire.command;
+
+import org.fusesource.hawtbuf.Buffer;
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com";>Hiram Chirino</a>
+ */
+public interface CachedEncodingTrait {
+    boolean tight();
+    int version();
+    Buffer buffer();
+}

Modified: 
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/Message.java
URL: 
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/Message.java?rev=1245932&r1=1245931&r2=1245932&view=diff
==============================================================================
--- 
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/Message.java
 (original)
+++ 
activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/command/Message.java
 Sat Feb 18 14:49:07 2012
@@ -98,11 +98,11 @@ public abstract class Message extends Ba
         this.encodedSize = encodedSize;
     }
 
-    protected Object cachedEncoding;
-    public Object getCachedEncoding() {
+    protected CachedEncodingTrait cachedEncoding;
+    public CachedEncodingTrait getCachedEncoding() {
         return cachedEncoding;
     }
-    public void setCachedEncoding(Object cachedEncoding) {
+    public void setCachedEncoding(CachedEncodingTrait cachedEncoding) {
         this.cachedEncoding = cachedEncoding;
     }
 


Reply via email to