diff options
author | Kim van der Riet <kpvdr@apache.org> | 2007-01-23 14:23:25 +0000 |
---|---|---|
committer | Kim van der Riet <kpvdr@apache.org> | 2007-01-23 14:23:25 +0000 |
commit | ceb6f31cdde10e52f0caa4c4bdd396700a262dee (patch) | |
tree | c86046c5000567094da60cf09ca2fc122f62429d | |
parent | 2801b3827c07062ca30b6c246d0c057ebb971777 (diff) | |
download | qpid-python-ceb6f31cdde10e52f0caa4c4bdd396700a262dee.tar.gz |
Modified Content to make get methods to be non-consuming through use of light-weight copys. Shortened name of Content type enum.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/qpid.0-9@499030 13f79535-47bb-0310-9956-ffa450edef68
7 files changed, 46 insertions, 34 deletions
diff --git a/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java b/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java index 47288884f3..7c161522ca 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java +++ b/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java @@ -193,10 +193,10 @@ public class AMQChannel message.setPublisher(publisher); Content body = transferBody.getBody(); switch (body.getContentType()) { - case CONTENT_TYPE_INLINE: + case INLINE_T: route(message); break; - case CONTENT_TYPE_REFERENCE: + case REF_T: getMessages(body.getContentAsByteArray()).add(message); break; } diff --git a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java index 44994fe161..9a228b48d4 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java +++ b/java/broker/src/main/java/org/apache/qpid/server/queue/AMQMessage.java @@ -139,7 +139,7 @@ public class AMQMessage int size = _transferBody.getBodySize(); Content body = _transferBody.getBody(); switch (body.getContentType()) { - case CONTENT_TYPE_INLINE: + case INLINE_T: size -= _transferBody.getBody().getEncodedSize(); break; } @@ -149,9 +149,9 @@ public class AMQMessage public long getBodySize() { Content body = _transferBody.getBody(); switch (body.getContentType()) { - case CONTENT_TYPE_INLINE: + case INLINE_T: return _transferBody.getBody().getContent().limit(); - case CONTENT_TYPE_REFERENCE: + case REF_T: return getReferenceSize(); default: throw new IllegalStateException("unrecognized type: " + body.getContentType()); diff --git a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java index b667eb0242..dba8049657 100644 --- a/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java +++ b/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java @@ -577,7 +577,7 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j // Inline message case _logger.debug("Inline case, sending data inline with the transfer method"); - Content data = new Content(Content.ContentTypeEnum.CONTENT_TYPE_INLINE,payload); + Content data = new Content(Content.TypeEnum.INLINE_T, payload); doMessageTransfer(messageHeaders,destination,data,message,deliveryMode,priority,timeToLive,immediate); } else { @@ -598,7 +598,7 @@ public class BasicMessageProducer extends Closeable implements org.apache.qpid.j doMessageOpen(referenceId); // Message.Transfer - Content data = new Content(Content.ContentTypeEnum.CONTENT_TYPE_REFERENCE,referenceId.getBytes()); + Content data = new Content(Content.TypeEnum.REF_T, referenceId.getBytes()); doMessageTransfer(messageHeaders,destination,data,message,deliveryMode,priority,timeToLive,immediate); //Message.Append diff --git a/java/client/src/main/java/org/apache/qpid/client/handler/MessageTransferMethodHandler.java b/java/client/src/main/java/org/apache/qpid/client/handler/MessageTransferMethodHandler.java index fa31bc8056..f4e917a943 100644 --- a/java/client/src/main/java/org/apache/qpid/client/handler/MessageTransferMethodHandler.java +++ b/java/client/src/main/java/org/apache/qpid/client/handler/MessageTransferMethodHandler.java @@ -75,7 +75,7 @@ public class MessageTransferMethodHandler implements StateAwareMethodListener msg.contentHeader = messageHeaders; - if(transferBody.getBody().contentType == Content.ContentTypeEnum.CONTENT_TYPE_INLINE) + if(transferBody.getBody().contentType == Content.TypeEnum.INLINE_T) { msg.addContent(transferBody.getBody().getContentAsByteArray()); protocolSession.deliverMessageToAMQSession(evt.getChannelId(), msg); diff --git a/java/common/src/main/java/org/apache/qpid/framing/Content.java b/java/common/src/main/java/org/apache/qpid/framing/Content.java index 4448ef3ae5..222500aa8a 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/Content.java +++ b/java/common/src/main/java/org/apache/qpid/framing/Content.java @@ -24,38 +24,38 @@ import org.apache.mina.common.ByteBuffer; public class Content { - public enum ContentTypeEnum + public enum TypeEnum { - CONTENT_TYPE_INLINE((byte)0), CONTENT_TYPE_REFERENCE((byte)1); + INLINE_T((byte)0), REF_T((byte)1); private byte type; - ContentTypeEnum(byte type) { this.type = type; } + TypeEnum(byte type) { this.type = type; } public byte toByte() { return type; } - public static ContentTypeEnum toContentEnum(byte b) + public static TypeEnum toContentEnum(byte b) { switch (b) { - case 0: return CONTENT_TYPE_INLINE; - case 1: return CONTENT_TYPE_REFERENCE; + case 0: return INLINE_T; + case 1: return REF_T; default: throw new IllegalArgumentException("Illegal value " + b + - ", not represented in ContentTypeEnum."); + ", not represented in TypeEnum."); } } } - public ContentTypeEnum contentType; + public TypeEnum contentType; public ByteBuffer content; // Constructors public Content() { - contentType = ContentTypeEnum.CONTENT_TYPE_INLINE; // default + contentType = TypeEnum.INLINE_T; // default content = null; } - public Content(ContentTypeEnum contentType, byte[] content) + public Content(TypeEnum contentType, byte[] content) { - if (contentType == ContentTypeEnum.CONTENT_TYPE_REFERENCE) + if (contentType == TypeEnum.REF_T) { if (content == null) throw new IllegalArgumentException("Content cannot be null for a ref type."); @@ -67,14 +67,14 @@ public class Content this.content.put(content); } - public Content(ContentTypeEnum contentType, String contentStr) + public Content(TypeEnum contentType, String contentStr) { this(contentType, contentStr.getBytes()); } - public Content(ContentTypeEnum contentType, ByteBuffer content) + public Content(TypeEnum contentType, ByteBuffer content) { - if (contentType == ContentTypeEnum.CONTENT_TYPE_REFERENCE) + if (contentType == TypeEnum.REF_T) { if (content == null) throw new IllegalArgumentException("Content cannot be null for a ref type."); @@ -87,13 +87,21 @@ public class Content // Get functions - public ContentTypeEnum getContentType() { return contentType; } - public ByteBuffer getContent() { return content; } + public TypeEnum getContentType() + { + return contentType; + } + + public ByteBuffer getContent() + { + return content.duplicate(); + } public byte[] getContentAsByteArray() { - byte[] ba = new byte[content.remaining()]; - content.get(ba); + ByteBuffer dup = content.duplicate().rewind(); + byte[] ba = new byte[dup.remaining()]; + dup.get(ba); return ba; } @@ -122,7 +130,7 @@ public class Content public void populateFromBuffer(ByteBuffer buffer) throws AMQFrameDecodingException { - contentType = ContentTypeEnum.toContentEnum(buffer.get()); + contentType = TypeEnum.toContentEnum(buffer.get()); int length = buffer.getInt(); content = buffer.slice(); buffer.skip(length); @@ -131,11 +139,6 @@ public class Content public synchronized String toString() { - int position = content.position(); - content.flip(); - String tmp = content.toString(); - content.position(position); - - return tmp; + return getContent().rewind().toString(); } } diff --git a/java/common/src/main/java/org/apache/qpid/framing/RequestManager.java b/java/common/src/main/java/org/apache/qpid/framing/RequestManager.java index ca8735cb62..f7178742f9 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/RequestManager.java +++ b/java/common/src/main/java/org/apache/qpid/framing/RequestManager.java @@ -80,6 +80,8 @@ public class RequestManager logger.debug((serverFlag ? "SRV" : "CLI") + " TX REQ: ch=" + channel + " Req[" + requestId + " " + lastProcessedResponseId + "]; " + requestMethodBody); } + //System.out.println((serverFlag ? "SRV" : "CLI") + " TX REQ: ch=" + channel + + // " Req[" + requestId + " " + lastProcessedResponseId + "]; " + requestMethodBody); return requestId; } @@ -93,6 +95,8 @@ public class RequestManager logger.debug((serverFlag ? "SRV" : "CLI") + " RX RES: ch=" + channel + " " + responseBody + "; " + responseBody.getMethodPayload()); } + //System.out.println((serverFlag ? "SRV" : "CLI") + " RX RES: ch=" + channel + + // " " + responseBody + "; " + responseBody.getMethodPayload()); for (long requestId = requestIdStart; requestId <= requestIdStop; requestId++) { AMQMethodListener methodListener = requestSentMap.get(requestId); diff --git a/java/common/src/main/java/org/apache/qpid/framing/ResponseManager.java b/java/common/src/main/java/org/apache/qpid/framing/ResponseManager.java index 8bc526900a..f7dea180b8 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/ResponseManager.java +++ b/java/common/src/main/java/org/apache/qpid/framing/ResponseManager.java @@ -122,11 +122,14 @@ public class ResponseManager logger.debug((serverFlag ? "SRV" : "CLI") + " RX REQ: ch=" + channel + " " + requestBody + "; " + requestBody.getMethodPayload()); } + //System.out.println((serverFlag ? "SRV" : "CLI") + " RX REQ: ch=" + channel + + // " " + requestBody + "; " + requestBody.getMethodPayload()); // TODO: responseMark is used in HA, but until then, ignore... long responseMark = requestBody.getResponseMark(); lastReceivedRequestId = requestId; responseMap.put(requestId, new ResponseStatus(requestId)); - AMQMethodEvent methodEvent = new AMQMethodEvent(channel, requestBody.getMethodPayload(), requestId); + AMQMethodEvent methodEvent = new AMQMethodEvent(channel, + requestBody.getMethodPayload(), requestId); methodListener.methodReceived(methodEvent); } @@ -138,6 +141,8 @@ public class ResponseManager logger.debug((serverFlag ? "SRV" : "CLI") + " TX RES: ch=" + channel + " Res[# " + requestId + "]; " + responseMethodBody); } + //System.out.println((serverFlag ? "SRV" : "CLI") + " TX RES: ch=" + channel + + // " Res[# " + requestId + "]; " + responseMethodBody); ResponseStatus responseStatus = responseMap.get(requestId); if (responseStatus == null) throw new RequestResponseMappingException(requestId, |