diff options
| author | Kim van der Riet <kpvdr@apache.org> | 2007-01-05 19:37:18 +0000 |
|---|---|---|
| committer | Kim van der Riet <kpvdr@apache.org> | 2007-01-05 19:37:18 +0000 |
| commit | 0fe65867ec72e6e3ff10a1ac817a734bd416b3a6 (patch) | |
| tree | 6a89d4d66b3097e3f2b3c4a47689cc4b34969b17 /java/common | |
| parent | 2d407db755d9d23d87794c676895d81460f61716 (diff) | |
| download | qpid-python-0fe65867ec72e6e3ff10a1ac817a734bd416b3a6.tar.gz | |
New framing classes for AMQP 0-9 request and response
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/qpid.0-9@493157 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common')
| -rw-r--r-- | java/common/src/main/java/org/apache/qpid/framing/AMQRequest.java | 86 | ||||
| -rw-r--r-- | java/common/src/main/java/org/apache/qpid/framing/AMQResponse.java | 86 |
2 files changed, 172 insertions, 0 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQRequest.java b/java/common/src/main/java/org/apache/qpid/framing/AMQRequest.java new file mode 100644 index 0000000000..821b5d177d --- /dev/null +++ b/java/common/src/main/java/org/apache/qpid/framing/AMQRequest.java @@ -0,0 +1,86 @@ +/* + * + * 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.framing; + +import org.apache.mina.common.ByteBuffer; + +public class AMQRequest extends AMQBody +{ + public static final byte TYPE = (byte)AmqpConstants.frameRequestAsInt(); + + // Fields declared in specification + public long requestId; + public long responseMark; + public AMQMethodBody methodPayload; + + + // Constructor + public AMQRequest() {} + + // Field methods + + public long getRequestId() { return requestId; } + public long getResponseMark() { return responseMark; } + public AMQMethodBody getMethodPayload() { return methodPayload; } + + + protected byte getFrameType() + { + return TYPE; + } + + protected int getSize() + { + return 8 + 8 + 4 + methodPayload.getBodySize(); + } + + protected void writePayload(ByteBuffer buffer) + { + EncodingUtils.writeLong(buffer, requestId); + EncodingUtils.writeLong(buffer, responseMark); + EncodingUtils.writeUnsignedShort(buffer, 0); // reserved, set to 0 + methodPayload.writePayload(buffer); + } + + protected void populateFromBuffer(ByteBuffer buffer, long size) + throws AMQFrameDecodingException, AMQProtocolVersionException + { + requestId = EncodingUtils.readLong(buffer); + responseMark = EncodingUtils.readLong(buffer); + int reserved = EncodingUtils.readShort(buffer); // reserved, throw away + methodPayload.populateFromBuffer(buffer, size - 8 - 8 - 4); + } + + public static AMQFrame createAMQFrame(int channelId, long requestId, + long responseMark, AMQMethodBody methodPayload) + { + AMQResponse responseFrame = new AMQResponse(); + responseFrame.requestId = requestId; + responseFrame.responseMark = responseMark; + responseFrame.methodPayload = methodPayload; + + + AMQFrame frame = new AMQFrame(); + frame.channel = channelId; + frame.bodyFrame = responseFrame; + return frame; + } +} diff --git a/java/common/src/main/java/org/apache/qpid/framing/AMQResponse.java b/java/common/src/main/java/org/apache/qpid/framing/AMQResponse.java new file mode 100644 index 0000000000..bf4bec8cda --- /dev/null +++ b/java/common/src/main/java/org/apache/qpid/framing/AMQResponse.java @@ -0,0 +1,86 @@ +/* + * + * 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.framing; + +import org.apache.mina.common.ByteBuffer; + +public class AMQResponse extends AMQBody +{ + public static final byte TYPE = (byte)AmqpConstants.frameResponseAsInt(); + + // Fields declared in specification + public long requestId; + public long responseMark; + public int batchOffset; + public AMQMethodBody methodPayload; + + // Constructor + public AMQResponse() {} + + // Field methods + + public long getRequestId() { return requestId; } + public long getResponseMark() { return responseMark; } + public int getBatchOffset() { return batchOffset; } + public AMQMethodBody getMethodPayload() { return methodPayload; } + + protected byte getFrameType() + { + return TYPE; + } + + protected int getSize() + { + return 8 + 8 + 4 + methodPayload.getBodySize(); + } + + protected void writePayload(ByteBuffer buffer) + { + EncodingUtils.writeLong(buffer, requestId); + EncodingUtils.writeLong(buffer, responseMark); + EncodingUtils.writeUnsignedShort(buffer, batchOffset); + methodPayload.writePayload(buffer); + } + + protected void populateFromBuffer(ByteBuffer buffer, long size) + throws AMQFrameDecodingException, AMQProtocolVersionException + { + requestId = EncodingUtils.readLong(buffer); + responseMark = EncodingUtils.readLong(buffer); + batchOffset = EncodingUtils.readShort(buffer); + methodPayload.populateFromBuffer(buffer, size - 8 - 8 - 4); + } + + public static AMQFrame createAMQFrame(int channelId, long requestId, + long responseMark, int batchOffset, AMQMethodBody methodPayload) + { + AMQResponse responseFrame = new AMQResponse(); + responseFrame.requestId = requestId; + responseFrame.responseMark = responseMark; + responseFrame.batchOffset = batchOffset; + responseFrame.methodPayload = methodPayload; + + AMQFrame frame = new AMQFrame(); + frame.channel = channelId; + frame.bodyFrame = responseFrame; + return frame; + } +} |
