You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2007/07/25 16:08:10 UTC
svn commit: r559465 - in /incubator/qpid/trunk/qpid/java/common: ./
src/main/java/org/apache/qpidity/
Author: rhs
Date: Wed Jul 25 07:08:08 2007
New Revision: 559465
URL: http://svn.apache.org/viewvc?view=rev&rev=559465
Log:
added support for precomputing sizes
Added:
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/AbstractStruct.java (with props)
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/SizeEncoder.java (with props)
Modified:
incubator/qpid/trunk/qpid/java/common/generate
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/AbstractMethod.java
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Frame.java
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Method.java
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Stub.java
Modified: incubator/qpid/trunk/qpid/java/common/generate
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/generate?view=diff&rev=559465&r1=559464&r2=559465
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/generate (original)
+++ incubator/qpid/trunk/qpid/java/common/generate Wed Jul 25 07:08:08 2007
@@ -112,7 +112,7 @@
(self.name, isfx, self.name))
out.line()
- out.line(" public int getEncodingType() {")
+ out.line(" public int getEncodedType() {")
out.line(" return TYPE;")
out.line(" }")
Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/AbstractMethod.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/AbstractMethod.java?view=diff&rev=559465&r1=559464&r2=559465
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/AbstractMethod.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/AbstractMethod.java Wed Jul 25 07:08:08 2007
@@ -28,4 +28,4 @@
* @author Rafael H. Schloming
*/
-abstract class AbstractMethod implements Method {}
+abstract class AbstractMethod extends AbstractStruct implements Method {}
Added: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/AbstractStruct.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/AbstractStruct.java?view=auto&rev=559465
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/AbstractStruct.java (added)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/AbstractStruct.java Wed Jul 25 07:08:08 2007
@@ -0,0 +1,30 @@
+/*
+ *
+ * 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.qpidity;
+
+
+/**
+ * AbstractStruct
+ *
+ * @author Rafael H. Schloming
+ */
+
+public abstract class AbstractStruct implements Struct {}
Propchange: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/AbstractStruct.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Frame.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Frame.java?view=diff&rev=559465&r1=559464&r2=559465
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Frame.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Frame.java Wed Jul 25 07:08:08 2007
@@ -116,8 +116,7 @@
{
StringBuilder str = new StringBuilder();
str.append(String.format
- ("[%05d %05d %1d %1d %d%d%d%d]", channel, track, type,
- getSize(),
+ ("[%05d %05d %1d %1d %d%d%d%d]", channel, getSize(), track, type,
firstSegment ? 1 : 0, lastSegment ? 1 : 0,
firstFrame ? 1 : 0, lastFrame ? 1 : 0));
ShortBuffer shorts = payload.asShortBuffer();
Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Method.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Method.java?view=diff&rev=559465&r1=559464&r2=559465
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Method.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Method.java Wed Jul 25 07:08:08 2007
@@ -29,6 +29,6 @@
interface Method extends Struct {
- int getEncodingType();
+ int getEncodedType();
}
Added: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/SizeEncoder.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/SizeEncoder.java?view=auto&rev=559465
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/SizeEncoder.java (added)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/SizeEncoder.java Wed Jul 25 07:08:08 2007
@@ -0,0 +1,122 @@
+/*
+ *
+ * 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.qpidity;
+
+import java.nio.ByteBuffer;
+
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * SizeEncoder
+ *
+ * @author Rafael H. Schloming
+ */
+
+class SizeEncoder implements Encoder
+{
+
+ private int size;
+
+ public SizeEncoder() {
+ this(0);
+ }
+
+ public SizeEncoder(int size) {
+ this.size = size;
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public void setSize(int size) {
+ this.size = size;
+ }
+
+ public void writeBit(boolean b)
+ {
+ //throw new Error("TODO");
+ }
+
+ public void writeOctet(byte b)
+ {
+ size += 1;
+ }
+
+ public void writeShort(short s)
+ {
+ size += 2;
+ }
+
+ public void writeLong(int i)
+ {
+ size += 4;
+ }
+
+ public void writeLonglong(long l)
+ {
+ size += 8;
+ }
+
+
+ public void writeTimestamp(long l)
+ {
+ size += 8;
+ }
+
+
+ public void writeShortstr(String s)
+ {
+ if (s.length() > 255) {
+ throw new IllegalArgumentException(s);
+ }
+ writeOctet((byte) s.length());
+ size += s.length();
+ }
+
+ public void writeLongstr(String s)
+ {
+ throw new Error("TODO");
+ }
+
+
+ public void writeTable(Map<String,?> table)
+ {
+ //throw new Error("TODO");
+ }
+
+ public void writeRfc1982LongSet(Range<Integer>[] ranges)
+ {
+ throw new Error("TODO");
+ }
+
+ public void writeUuid(UUID uuid)
+ {
+ throw new Error("TODO");
+ }
+
+ public void writeContent(String c)
+ {
+ throw new Error("TODO");
+ }
+
+}
Propchange: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/SizeEncoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Stub.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Stub.java?view=diff&rev=559465&r1=559464&r2=559465
==============================================================================
--- incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Stub.java (original)
+++ incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpidity/Stub.java Wed Jul 25 07:08:08 2007
@@ -15,9 +15,13 @@
}
private static void frame(short track, short type, boolean first, boolean last, Method m) {
- ByteBuffer buf = ByteBuffer.allocate(512);
+ SizeEncoder sizer = new SizeEncoder();
if (m != null) {
- buf.putInt(m.getEncodingType());
+ m.write(sizer);
+ }
+ ByteBuffer buf = ByteBuffer.allocate(sizer.getSize() + 4);
+ if (m != null) {
+ buf.putInt(m.getEncodedType());
m.write(new BBEncoder(buf));
}
buf.flip();
@@ -29,7 +33,7 @@
StructFactory f = new StructFactory_v0_10();
frame(Frame.L2, Frame.METHOD, true, true, f.newSessionOpen(0));
frame(Frame.L4, Frame.METHOD, true, false,
- f.newQueueDeclare((short) 0, "asdf", "alternate", null, DURABLE));
+ f.newQueueDeclare((short) 0, "asdf", "alternate", null, DURABLE));
frame(Frame.L4, Frame.METHOD, false, false);
frame(Frame.L3, Frame.METHOD, true, true,
f.newExchangeDeclare((short) 0, "exchange", "type", "alternate", null));