Author: rgodfrey
Date: Thu Oct 18 16:35:17 2012
New Revision: 1399729

URL: http://svn.apache.org/viewvc?rev=1399729&view=rev
Log:
PROTON-87 : Pluggable tracing for proton-j

Added:
    
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/ProtocolTracer.java
Modified:
    
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
    
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/type/Binary.java

Added: 
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/ProtocolTracer.java
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/ProtocolTracer.java?rev=1399729&view=auto
==============================================================================
--- 
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/ProtocolTracer.java
 (added)
+++ 
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/ProtocolTracer.java
 Thu Oct 18 16:35:17 2012
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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.qpid.proton.engine.impl;
+
+import org.apache.qpid.proton.framing.TransportFrame;
+import org.apache.qpid.proton.type.Binary;
+import org.apache.qpid.proton.type.DescribedType;
+import org.apache.qpid.proton.type.transport.FrameBody;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author <a href="http://hiramchirino.com";>Hiram Chirino</a>
+ */
+public interface ProtocolTracer 
+{
+    public void receivedFrame(TransportFrame transportFrame);
+    public void sentFrame(TransportFrame transportFrame);
+}

Modified: 
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java?rev=1399729&r1=1399728&r2=1399729&view=diff
==============================================================================
--- 
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
 (original)
+++ 
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java
 Thu Oct 18 16:35:17 2012
@@ -95,7 +95,7 @@ public class TransportImpl extends Endpo
     private Open _open;
     private SaslImpl _sasl;
     private TransportException _inputException;
-
+    private ProtocolTracer _protocolTracer = null;
 
     {
         AMQPDefinedTypes.registerAllTypes(_decoder);
@@ -839,6 +839,16 @@ public class TransportImpl extends Endpo
                            ByteBuffer payload,
                            Runnable onPayloadTooLarge)
     {
+        if( _protocolTracer!=null ) 
+        {
+            ByteBuffer originalPayload = null;
+            if( payload!=null ) 
+            {
+                originalPayload = payload.duplicate();
+            }
+            _protocolTracer.sentFrame(new TransportFrame(channel, (FrameBody) 
frameBody, Binary.create(originalPayload)));
+        }
+
         int oldPosition = buffer.position();
         buffer.position(buffer.position()+8);
         _encoder.setByteBuffer(buffer);
@@ -1094,6 +1104,10 @@ public class TransportImpl extends Endpo
 
     public boolean input(TransportFrame frame)
     {
+        if( _protocolTracer!=null ) 
+        {
+            _protocolTracer.receivedFrame(frame);
+        }
         if(_connectionEndpoint != null || getRemoteState() == 
EndpointState.UNINITIALIZED)
         {
             frame.getBody().invoke(this,frame.getPayload(), 
frame.getChannel());
@@ -1120,4 +1134,13 @@ public class TransportImpl extends Endpo
         }
     }
 
-   }
+    public ProtocolTracer getProtocolTracer() 
+    {
+        return _protocolTracer;
+    }
+
+    public void setProtocolTracer(ProtocolTracer protocolTracer) 
+    {
+        this._protocolTracer = protocolTracer;
+    }
+}

Modified: 
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/type/Binary.java
URL: 
http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/type/Binary.java?rev=1399729&r1=1399728&r2=1399729&view=diff
==============================================================================
--- 
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/type/Binary.java
 (original)
+++ 
qpid/proton/trunk/proton-j/src/main/java/org/apache/qpid/proton/type/Binary.java
 Thu Oct 18 16:35:17 2012
@@ -160,4 +160,21 @@ public class Binary
     {
         return new Binary(_data, _offset+offset, length);
     }
+
+    public static Binary create(ByteBuffer buffer) 
+    {
+        if( buffer == null )
+            return null;
+        if( buffer.isDirect() ) 
+        {
+            byte data[] = new byte [buffer.remaining()];
+            ByteBuffer dup = buffer.duplicate();
+            dup.get(data);
+            return new Binary(data);
+        }
+        else 
+        {
+            return new Binary(buffer.array(), 
buffer.arrayOffset()+buffer.position(), buffer.remaining());
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to