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 /java/common | |
| 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
Diffstat (limited to 'java/common')
3 files changed, 38 insertions, 26 deletions
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, |
