You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2011/08/14 19:15:08 UTC

svn commit: r1157566 [20/23] - in /qpid: branches/rg-amqp-1-0-sandbox/qpid/java/ branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/ branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/src/ branches/rg-amqp-1-0-sandbox/qpid/java/amqp-1-0-client/...

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java?rev=1157566&r1=1157565&r2=1157566&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/QueueConfiguration.java Sun Aug 14 17:14:51 2011
@@ -167,6 +167,11 @@ public class QueueConfiguration extends 
         return getStringValue("lvqKey", null);
     }
 
+    public boolean isTopic()
+    {
+        return getBooleanValue("topic");
+    }
+
 
     public static class QueueConfig extends ConfigurationPlugin
     {

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/AMQMessage.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/AMQMessage.java?rev=1157566&r1=1157565&r2=1157566&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/AMQMessage.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/AMQMessage.java Sun Aug 14 17:14:51 2011
@@ -37,7 +37,7 @@ import java.nio.ByteBuffer;
 /**
  * A deliverable message.
  */
-public class AMQMessage implements ServerMessage
+public class AMQMessage implements ServerMessage<AMQMessage>
 {
     /** Used for debugging purposes. */
     private static final Logger _log = Logger.getLogger(AMQMessage.class);
@@ -73,7 +73,7 @@ public class AMQMessage implements Serve
     {
         this(handle, null);
     }
-    
+
     public AMQMessage(StoredMessage<MessageMetaData> handle, WeakReference<AMQChannel> channelRef)
     {
         _handle = handle;
@@ -85,7 +85,7 @@ public class AMQMessage implements Serve
         {
             _flags |= IMMEDIATE;
         }
-        
+
         _channelRef = channelRef;
     }
 
@@ -294,7 +294,7 @@ public class AMQMessage implements Serve
         return _expiration;
     }
 
-    public MessageReference newReference()
+    public AMQMessageReference newReference()
     {
         return new AMQMessageReference(this);
     }

Copied: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData_1_0.java (from r1073293, qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData_0_10.java)
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData_1_0.java?p2=qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData_1_0.java&p1=qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData_0_10.java&r1=1073293&r2=1157566&rev=1157566&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData_0_10.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageMetaData_1_0.java Sun Aug 14 17:14:51 2011
@@ -20,119 +20,273 @@
 */
 package org.apache.qpid.server.message;
 
-import org.apache.qpid.server.store.StorableMessageMetaData;
+import org.apache.qpid.amqp_1_0.codec.ValueHandler;
+import org.apache.qpid.amqp_1_0.messaging.SectionDecoder;
+import org.apache.qpid.amqp_1_0.type.AmqpErrorException;
+import org.apache.qpid.amqp_1_0.type.Binary;
+import org.apache.qpid.amqp_1_0.type.Section;
+import org.apache.qpid.amqp_1_0.type.Symbol;
+import org.apache.qpid.amqp_1_0.type.UnsignedInteger;
+import org.apache.qpid.amqp_1_0.type.codec.AMQPDescribedTypeRegistry;
+import org.apache.qpid.amqp_1_0.type.messaging.*;
+
+
+import org.apache.qpid.amqp_1_0.type.messaging.Properties;
+import org.apache.qpid.configuration.Validator;
 import org.apache.qpid.server.store.MessageMetaDataType;
-import org.apache.qpid.transport.MessageTransfer;
-import org.apache.qpid.transport.DeliveryProperties;
-import org.apache.qpid.transport.MessageProperties;
-import org.apache.qpid.transport.Header;
-import org.apache.qpid.transport.MessageDeliveryMode;
-import org.apache.qpid.transport.Struct;
-import org.apache.qpid.transport.codec.BBEncoder;
-import org.apache.qpid.transport.codec.BBDecoder;
+import org.apache.qpid.server.store.StorableMessageMetaData;
 
 import java.nio.ByteBuffer;
-import java.lang.ref.SoftReference;
+import java.util.*;
 
-public class MessageMetaData_0_10 implements StorableMessageMetaData
+public class MessageMetaData_1_0 implements StorableMessageMetaData
 {
-    private Header _header;
-    private DeliveryProperties _deliveryProps;
-    private MessageProperties _messageProps;
-    private MessageTransferHeader _messageHeader;
-    private long _arrivalTime;
-    private int _bodySize;
-    private volatile SoftReference<ByteBuffer> _body;
+    // TODO move to somewhere more useful
+    public static final Symbol JMS_TYPE = Symbol.valueOf("x-jms-type");
 
-    private static final int ENCODER_SIZE = 1 << 16;
 
-    public static final MessageMetaDataType.Factory<MessageMetaData_0_10> FACTORY = new MetaDataFactory();
+    private Header _header;
+    private Properties _properties;
+    private Map _deliveryAnnotations;
+    private Map _messageAnnotations;
+    private Map _appProperties;
+    private Map _footer;
+
+    private List<ByteBuffer> _encodedSections = new ArrayList<ByteBuffer>(3);
 
     private volatile ByteBuffer _encoded;
+    private MessageHeader_1_0 _messageHeader;
+
 
 
-    public MessageMetaData_0_10(MessageTransfer xfr)
+    public MessageMetaData_1_0(ByteBuffer[] fragments, SectionDecoder decoder)
     {
-        this(xfr.getHeader(), xfr.getBodySize(), xfr.getBody(), System.currentTimeMillis());
+        this(fragments, decoder, new ArrayList<ByteBuffer>(3));
     }
 
-    private MessageMetaData_0_10(Header header, int bodySize, long arrivalTime)
+    public MessageMetaData_1_0(ByteBuffer[] fragments, SectionDecoder decoder, List<ByteBuffer> immuatableSections)
     {
-        this(header, bodySize, null, arrivalTime);
+        this(constructSections(fragments, decoder,immuatableSections), immuatableSections);
     }
 
-    private MessageMetaData_0_10(Header header, int bodySize, ByteBuffer xfrBody, long arrivalTime)
+    private MessageMetaData_1_0(List<Section> sections, List<ByteBuffer> encodedSections)
     {
-        _header = header;
-        if(_header != null)
+        _encodedSections = encodedSections;
+
+        Iterator<Section> sectIter = sections.iterator();
+
+        Section section = sectIter.hasNext() ? sectIter.next() : null;
+        if(section instanceof Header)
         {
-            _deliveryProps = _header.get(DeliveryProperties.class);
-            _messageProps = _header.get(MessageProperties.class);
+            _header = (Header) section;
+            section = sectIter.hasNext() ? sectIter.next() : null;
         }
-        else
+
+        if(section instanceof DeliveryAnnotations)
         {
-            _deliveryProps = null;
-            _messageProps = null;
+            _deliveryAnnotations = ((DeliveryAnnotations) section).getValue();
+            section = sectIter.hasNext() ? sectIter.next() : null;
         }
-        _messageHeader = new MessageTransferHeader(_deliveryProps, _messageProps);
-        _arrivalTime = arrivalTime;
-        _bodySize = bodySize;
 
+        if(section instanceof MessageAnnotations)
+        {
+            _messageAnnotations = ((MessageAnnotations) section).getValue();
+            section = sectIter.hasNext() ? sectIter.next() : null;
+        }
 
+        if(section instanceof Properties)
+        {
+            _properties = (Properties) section;
+            section = sectIter.hasNext() ? sectIter.next() : null;
+        }
 
-        if(xfrBody == null)
+        if(section instanceof ApplicationProperties)
         {
-            _body = null;
+            _appProperties = ((ApplicationProperties) section).getValue();
+            section = sectIter.hasNext() ? sectIter.next() : null;
         }
-        else
+
+        if(section instanceof Footer)
         {
-            ByteBuffer body = ByteBuffer.allocate(_bodySize);
-            body.put(xfrBody);
-            body.flip();
-            _body = new SoftReference<ByteBuffer>(body);
+            _footer = ((Footer) section).getValue();
+            section = sectIter.hasNext() ? sectIter.next() : null;
         }
 
+        _messageHeader = new MessageHeader_1_0();
 
     }
 
+    private static List<Section> constructSections(final ByteBuffer[] fragments, final SectionDecoder decoder, List<ByteBuffer> encodedSections)
+    {
+        List<Section> sections = new ArrayList<Section>(3);
+
+        ByteBuffer src;
+        if(fragments.length == 1)
+        {
+            src = fragments[0].duplicate();
+        }
+        else
+        {
+            int size = 0;
+            for(ByteBuffer buf : fragments)
+            {
+                size += buf.remaining();
+            }
+            src = ByteBuffer.allocate(size);
+            for(ByteBuffer buf : fragments)
+            {
+                src.put(buf.duplicate());
+            }
+            src.flip();
+
+        }
+
+        try
+        {
+            int startBarePos = -1;
+            int lastPos = src.position();
+            Section s = decoder.readSection(src);
+
+
+
+            if(s instanceof Header)
+            {
+                sections.add(s);
+                lastPos = src.position();
+                s = src.hasRemaining() ? decoder.readSection(src) : null;
+            }
+
+            if(s instanceof DeliveryAnnotations)
+            {
+                sections.add(s);
+                lastPos = src.position();
+                s = src.hasRemaining() ? decoder.readSection(src) : null;
+            }
+
+            if(s instanceof MessageAnnotations)
+            {
+                sections.add(s);
+                lastPos = src.position();
+                s = src.hasRemaining() ? decoder.readSection(src) : null;
+            }
+
+            if(s instanceof Properties)
+            {
+                sections.add(s);
+                if(startBarePos == -1)
+                {
+                    startBarePos = lastPos;
+                }
+                s = src.hasRemaining() ? decoder.readSection(src) : null;
+            }
+
+            if(s instanceof ApplicationProperties)
+            {
+                sections.add(s);
+                if(startBarePos == -1)
+                {
+                    startBarePos = lastPos;
+                }
+                s = src.hasRemaining() ? decoder.readSection(src) : null;
+            }
+
+            if(s instanceof AmqpValue)
+            {
+                if(startBarePos == -1)
+                {
+                    startBarePos = lastPos;
+                }
+                s = src.hasRemaining() ? decoder.readSection(src) : null;
+            }
+            else if(s instanceof Data)
+            {
+                if(startBarePos == -1)
+                {
+                    startBarePos = lastPos;
+                }
+                do
+                {
+                    s = src.hasRemaining() ? decoder.readSection(src) : null;
+                } while(s instanceof Data);
+            }
+            else if(s instanceof AmqpSequence)
+            {
+                if(startBarePos == -1)
+                {
+                    startBarePos = lastPos;
+                }
+                do
+                {
+                    s = src.hasRemaining() ? decoder.readSection(src) : null;
+                }
+                while(s instanceof AmqpSequence);
+            }
+
+            if(s instanceof Footer)
+            {
+                sections.add(s);
+            }
+
+
+            int pos = 0;
+            for(ByteBuffer buf : fragments)
+            {
+/*
+                if(pos < startBarePos)
+                {
+                    if(pos + buf.remaining() > startBarePos)
+                    {
+                        ByteBuffer dup = buf.duplicate();
+                        dup.position(dup.position()+startBarePos-pos);
+                        dup.slice();
+                        encodedSections.add(dup);
+                    }
+                }
+                else
+*/
+                {
+                    encodedSections.add(buf.duplicate());
+                }
+                pos += buf.remaining();
+            }
+
+            return sections;
+        }
+        catch (AmqpErrorException e)
+        {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            throw new IllegalArgumentException(e);
+        }
+    }
 
 
     public MessageMetaDataType getType()
     {
-        return MessageMetaDataType.META_DATA_0_10;
+        return MessageMetaDataType.META_DATA_1_0;
     }
 
+
     public int getStorableSize()
     {
-        ByteBuffer buf = _encoded;
+        int size = 0;
 
-        if(buf == null)
+        for(ByteBuffer bin : _encodedSections)
         {
-            buf = encodeAsBuffer();
-            _encoded = buf;
+            size += bin.limit();
         }
 
-        //TODO -- need to add stuff
-        return buf.limit();
+        return size;
     }
 
     private ByteBuffer encodeAsBuffer()
     {
-        BBEncoder encoder = new BBEncoder(ENCODER_SIZE);
-
-        encoder.writeInt64(_arrivalTime);
-        encoder.writeInt32(_bodySize);
-        Struct[] headers = _header == null ? new Struct[0] : _header.getStructs();
-        encoder.writeInt32(headers.length);
+        ByteBuffer buf = ByteBuffer.allocate(getStorableSize());
 
-
-        for(Struct header : headers)
+        for(ByteBuffer bin : _encodedSections)
         {
-            encoder.writeStruct32(header);
-
+            buf.put(bin.duplicate());
         }
 
-        ByteBuffer buf = encoder.buffer();
         return buf;
     }
 
@@ -158,85 +312,190 @@ public class MessageMetaData_0_10 implem
         return buf.limit();
     }
 
-    public int getContentSize()
-    {
-        return _bodySize;
-    }
-
     public boolean isPersistent()
     {
-        return _deliveryProps == null ? false : _deliveryProps.getDeliveryMode() == MessageDeliveryMode.PERSISTENT;
+        return _header != null && Boolean.TRUE.equals(_header.getDurable());
     }
 
-    public String getRoutingKey()
-    {
-        return _deliveryProps == null ? null : _deliveryProps.getRoutingKey();
-    }
-
-    public AMQMessageHeader getMessageHeader()
+    public MessageHeader_1_0 getMessageHeader()
     {
         return _messageHeader;
     }
 
-    public long getSize()
-    {
+    public static final MessageMetaDataType.Factory<MessageMetaData_1_0> FACTORY = new MetaDataFactory();
 
-        return _bodySize;
-    }
 
-    public boolean isImmediate()
+    private static class MetaDataFactory implements MessageMetaDataType.Factory<MessageMetaData_1_0>
     {
-        return _deliveryProps != null && _deliveryProps.getImmediate();
-    }
+        private final AMQPDescribedTypeRegistry _typeRegistry = AMQPDescribedTypeRegistry.newInstance();
 
-    public long getExpiration()
-    {
-        return _deliveryProps == null ? 0L : _deliveryProps.getExpiration();
-    }
+        public MessageMetaData_1_0 createMetaData(ByteBuffer buf)
+        {
+            ValueHandler valueHandler = new ValueHandler(_typeRegistry);
 
-    public long getArrivalTime()
-    {
-        return _arrivalTime;
-    }
+            ArrayList<Section> sections = new ArrayList<Section>(3);
+            ArrayList<ByteBuffer> encodedSections = new ArrayList<ByteBuffer>(3);
 
-    public Header getHeader()
-    {
-        return _header;
-    }
+            while(buf.hasRemaining())
+            {
+                try
+                {
+                    ByteBuffer encodedBuf = buf.duplicate();
+                    sections.add((Section) valueHandler.parse(buf));
+                    encodedBuf.limit(buf.position());
+                    encodedSections.add(encodedBuf);
+
+                }
+                catch (AmqpErrorException e)
+                {
+                    //TODO
+                    throw new RuntimeException(e);
+                }
 
-    public ByteBuffer getBody()
-    {
-        ByteBuffer body = _body == null ? null : _body.get();
-        return body;
-    }
+            }
 
-    public void setBody(ByteBuffer body)
-    {
-        _body = new SoftReference<ByteBuffer>(body);
+            return new MessageMetaData_1_0(sections,encodedSections);
+
+        }
     }
 
-    private static class MetaDataFactory implements MessageMetaDataType.Factory<MessageMetaData_0_10>
+    public class MessageHeader_1_0 implements AMQMessageHeader
     {
-        public MessageMetaData_0_10 createMetaData(ByteBuffer buf)
+
+        public String getCorrelationId()
         {
-            BBDecoder decoder = new BBDecoder();
-            decoder.init(buf);
+            if(_properties == null || _properties.getCorrelationId() == null)
+            {
+                return null;
+            }
+            else
+            {
+                return _properties.getMessageId().toString();
+            }
+        }
 
-            long arrivalTime = decoder.readInt64();
-            int bodySize = decoder.readInt32();
-            int headerCount = decoder.readInt32();
+        public long getExpiration()
+        {
+            return 0;  //TODO
+        }
 
-            Struct[] headers = new Struct[headerCount];
+        public String getMessageId()
+        {
+            if(_properties == null || _properties.getCorrelationId() == null)
+            {
+                return null;
+            }
+            else
+            {
+                return _properties.getCorrelationId().toString();
+            }
+        }
+
+        public String getMimeType()
+        {
 
-            for(int i = 0 ; i < headerCount; i++)
+            if(_properties == null || _properties.getContentType() == null)
+            {
+                return null;
+            }
+            else
             {
-                headers[i] = decoder.readStruct32();
+                return _properties.getContentType().toString();
             }
+        }
 
-            Header header = new Header(headers);
+        public String getEncoding()
+        {
+            return null;  //TODO
+        }
 
-            return new MessageMetaData_0_10(header, bodySize, arrivalTime);
+        public byte getPriority()
+        {
+            if(_header == null || _header.getPriority() == null)
+            {
+                return 4; //javax.jms.Message.DEFAULT_PRIORITY;
+            }
+            else
+            {
+                return _header.getPriority().byteValue();
+            }
+        }
 
+        public long getTimestamp()
+        {
+            if(_properties == null || _properties.getCreationTime() == null)
+            {
+                return 0L;
+            }
+            else
+            {
+                return _properties.getCreationTime().getTime();
+            }
+
+        }
+
+        public String getType()
+        {
+
+            if(_appProperties == null || _appProperties.get(JMS_TYPE) == null)
+            {
+                return null;
+            }
+            else
+            {
+                return _appProperties.get(JMS_TYPE).toString();
+            }
+        }
+
+        public String getReplyTo()
+        {
+            if(_properties == null || _properties.getReplyTo() == null)
+            {
+                return null;
+            }
+            else
+            {
+                return _properties.getReplyTo().toString();
+            }
+        }
+
+        public String getReplyToExchange()
+        {
+            return null;  //TODO
+        }
+
+        public String getReplyToRoutingKey()
+        {
+            return null;  //TODO
         }
+
+        public Object getHeader(final String name)
+        {
+            return _appProperties == null ? null : _appProperties.get(name);
+        }
+
+        public boolean containsHeaders(final Set<String> names)
+        {
+            if(_appProperties == null)
+            {
+                return false;
+            }
+
+            for(String key : names)
+            {
+                if(!_appProperties.containsKey(key))
+                {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        public boolean containsHeader(final String name)
+        {
+            return _appProperties != null && _appProperties.containsKey(name);
+        }
+
     }
+
 }

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageTransferMessage.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageTransferMessage.java?rev=1157566&r1=1157565&r2=1157566&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageTransferMessage.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/MessageTransferMessage.java Sun Aug 14 17:14:51 2011
@@ -29,7 +29,7 @@ import java.nio.ByteBuffer;
 import java.lang.ref.WeakReference;
 
 
-public class MessageTransferMessage implements InboundMessage, ServerMessage
+public class MessageTransferMessage implements InboundMessage, ServerMessage<MessageTransferMessage>
 {
 
 
@@ -90,7 +90,7 @@ public class MessageTransferMessage impl
         return getMetaData().getExpiration();
     }
 
-    public MessageReference newReference()
+    public MessageReference<MessageTransferMessage> newReference()
     {
         return new TransferMessageReference(this);
     }
@@ -145,5 +145,5 @@ public class MessageTransferMessage impl
     {
         return _sessionRef == null ? null : (ServerSession) _sessionRef.get();
     }
-    
+
 }

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/ServerMessage.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/ServerMessage.java?rev=1157566&r1=1157565&r2=1157566&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/ServerMessage.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/message/ServerMessage.java Sun Aug 14 17:14:51 2011
@@ -24,7 +24,7 @@ import java.nio.ByteBuffer;
 
 import org.apache.qpid.server.configuration.SessionConfig;
 
-public interface ServerMessage extends EnqueableMessage, MessageContentSource
+public interface ServerMessage<T extends ServerMessage> extends EnqueableMessage, MessageContentSource
 {
     String getRoutingKey();
 
@@ -38,7 +38,7 @@ public interface ServerMessage extends E
 
     long getExpiration();
 
-    MessageReference newReference();
+    MessageReference<T> newReference();
 
     Long getMessageNumber();
 

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQPSASLEngine_1_0_0.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQPSASLEngine_1_0_0.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQPSASLEngine_1_0_0.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQPSASLEngine_1_0_0.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,339 @@
+/*
+ *
+ * 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.server.protocol;
+
+import org.apache.qpid.amqp_1_0.codec.FrameWriter;
+import org.apache.qpid.amqp_1_0.framing.AMQFrame;
+import org.apache.qpid.amqp_1_0.framing.FrameHandler;
+import org.apache.qpid.amqp_1_0.transport.ConnectionEndpoint;
+import org.apache.qpid.amqp_1_0.transport.Container;
+import org.apache.qpid.amqp_1_0.transport.FrameOutputHandler;
+import org.apache.qpid.amqp_1_0.type.FrameBody;
+
+import org.apache.qpid.protocol.ProtocolEngine;
+import org.apache.qpid.server.configuration.ConfigStore;
+import org.apache.qpid.server.configuration.ConnectionConfigType;
+import org.apache.qpid.server.protocol.v1_0.Connection_1_0;
+import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.transport.NetworkDriver;
+
+import java.io.PrintWriter;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.security.Principal;
+import java.util.UUID;
+
+public class AMQPSASLEngine_1_0_0 implements ProtocolEngine, FrameOutputHandler
+{
+    public static final int MAX_FRAME_SIZE = 64 * 1024 - 1;
+
+    private NetworkDriver _networkDriver;
+    private long _readBytes;
+    private long _writtenBytes;
+    private final UUID _id;
+    private final IApplicationRegistry _appRegistry;
+    private long _createTime = System.currentTimeMillis();
+
+    private static final int BUF_SIZE = 8;
+    private static final ByteBuffer HEADER =
+            ByteBuffer.wrap(new byte[]
+                    {
+                        (byte)'A',
+                        (byte)'M',
+                        (byte)'Q',
+                        (byte)'P',
+                        (byte) 0,
+                        (byte) 1,
+                        (byte) 0,
+                        (byte) 0
+                    });
+
+    private FrameWriter _frameWriter;
+    private FrameHandler _frameHandler;
+    private ByteBuffer _buf = ByteBuffer.allocate(1024 * 1024);
+    private Object _sendLock = new Object();
+    private byte _major;
+    private byte _minor;
+    private byte _revision;
+    private ConnectionEndpoint _conn;
+
+
+    static enum State {
+        A,
+        M,
+        Q,
+        P,
+        PROTOCOL,
+        MAJOR,
+        MINOR,
+        REVISION,
+        FRAME
+    }
+
+    private State _state = State.A;
+
+    public AMQPSASLEngine_1_0_0(NetworkDriver networkDriver,
+                                final IApplicationRegistry appRegistry)
+    {
+
+
+        _networkDriver = networkDriver;
+        _id = appRegistry.getConfigStore().createId();
+        _appRegistry = appRegistry;
+
+
+        // FIXME Two log messages to maintain compatinbility with earlier protocol versions
+//        _connection.getLogActor().message(ConnectionMessages.OPEN(null, null, false, false));
+//        _connection.getLogActor().message(ConnectionMessages.OPEN(null, "0-10", false, true));
+    }
+
+    public void setNetworkDriver(NetworkDriver driver)
+    {
+        _networkDriver = driver;
+
+
+        _conn = new ConnectionEndpoint(new Container(),_appRegistry.getAuthenticationManager());
+        _conn.setConnectionEventListener(new Connection_1_0(_appRegistry));
+        _conn.setFrameOutputHandler(this);
+
+
+        _frameWriter =  new FrameWriter(_conn.getDescribedTypeRegistry());
+        _frameHandler = new FrameHandler(_conn);
+
+        _networkDriver.send(HEADER.duplicate());
+
+
+
+    }
+
+    public SocketAddress getRemoteAddress()
+    {
+        return _networkDriver.getRemoteAddress();
+    }
+
+    public SocketAddress getLocalAddress()
+    {
+        return _networkDriver.getLocalAddress();
+    }
+
+    public long getReadBytes()
+    {
+        return _readBytes;
+    }
+
+    public long getWrittenBytes()
+    {
+        return _writtenBytes;
+    }
+
+    public void writerIdle()
+    {
+        //Todo
+    }
+
+    public void readerIdle()
+    {
+        //Todo
+    }
+
+    public String getAddress()
+    {
+        return getRemoteAddress().toString();
+    }
+
+
+    public ConfigStore getConfigStore()
+    {
+        return _appRegistry.getConfigStore();
+    }
+
+    public UUID getId()
+    {
+        return _id;
+    }
+
+    public ConnectionConfigType getConfigType()
+    {
+        return ConnectionConfigType.getInstance();
+    }
+
+    public boolean isDurable()
+    {
+        return false;
+    }
+
+    public synchronized void received(ByteBuffer msg)
+    {
+        _readBytes += msg.remaining();
+            switch(_state)
+            {
+                case A:
+                    if(msg.hasRemaining())
+                    {
+                        msg.get();
+                    }
+                    else
+                    {
+                        break;
+                    }
+                case M:
+                    if(msg.hasRemaining())
+                    {
+                        msg.get();
+                    }
+                    else
+                    {
+                        _state = State.M;
+                        break;
+                    }
+
+                case Q:
+                    if(msg.hasRemaining())
+                    {
+                        msg.get();
+                    }
+                    else
+                    {
+                        _state = State.Q;
+                        break;
+                    }
+                case P:
+                    if(msg.hasRemaining())
+                    {
+                        msg.get();
+                    }
+                    else
+                    {
+                        _state = State.P;
+                        break;
+                    }
+                case PROTOCOL:
+                    if(msg.hasRemaining())
+                    {
+                        msg.get();
+                    }
+                    else
+                    {
+                        _state = State.PROTOCOL;
+                        break;
+                    }
+                case MAJOR:
+                    if(msg.hasRemaining())
+                    {
+                        _major = msg.get();
+                    }
+                    else
+                    {
+                        _state = State.MAJOR;
+                        break;
+                    }
+                case MINOR:
+                    if(msg.hasRemaining())
+                    {
+                        _minor = msg.get();
+                    }
+                    else
+                    {
+                        _state = State.MINOR;
+                        break;
+                    }
+                case REVISION:
+                    if(msg.hasRemaining())
+                    {
+                        _revision = msg.get();
+
+                        _state = State.FRAME;
+                    }
+                    else
+                    {
+                        _state = State.REVISION;
+                        break;
+                    }
+                case FRAME:
+                    _frameHandler.parse(msg);
+            }
+
+    }
+
+    public void exception(Throwable t)
+    {
+        t.printStackTrace();
+    }
+
+    public void closed()
+    {
+        // todo
+
+    }
+
+    public long getCreateTime()
+    {
+        return _createTime;
+    }
+
+
+    public boolean canSend()
+    {
+        return true;
+    }
+
+    public void send(AMQFrame frame)
+    {
+        send(frame, null);
+    }
+    public void send(AMQFrame frame, ByteBuffer buffer)
+    {
+
+        synchronized(_sendLock)
+        {
+
+            if(_buf.remaining() < MAX_FRAME_SIZE)
+            {
+                _buf = ByteBuffer.allocate(1024*1024);
+            }
+
+            _frameWriter.setValue(frame);
+
+            ByteBuffer dup = _buf.slice();
+
+            _frameWriter.writeToBuffer(dup);
+
+            _buf.position(_buf.position()+dup.position());
+
+            dup.flip();
+            _writtenBytes += dup.limit();
+            _networkDriver.send(dup);
+
+        }
+    }
+
+    public void close()
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void setLogOutput(final PrintWriter out)
+    {
+        //TODO
+    }
+
+
+}

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java?rev=1157566&r1=1157565&r2=1157566&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngine.java Sun Aug 14 17:14:51 2011
@@ -153,6 +153,28 @@ private static final byte[] AMQP_0_9_1_H
                          (byte) 10
             };
 
+    private static final byte[] AMQP_1_0_0_HEADER =
+                new byte[] { (byte) 'A',
+                             (byte) 'M',
+                             (byte) 'Q',
+                             (byte) 'P',
+                             (byte) 0,
+                             (byte) 1,
+                             (byte) 0,
+                             (byte) 0
+                };
+
+    private static final byte[] AMQP_SASL_1_0_0_HEADER =
+                new byte[] { (byte) 'A',
+                             (byte) 'M',
+                             (byte) 'Q',
+                             (byte) 'P',
+                             (byte) 3,
+                             (byte) 1,
+                             (byte) 0,
+                             (byte) 0
+                };
+
     private static interface DelegateCreator
     {
         VERSION getVersion();
@@ -246,8 +268,49 @@ private static final byte[] AMQP_0_9_1_H
         }
     };
 
+    private DelegateCreator creator_1_0_0 = new DelegateCreator()
+    {
+
+        public VERSION getVersion()
+        {
+            return VERSION.v1_0_0;
+        }
+
+
+        public byte[] getHeaderIdentifier()
+        {
+            return AMQP_1_0_0_HEADER;
+        }
+
+        public ProtocolEngine getProtocolEngine()
+        {
+            return new ProtocolEngine_1_0_0(_networkDriver, _appRegistry);
+        }
+    };
+
+    private DelegateCreator creator_1_0_0_SASL = new DelegateCreator()
+    {
+
+        public VERSION getVersion()
+        {
+            return VERSION.v1_0_0;
+        }
+
+
+        public byte[] getHeaderIdentifier()
+        {
+            return AMQP_SASL_1_0_0_HEADER;
+        }
+
+        public ProtocolEngine getProtocolEngine()
+        {
+            return new ProtocolEngine_1_0_0_SASL(_networkDriver, _appRegistry);
+        }
+    };
+
+
     private final DelegateCreator[] _creators =
-            new DelegateCreator[] { creator_0_8, creator_0_9, creator_0_9_1, creator_0_10 };
+            new DelegateCreator[] { creator_0_8, creator_0_9, creator_0_9_1, creator_0_10, creator_1_0_0_SASL, creator_1_0_0};
 
 
     private class ClosedDelegateProtocolEngine implements ProtocolEngine

Copied: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java (from r1073293, qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java)
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java?p2=qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java&p1=qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java&r1=1073293&r2=1157566&rev=1157566&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_0_10.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0.java Sun Aug 14 17:14:51 2011
@@ -20,60 +20,115 @@
  */
 package org.apache.qpid.server.protocol;
 
+import org.apache.qpid.amqp_1_0.codec.FrameWriter;
+import org.apache.qpid.amqp_1_0.framing.AMQFrame;
+import org.apache.qpid.amqp_1_0.framing.FrameHandler;
+import org.apache.qpid.amqp_1_0.framing.OversizeFrameException;
+import org.apache.qpid.amqp_1_0.transport.*;
+import org.apache.qpid.amqp_1_0.type.Binary;
+import org.apache.qpid.amqp_1_0.type.FrameBody;
+
 import org.apache.qpid.protocol.ProtocolEngine;
-import org.apache.qpid.transport.NetworkDriver;
-import org.apache.qpid.transport.network.InputHandler;
-import org.apache.qpid.transport.network.Assembler;
-import org.apache.qpid.transport.network.Disassembler;
 import org.apache.qpid.server.configuration.*;
-import org.apache.qpid.server.transport.ServerConnection;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.messages.ConnectionMessages;
+import org.apache.qpid.server.protocol.v1_0.Connection_1_0;
 import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.transport.NetworkDriver;
 
+import java.io.PrintWriter;
 import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.security.Principal;
 import java.util.UUID;
+import java.util.logging.*;
 
-public class ProtocolEngine_0_10  extends InputHandler implements ProtocolEngine, ConnectionConfig
+public class ProtocolEngine_1_0_0 implements ProtocolEngine, FrameOutputHandler
 {
     public static final int MAX_FRAME_SIZE = 64 * 1024 - 1;
 
     private NetworkDriver _networkDriver;
     private long _readBytes;
     private long _writtenBytes;
-    private ServerConnection _connection;
     private final UUID _id;
     private final IApplicationRegistry _appRegistry;
     private long _createTime = System.currentTimeMillis();
+    private ConnectionEndpoint _conn;
+
+    private static final int BUF_SIZE = 8;
+    private static final ByteBuffer HEADER =
+            ByteBuffer.wrap(new byte[]
+                    {
+                        (byte)'A',
+                        (byte)'M',
+                        (byte)'Q',
+                        (byte)'P',
+                        (byte) 0,
+                        (byte) 1,
+                        (byte) 0,
+                        (byte) 0
+                    });
+
+    private FrameWriter _frameWriter;
+    private FrameHandler _frameHandler;
+    private ByteBuffer _buf = ByteBuffer.allocate(1024 * 1024);
+    private Object _sendLock = new Object();
+    private byte _major;
+    private byte _minor;
+    private byte _revision;
+
+
+    static enum State {
+        A,
+        M,
+        Q,
+        P,
+        PROTOCOL,
+        MAJOR,
+        MINOR,
+        REVISION,
+        FRAME
+    }
+
+    private State _state = State.A;
+
+    public ProtocolEngine_1_0_0(NetworkDriver networkDriver,
+                                final IApplicationRegistry appRegistry)
+    {
+
 
-    public ProtocolEngine_0_10(ServerConnection conn,
-                               NetworkDriver networkDriver,
-                               final IApplicationRegistry appRegistry)
-    {
-        super(new Assembler(conn));
-        _connection = conn;
-        _connection.setConnectionConfig(this);
         _networkDriver = networkDriver;
         _id = appRegistry.getConfigStore().createId();
         _appRegistry = appRegistry;
 
+
         // FIXME Two log messages to maintain compatinbility with earlier protocol versions
-        _connection.getLogActor().message(ConnectionMessages.OPEN(null, null, false, false));
-        _connection.getLogActor().message(ConnectionMessages.OPEN(null, "0-10", false, true));
+//        _connection.getLogActor().message(ConnectionMessages.OPEN(null, null, false, false));
+//        _connection.getLogActor().message(ConnectionMessages.OPEN(null, "0-10", false, true));
     }
 
     public void setNetworkDriver(NetworkDriver driver)
     {
         _networkDriver = driver;
-        Disassembler dis = new Disassembler(driver, MAX_FRAME_SIZE);
-        _connection.setSender(dis);
-        _connection.onOpen(new Runnable()
-        {
-            public void run()
-            {
-                getConfigStore().addConfiguredObject(ProtocolEngine_0_10.this);
-            }
-        });
+        Container container = new Container();
+
+                    Principal principal = new Principal()
+                    {
+
+                        public String getName()
+                        {
+                            // TODO
+                            return "rob";
+                        }
+                    };
+        _conn = new ConnectionEndpoint(container,_appRegistry.getAuthenticationManager());
+        _conn.setConnectionEventListener(new Connection_1_0(_appRegistry));
+        _conn.setFrameOutputHandler(this);
+        _conn.setRemoteAddress(driver.getRemoteAddress());
+
+
+        _frameWriter =  new FrameWriter(_conn.getDescribedTypeRegistry());
+        _frameHandler = new FrameHandler(_conn);
+
+        _networkDriver.send(HEADER.duplicate());
 
     }
 
@@ -107,95 +162,229 @@ public class ProtocolEngine_0_10  extend
         //Todo
     }
 
-    public VirtualHostConfig getVirtualHost()
-    {
-        return _connection.getVirtualHost();
-    }
-
     public String getAddress()
     {
         return getRemoteAddress().toString();
     }
 
-    public Boolean isIncoming()
-    {
-        return true;
-    }
 
-    public Boolean isSystemConnection()
+    public ConfigStore getConfigStore()
     {
-        return false;
+        return _appRegistry.getConfigStore();
     }
 
-    public Boolean isFederationLink()
+    public UUID getId()
     {
-        return false;
+        return _id;
     }
 
-    public String getAuthId()
+    public ConnectionConfigType getConfigType()
     {
-        return _connection.getAuthorizationID();
+        return ConnectionConfigType.getInstance();
     }
 
-    public String getRemoteProcessName()
+    public boolean isDurable()
     {
-        return null;
+        return false;
     }
 
-    public Integer getRemotePID()
+    public synchronized void received(ByteBuffer msg)
     {
-        return null;
-    }
+        if(RAW_LOGGER.isLoggable(Level.FINE))
+        {
+            ByteBuffer dup = msg.duplicate();
+            byte[] data = new byte[dup.remaining()];
+            dup.get(data);
+            Binary bin = new Binary(data);
+            RAW_LOGGER.fine("RECV[" + getRemoteAddress() + "] : " + bin.toString());
+        }
+        _readBytes += msg.remaining();
+            switch(_state)
+            {
+                case A:
+                    if(msg.hasRemaining())
+                    {
+                        msg.get();
+                    }
+                    else
+                    {
+                        break;
+                    }
+                case M:
+                    if(msg.hasRemaining())
+                    {
+                        msg.get();
+                    }
+                    else
+                    {
+                        _state = State.M;
+                        break;
+                    }
+
+                case Q:
+                    if(msg.hasRemaining())
+                    {
+                        msg.get();
+                    }
+                    else
+                    {
+                        _state = State.Q;
+                        break;
+                    }
+                case P:
+                    if(msg.hasRemaining())
+                    {
+                        msg.get();
+                    }
+                    else
+                    {
+                        _state = State.P;
+                        break;
+                    }
+                case PROTOCOL:
+                    if(msg.hasRemaining())
+                    {
+                        msg.get();
+                    }
+                    else
+                    {
+                        _state = State.PROTOCOL;
+                        break;
+                    }
+                case MAJOR:
+                    if(msg.hasRemaining())
+                    {
+                        _major = msg.get();
+                    }
+                    else
+                    {
+                        _state = State.MAJOR;
+                        break;
+                    }
+                case MINOR:
+                    if(msg.hasRemaining())
+                    {
+                        _minor = msg.get();
+                    }
+                    else
+                    {
+                        _state = State.MINOR;
+                        break;
+                    }
+                case REVISION:
+                    if(msg.hasRemaining())
+                    {
+                        _revision = msg.get();
+
+                        _state = State.FRAME;
+                    }
+                    else
+                    {
+                        _state = State.REVISION;
+                        break;
+                    }
+                case FRAME:
+                    _frameHandler.parse(msg);
+            }
 
-    public Integer getRemoteParentPID()
-    {
-        return null;
     }
 
-    public ConfigStore getConfigStore()
+    public void exception(Throwable t)
     {
-        return _appRegistry.getConfigStore();
+        t.printStackTrace();
     }
 
-    public UUID getId()
+    public void closed()
     {
-        return _id;
-    }
+        _conn.inputClosed();
+        if(_conn != null && _conn.getConnectionEventListener() != null)
+        {
+            ((Connection_1_0)_conn.getConnectionEventListener()).closed();
+        }
 
-    public ConnectionConfigType getConfigType()
-    {
-        return ConnectionConfigType.getInstance();
     }
 
-    public ConfiguredObject getParent()
+    public long getCreateTime()
     {
-        return getVirtualHost();
+        return _createTime;
     }
 
-    public boolean isDurable()
+
+    public boolean canSend()
     {
-        return false;
+        return true;
     }
 
-    @Override
-    public void closed()
+    public void send(final AMQFrame amqFrame)
     {
-        super.closed();
-        getConfigStore().removeConfiguredObject(this);
+        send(amqFrame, null);
     }
 
-    public long getCreateTime()
+    private final Logger FRAME_LOGGER = Logger.getLogger("FRM");
+    private final Logger RAW_LOGGER = Logger.getLogger("RAW");
+
+
+    public void send(final AMQFrame amqFrame, ByteBuffer buf)
     {
-        return _createTime;
+        synchronized(_sendLock)
+        {
+
+            if(FRAME_LOGGER.isLoggable(Level.FINE))
+            {
+                FRAME_LOGGER.fine("SEND[" + getRemoteAddress() + "|" + amqFrame.getChannel() + "] : " + amqFrame.getFrameBody());
+            }
+
+            if(_buf.remaining() < _conn.getMaxFrameSize())
+            {
+                _buf = ByteBuffer.allocate(Math.min(_conn.getMaxFrameSize(),1024*1024));
+            }
+            _frameWriter.setValue(amqFrame);
+
+
+
+            ByteBuffer dup = ByteBuffer.allocate(_conn.getMaxFrameSize());
+  //          int pos = _buf.position();
+
+            int size = _frameWriter.writeToBuffer(dup);
+            if(size > _conn.getMaxFrameSize())
+            {
+//                _buf.position(pos);
+                throw new OversizeFrameException(amqFrame,size);
+            }
+
+//            _buf.position(_buf.position()+dup.position());
+
+            dup.flip();
+            _writtenBytes += dup.limit();
+
+            if(RAW_LOGGER.isLoggable(Level.FINE))
+             {
+                ByteBuffer dup2 = dup.duplicate();
+                byte[] data = new byte[dup2.remaining()];
+                dup2.get(data);
+                Binary bin = new Binary(data);
+                RAW_LOGGER.fine("SEND[" + getRemoteAddress() + "] : " + bin.toString());
+             }
+
+
+            _networkDriver.send(dup);
+
+        }
     }
 
-    public Boolean isShadow()
+    public void send(short channel, FrameBody body)
     {
-        return false;
+        AMQFrame frame = AMQFrame.createAMQFrame(channel, body);
+        send(frame);
+
     }
-    
-    public void mgmtClose()
+
+    public void close()
     {
-        _connection.mgmtClose();
+        System.out.print(true);
+        //To change body of implemented methods use File | Settings | File Templates.
     }
+
+
+
 }

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/ProtocolEngine_1_0_0_SASL.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,426 @@
+/*
+ *
+ * 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.server.protocol;
+
+import org.apache.qpid.amqp_1_0.codec.FrameWriter;
+import org.apache.qpid.amqp_1_0.codec.ProtocolHandler;
+import org.apache.qpid.amqp_1_0.framing.AMQFrame;
+import org.apache.qpid.amqp_1_0.framing.FrameHandler;
+import org.apache.qpid.amqp_1_0.framing.OversizeFrameException;
+import org.apache.qpid.amqp_1_0.framing.SASLFrameHandler;
+import org.apache.qpid.amqp_1_0.transport.ConnectionEndpoint;
+import org.apache.qpid.amqp_1_0.transport.Container;
+import org.apache.qpid.amqp_1_0.transport.FrameOutputHandler;
+import org.apache.qpid.amqp_1_0.type.Binary;
+import org.apache.qpid.amqp_1_0.type.FrameBody;
+
+import org.apache.qpid.protocol.ProtocolEngine;
+import org.apache.qpid.server.configuration.ConfigStore;
+import org.apache.qpid.server.configuration.ConnectionConfigType;
+import org.apache.qpid.server.protocol.v1_0.Connection_1_0;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.transport.NetworkDriver;
+
+import java.io.PrintWriter;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.security.Principal;
+import java.util.UUID;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class ProtocolEngine_1_0_0_SASL implements ProtocolEngine, FrameOutputHandler
+{
+    private NetworkDriver _networkDriver;
+       private long _readBytes;
+       private long _writtenBytes;
+       private final UUID _id;
+       private final IApplicationRegistry _appRegistry;
+       private long _createTime = System.currentTimeMillis();
+       private ConnectionEndpoint _conn;
+
+       private static final int BUF_SIZE = 8;
+       private static final ByteBuffer HEADER =
+               ByteBuffer.wrap(new byte[]
+                       {
+                           (byte)'A',
+                           (byte)'M',
+                           (byte)'Q',
+                           (byte)'P',
+                           (byte) 3,
+                           (byte) 1,
+                           (byte) 0,
+                           (byte) 0
+                       });
+
+        private static final ByteBuffer PROTOCOL_HEADER =
+            ByteBuffer.wrap(new byte[]
+                    {
+                        (byte)'A',
+                        (byte)'M',
+                        (byte)'Q',
+                        (byte)'P',
+                        (byte) 0,
+                        (byte) 1,
+                        (byte) 0,
+                        (byte) 0
+                    });
+
+
+       private FrameWriter _frameWriter;
+       private ProtocolHandler _frameHandler;
+       private ByteBuffer _buf = ByteBuffer.allocate(1024 * 1024);
+       private Object _sendLock = new Object();
+       private byte _major;
+       private byte _minor;
+       private byte _revision;
+    private PrintWriter _out;
+
+
+    static enum State {
+           A,
+           M,
+           Q,
+           P,
+           PROTOCOL,
+           MAJOR,
+           MINOR,
+           REVISION,
+           FRAME
+       }
+
+       private State _state = State.A;
+
+
+    public ProtocolEngine_1_0_0_SASL(final NetworkDriver networkDriver, final IApplicationRegistry appRegistry)
+    {
+        _networkDriver = networkDriver;
+        _id = appRegistry.getConfigStore().createId();
+        _appRegistry = appRegistry;
+    }
+
+    public void setNetworkDriver(final NetworkDriver driver)
+    {
+        _networkDriver = driver;
+        Container container = new Container();
+
+                    Principal principal = new Principal()
+                    {
+
+                        public String getName()
+                        {
+                            // TODO
+                            return "rob";
+                        }
+                    };
+        _conn = new ConnectionEndpoint(container, ApplicationRegistry.getInstance().getAuthenticationManager());
+        _conn.setConnectionEventListener(new Connection_1_0(_appRegistry));
+        _conn.setRemoteAddress(getRemoteAddress());
+
+
+        _conn.setFrameOutputHandler(this);
+        _conn.setSaslFrameOutput(this);
+
+        _conn.setOnSaslComplete(new Runnable()
+        {
+
+
+            public void run()
+            {
+                if(_conn.isAuthenticated())
+                {
+                    _networkDriver.send(PROTOCOL_HEADER.duplicate());
+                }
+                else
+                {
+                    _networkDriver.close();
+                }
+            }
+        });
+        _frameWriter =  new FrameWriter(_conn.getDescribedTypeRegistry());
+        _frameHandler = new SASLFrameHandler(_conn);
+
+        _networkDriver.send(HEADER.duplicate());
+
+        _conn.initiateSASL();
+
+    }
+
+    public SocketAddress getRemoteAddress()
+    {
+        return _networkDriver.getRemoteAddress();
+    }
+
+    public SocketAddress getLocalAddress()
+    {
+        return _networkDriver.getLocalAddress();
+    }
+
+    public long getReadBytes()
+    {
+        return _readBytes;
+    }
+
+    public long getWrittenBytes()
+    {
+        return _writtenBytes;
+    }
+
+    public void writerIdle()
+    {
+        //Todo
+    }
+
+    public void readerIdle()
+    {
+        //Todo
+    }
+
+    public String getAddress()
+    {
+        return getRemoteAddress().toString();
+    }
+
+
+    public ConfigStore getConfigStore()
+    {
+        return _appRegistry.getConfigStore();
+    }
+
+    public UUID getId()
+    {
+        return _id;
+    }
+
+    public ConnectionConfigType getConfigType()
+    {
+        return ConnectionConfigType.getInstance();
+    }
+
+    public boolean isDurable()
+    {
+        return false;
+    }
+
+    private final Logger RAW_LOGGER = Logger.getLogger("RAW");
+
+
+    public synchronized void received(ByteBuffer msg)
+    {
+        if(RAW_LOGGER.isLoggable(Level.FINE))
+        {
+            ByteBuffer dup = msg.duplicate();
+            byte[] data = new byte[dup.remaining()];
+            dup.get(data);
+            Binary bin = new Binary(data);
+            RAW_LOGGER.fine("RECV[" + getRemoteAddress() + "] : " + bin.toString());
+        }
+         _readBytes += msg.remaining();
+             switch(_state)
+             {
+                 case A:
+                     if(msg.hasRemaining())
+                     {
+                         msg.get();
+                     }
+                     else
+                     {
+                         break;
+                     }
+                 case M:
+                     if(msg.hasRemaining())
+                     {
+                         msg.get();
+                     }
+                     else
+                     {
+                         _state = State.M;
+                         break;
+                     }
+
+                 case Q:
+                     if(msg.hasRemaining())
+                     {
+                         msg.get();
+                     }
+                     else
+                     {
+                         _state = State.Q;
+                         break;
+                     }
+                 case P:
+                     if(msg.hasRemaining())
+                     {
+                         msg.get();
+                     }
+                     else
+                     {
+                         _state = State.P;
+                         break;
+                     }
+                 case PROTOCOL:
+                     if(msg.hasRemaining())
+                     {
+                         msg.get();
+                     }
+                     else
+                     {
+                         _state = State.PROTOCOL;
+                         break;
+                     }
+                 case MAJOR:
+                     if(msg.hasRemaining())
+                     {
+                         _major = msg.get();
+                     }
+                     else
+                     {
+                         _state = State.MAJOR;
+                         break;
+                     }
+                 case MINOR:
+                     if(msg.hasRemaining())
+                     {
+                         _minor = msg.get();
+                     }
+                     else
+                     {
+                         _state = State.MINOR;
+                         break;
+                     }
+                 case REVISION:
+                     if(msg.hasRemaining())
+                     {
+                         _revision = msg.get();
+
+                         _state = State.FRAME;
+                     }
+                     else
+                     {
+                         _state = State.REVISION;
+                         break;
+                     }
+                 case FRAME:
+                     _frameHandler = _frameHandler.parse(msg);
+             }
+
+     }
+
+     public void exception(Throwable t)
+     {
+         t.printStackTrace();
+     }
+
+     public void closed()
+     {
+         // todo
+        _conn.inputClosed();
+        if(_conn != null && _conn.getConnectionEventListener() != null)
+        {
+            ((Connection_1_0)_conn.getConnectionEventListener()).closed();
+        }
+
+     }
+
+     public long getCreateTime()
+     {
+         return _createTime;
+     }
+
+
+     public boolean canSend()
+     {
+         return true;
+     }
+
+     public void send(final AMQFrame amqFrame)
+     {
+         send(amqFrame, null);
+     }
+
+     private static final Logger FRAME_LOGGER = Logger.getLogger("FRM");
+
+
+     public void send(final AMQFrame amqFrame, ByteBuffer buf)
+     {
+
+         synchronized(_sendLock)
+         {
+            if(FRAME_LOGGER.isLoggable(Level.FINE))
+            {
+                FRAME_LOGGER.fine("SEND[" + getRemoteAddress() + "|" + amqFrame.getChannel() + "] : " + amqFrame.getFrameBody());
+            }
+             if(_buf.remaining() < _conn.getMaxFrameSize())
+             {
+                 _buf = ByteBuffer.allocate(Math.min(_conn.getMaxFrameSize(),1024*1024));
+             }
+             _frameWriter.setValue(amqFrame);
+
+             ByteBuffer dup = _buf.slice();
+             int pos = _buf.position();
+
+             int size = _frameWriter.writeToBuffer(dup);
+             if(size > _conn.getMaxFrameSize())
+             {
+                 _buf.position(pos);
+                 throw new OversizeFrameException(amqFrame,size);
+             }
+
+             _buf.position(_buf.position()+dup.position());
+
+             dup.flip();
+             _writtenBytes += dup.limit();
+
+             if(RAW_LOGGER.isLoggable(Level.FINE))
+             {
+                ByteBuffer dup2 = dup.duplicate();
+                byte[] data = new byte[dup2.remaining()];
+                dup2.get(data);
+                Binary bin = new Binary(data);
+                RAW_LOGGER.fine("SEND[" + getRemoteAddress() + "] : " + bin.toString());
+             }
+
+             _networkDriver.send(dup);
+
+         }
+     }
+
+     public void send(short channel, FrameBody body)
+     {
+         AMQFrame frame = AMQFrame.createAMQFrame(channel, body);
+         send(frame);
+
+     }
+
+     public void close()
+     {
+         //To change body of implemented methods use File | Settings | File Templates.
+     }
+
+     public void setLogOutput(final PrintWriter out)
+     {
+         _out = out;
+     }
+
+
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Connection_1_0.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,98 @@
+/*
+ *
+ * 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.server.protocol.v1_0;
+
+import org.apache.qpid.amqp_1_0.transport.ConnectionEventListener;
+import org.apache.qpid.amqp_1_0.transport.SessionEndpoint;
+
+import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class Connection_1_0 implements ConnectionEventListener
+{
+
+    private IApplicationRegistry _appRegistry;
+    private VirtualHost _vhost;
+
+
+    public static interface Task
+    {
+        public void doTask(Connection_1_0 connection);
+    }
+
+
+    private List<Task> _closeTasks =
+            Collections.synchronizedList(new ArrayList<Task>());
+
+
+
+    public Connection_1_0(IApplicationRegistry appRegistry)
+    {
+        _appRegistry = appRegistry;
+        _vhost = _appRegistry.getVirtualHostRegistry().getDefaultVirtualHost();
+    }
+
+    public void remoteSessionCreation(SessionEndpoint endpoint)
+    {
+        Session_1_0 session = new Session_1_0(_vhost, _appRegistry, this);
+        endpoint.setSessionEventListener(session);
+    }
+
+
+    void removeConnectionCloseTask(final Task task)
+    {
+        _closeTasks.remove( task );
+    }
+
+    void addConnectionCloseTask(final Task task)
+    {
+        _closeTasks.add( task );
+    }
+
+    public void closeReceived()
+    {
+        List<Task> taskCopy;
+        synchronized (_closeTasks)
+        {
+            taskCopy = new ArrayList<Task>(_closeTasks);
+        }
+        for(Task task : taskCopy)
+        {
+            task.doTask(this);
+        }
+        synchronized (_closeTasks)
+        {
+            _closeTasks.clear();
+        }
+
+    }
+
+    public void closed()
+    {
+        closeReceived();
+    }
+
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Destination.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Destination.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Destination.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Destination.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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.server.protocol.v1_0;
+
+
+public interface Destination
+{
+
+
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ExchangeDestination.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ExchangeDestination.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ExchangeDestination.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ExchangeDestination.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,90 @@
+/*
+ *
+ * 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.server.protocol.v1_0;
+
+import org.apache.qpid.amqp_1_0.type.Outcome;
+import org.apache.qpid.amqp_1_0.type.messaging.Accepted;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.queue.BaseQueue;
+import org.apache.qpid.server.txn.ServerTransaction;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class ExchangeDestination implements ReceivingDestination
+{
+    private static final Accepted ACCEPTED = new Accepted();
+    private static final Outcome[] OUTCOMES = { ACCEPTED };
+
+    private Exchange _exchange;
+
+    public ExchangeDestination(Exchange exchange)
+    {
+        _exchange = exchange;
+    }
+
+    public Outcome[] getOutcomes()
+    {
+        return OUTCOMES;
+    }
+
+    public Outcome send(final Message_1_0 message, ServerTransaction txn)
+    {
+        final ArrayList<? extends BaseQueue> queues = _exchange.route(message);
+
+        txn.enqueue(queues,message, new ServerTransaction.Action()
+        {
+
+            BaseQueue[] _queues = queues.toArray(new BaseQueue[queues.size()]);
+
+            public void postCommit()
+            {
+                for(int i = 0; i < _queues.length; i++)
+                {
+                    try
+                    {
+                        _queues[i].enqueue(message);
+                    }
+                    catch (AMQException e)
+                    {
+                        // TODO
+                        throw new RuntimeException(e);
+                    }
+                }
+            }
+
+            public void onRollback()
+            {
+                // NO-OP
+            }
+        });
+
+        return ACCEPTED;
+    }
+
+    public int getCredit()
+    {
+        // TODO - fix
+        return 20000;
+    }
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/LinkRegistry.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/LinkRegistry.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/LinkRegistry.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/LinkRegistry.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,59 @@
+package org.apache.qpid.server.protocol.v1_0;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class LinkRegistry
+{
+    private final Map<String, SendingLink_1_0> _sendingLinks = new HashMap<String, SendingLink_1_0>();
+    private final Map<String, ReceivingLink_1_0> _receivingLinks = new HashMap<String, ReceivingLink_1_0>();
+
+    public synchronized SendingLink_1_0 getDurableSendingLink(String name)
+    {
+        return _sendingLinks.get(name);
+    }
+
+    public synchronized boolean registerSendingLink(String name, SendingLink_1_0 link)
+    {
+        if(_sendingLinks.containsKey(name))
+        {
+            return false;
+        }
+        else
+        {
+            _sendingLinks.put(name, link);
+            return true;
+        }
+    }
+
+    public synchronized boolean unregisterSendingLink(String name)
+    {
+        if(!_sendingLinks.containsKey(name))
+        {
+            return false;
+        }
+        else
+        {
+            _sendingLinks.remove(name);
+            return true;
+        }
+    }
+
+    public synchronized ReceivingLink_1_0 getDurableReceivingLink(String name)
+    {
+        return _receivingLinks.get(name);
+    }
+
+    public synchronized  boolean registerReceivingLink(String name, ReceivingLink_1_0 link)
+    {
+        if(_receivingLinks.containsKey(name))
+        {
+            return false;
+        }
+        else
+        {
+            _receivingLinks.put(name, link);
+            return true;
+        }
+    }
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Link_1_0.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Link_1_0.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Link_1_0.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Link_1_0.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,26 @@
+/*
+ *
+ * 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.server.protocol.v1_0;
+
+public interface Link_1_0
+{
+    void start();
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Message_1_0.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Message_1_0.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Message_1_0.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/Message_1_0.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,145 @@
+/*
+ *
+ * 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.server.protocol.v1_0;
+
+
+import org.apache.qpid.server.configuration.SessionConfig;
+import org.apache.qpid.server.message.AMQMessageHeader;
+import org.apache.qpid.server.message.InboundMessage;
+import org.apache.qpid.server.message.MessageMetaData_1_0;
+import org.apache.qpid.server.message.MessageReference;
+import org.apache.qpid.server.message.ServerMessage;
+import org.apache.qpid.server.store.StoredMessage;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+
+public class Message_1_0 implements ServerMessage<Message_1_0>, InboundMessage
+{
+    private final StoredMessage<MessageMetaData_1_0> _storedMessage;
+    private List<ByteBuffer> _fragments;
+
+
+    public Message_1_0(final StoredMessage<MessageMetaData_1_0> storedMessage, final List<ByteBuffer> fragments)
+    {
+        _storedMessage = storedMessage;
+        _fragments = fragments;
+    }
+
+    public String getRoutingKey()
+    {
+        Object routingKey = getMessageHeader().getHeader("routing-key");
+        if(routingKey != null)
+        {
+            return routingKey.toString();
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    private MessageMetaData_1_0 getMessageMetaData()
+    {
+        return _storedMessage.getMetaData();
+    }
+
+    public AMQMessageHeader getMessageHeader()
+    {
+        return getMessageMetaData().getMessageHeader();
+    }
+
+    public boolean isPersistent()
+    {
+        return getMessageMetaData().isPersistent();
+    }
+
+    public boolean isRedelivered()
+    {
+        // TODO
+        return false;
+    }
+
+    public long getSize()
+    {
+        // TODO
+        return 0l;
+    }
+
+    public boolean isImmediate()
+    {
+        return false;
+    }
+
+    public long getExpiration()
+    {
+        return getMessageHeader().getExpiration();
+    }
+
+    public MessageReference<Message_1_0> newReference()
+    {
+        return new Reference(this);
+    }
+
+    public Long getMessageNumber()
+    {
+        return _storedMessage.getMessageNumber();
+    }
+
+    public long getArrivalTime()
+    {
+        return 0;  //TODO
+    }
+
+    public int getContent(final ByteBuffer buf, final int offset)
+    {
+        return _storedMessage.getContent(offset, buf);
+    }
+
+    public SessionConfig getSessionConfig()
+    {
+        return null;  //TODO
+    }
+
+    public List<ByteBuffer> getFragments()
+    {
+        return _fragments;
+    }
+
+    public static class Reference extends MessageReference<Message_1_0>
+    {
+        public Reference(Message_1_0 message)
+        {
+            super(message);
+        }
+
+        protected void onReference(Message_1_0 message)
+        {
+
+        }
+
+        protected void onRelease(Message_1_0 message)
+        {
+
+        }
+}
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/QueueDestination.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/QueueDestination.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/QueueDestination.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/QueueDestination.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,99 @@
+/*
+ *
+ * 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.server.protocol.v1_0;
+
+import org.apache.qpid.amqp_1_0.type.Outcome;
+import org.apache.qpid.amqp_1_0.type.messaging.Accepted;
+
+import org.apache.qpid.AMQException;
+import org.apache.qpid.server.queue.AMQQueue;
+
+import org.apache.qpid.server.txn.ServerTransaction;
+
+import java.util.Arrays;
+
+public class QueueDestination implements SendingDestination, ReceivingDestination
+{
+    private static final Accepted ACCEPTED = new Accepted();
+    private static final Outcome[] OUTCOMES = new Outcome[] { ACCEPTED };
+
+
+    private AMQQueue _queue;
+
+    public QueueDestination(AMQQueue queue)
+    {
+        _queue = queue;
+    }
+
+    public Outcome[] getOutcomes()
+    {
+        return OUTCOMES;
+    }
+
+    public Outcome send(final Message_1_0 message, ServerTransaction txn)
+    {
+
+        try
+        {
+            txn.enqueue(_queue,message, new ServerTransaction.Action()
+            {
+
+
+                public void postCommit()
+                {
+                    try
+                    {
+
+                        _queue.enqueue(message);
+                    }
+                    catch (Exception e)
+                    {
+                        // TODO
+                        throw new RuntimeException(e);
+                    }
+
+                }
+
+                public void onRollback()
+                {
+                    // NO-OP
+                }
+            });
+        }
+        catch(Exception e)
+        {
+            e.printStackTrace();
+            throw new RuntimeException(e);
+        }
+        return ACCEPTED;
+    }
+
+    public int getCredit()
+    {
+        // TODO - fix
+        return 100;
+    }
+
+    public AMQQueue getQueue()
+    {
+        return _queue;
+    }
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ReceivingDestination.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ReceivingDestination.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ReceivingDestination.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ReceivingDestination.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,35 @@
+/*
+ *
+ * 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.server.protocol.v1_0;
+
+import org.apache.qpid.amqp_1_0.type.Outcome;
+
+import org.apache.qpid.server.txn.ServerTransaction;
+
+public interface ReceivingDestination extends Destination
+{
+
+    Outcome[] getOutcomes();
+
+    Outcome send(Message_1_0 message, ServerTransaction txn);
+
+    int getCredit();
+}

Added: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ReceivingLinkAttachment.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ReceivingLinkAttachment.java?rev=1157566&view=auto
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ReceivingLinkAttachment.java (added)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/v1_0/ReceivingLinkAttachment.java Sun Aug 14 17:14:51 2011
@@ -0,0 +1,51 @@
+package org.apache.qpid.server.protocol.v1_0;
+
+import org.apache.qpid.amqp_1_0.transport.DeliveryStateHandler;
+import org.apache.qpid.amqp_1_0.transport.ReceivingLinkEndpoint;
+import org.apache.qpid.amqp_1_0.transport.SendingLinkEndpoint;
+import org.apache.qpid.amqp_1_0.type.Binary;
+import org.apache.qpid.amqp_1_0.type.DeliveryState;
+import org.apache.qpid.amqp_1_0.type.Source;
+import org.apache.qpid.amqp_1_0.type.Target;
+
+public class ReceivingLinkAttachment
+{
+    private final Session_1_0         _session;
+    private final ReceivingLinkEndpoint _endpoint;
+
+    public ReceivingLinkAttachment(final Session_1_0 session, final ReceivingLinkEndpoint endpoint)
+    {
+        _session = session;
+        _endpoint = endpoint;
+    }
+
+    public Session_1_0 getSession()
+    {
+        return _session;
+    }
+
+    public ReceivingLinkEndpoint getEndpoint()
+    {
+        return _endpoint;
+    }
+
+    public Source getSource()
+    {
+        return getEndpoint().getSource();
+    }
+
+    public void setDeliveryStateHandler(final DeliveryStateHandler handler)
+    {
+        getEndpoint().setDeliveryStateHandler(handler);
+    }
+
+    public void updateDisposition(final Binary deliveryTag, final DeliveryState state, final boolean settled)
+    {
+        getEndpoint().updateDisposition(deliveryTag, state, settled);
+    }
+
+    public Target getTarget()
+    {
+        return getEndpoint().getTarget();
+    }
+}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org