You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ra...@apache.org on 2015/08/14 21:07:40 UTC
[07/50] [abbrv] qpid-proton git commit: Added more skeleton code to
flush out the new approach. Using POJOBuilder and a lookup to construct the
Performative. Further changes are planned to avoid constructing a list and
instead directly construct the obje
Added more skeleton code to flush out the new approach.
Using POJOBuilder and a lookup to construct the Performative.
Further changes are planned to avoid constructing a list and instead directly construct the object from the Decoder by pulling relevant bits. For that to happen we need a hybrid parser that does both push/pull style.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/98807684
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/98807684
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/98807684
Branch: refs/heads/rajith-codec
Commit: 988076842984b2ec0b77a25a0182af1eb79965ef
Parents: 40607e4
Author: Rajith Attapattu <ra...@apache.org>
Authored: Mon Feb 2 13:34:32 2015 -0500
Committer: Rajith Attapattu <ra...@apache.org>
Committed: Thu Jul 9 09:12:37 2015 -0400
----------------------------------------------------------------------
.../qpid/proton/amqp/transport2/Flow.java | 158 ++++++++++++++-----
.../qpid/proton/codec2/DecodeException.java | 36 +++++
.../org/apache/qpid/proton/codec2/Decoder.java | 13 +-
.../apache/qpid/proton/codec2/Encodable.java | 26 +++
.../apache/qpid/proton/codec2/POJOBuilder.java | 23 ++-
.../qpid/proton/codec2/PerformativeFactory.java | 26 +++
.../proton/codec2/TransportTypesDecoder.java | 102 ------------
.../proton/codec2/TransportTypesEncoder.java | 62 --------
.../apache/qpid/proton/codec2/TypeRegistry.java | 63 ++++++++
9 files changed, 301 insertions(+), 208 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/98807684/proton-j/src/main/java/org/apache/qpid/proton/amqp/transport2/Flow.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/amqp/transport2/Flow.java b/proton-j/src/main/java/org/apache/qpid/proton/amqp/transport2/Flow.java
index 388cbef..714ef3c 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/amqp/transport2/Flow.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/amqp/transport2/Flow.java
@@ -1,42 +1,57 @@
-
/*
-*
-* 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.
-*
-*/
+ *
+ * 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.proton.amqp.transport2;
+import java.util.List;
import java.util.Map;
-public class Flow
+import org.apache.qpid.proton.codec2.DecodeException;
+import org.apache.qpid.proton.codec2.Encodable;
+import org.apache.qpid.proton.codec2.Encoder;
+import org.apache.qpid.proton.codec2.PerformativeFactory;
+
+public class Flow implements Encodable
{
private long _nextIncomingId;
+
private long _incomingWindow;
+
private long _nextOutgoingId;
+
private long _outgoingWindow;
+
private long _handle;
+
private long _deliveryCount;
+
private long _linkCredit;
+
private long _available;
+
private boolean _drain;
+
private boolean _echo;
- private Map _properties;
+
+ private Map<Object, Object> _properties;
public long getNextIncomingId()
{
@@ -75,7 +90,7 @@ public class Flow
public void setOutgoingWindow(long outgoingWindow)
{
- _outgoingWindow = outgoingWindow;
+ _outgoingWindow = outgoingWindow;
}
public long getHandle()
@@ -138,12 +153,12 @@ public class Flow
_echo = echo;
}
- public Map getProperties()
+ public Map<Object, Object> getProperties()
{
return _properties;
}
- public void setProperties(Map properties)
+ public void setProperties(Map<Object, Object> properties)
{
_properties = properties;
}
@@ -151,18 +166,85 @@ public class Flow
@Override
public String toString()
{
- return "Flow{" +
- "nextIncomingId=" + _nextIncomingId +
- ", incomingWindow=" + _incomingWindow +
- ", nextOutgoingId=" + _nextOutgoingId +
- ", outgoingWindow=" + _outgoingWindow +
- ", handle=" + _handle +
- ", deliveryCount=" + _deliveryCount +
- ", linkCredit=" + _linkCredit +
- ", available=" + _available +
- ", drain=" + _drain +
- ", echo=" + _echo +
- ", properties=" + _properties +
- '}';
+ return "Flow{" + "nextIncomingId=" + _nextIncomingId + ", incomingWindow=" + _incomingWindow
+ + ", nextOutgoingId=" + _nextOutgoingId + ", outgoingWindow=" + _outgoingWindow + ", handle=" + _handle
+ + ", deliveryCount=" + _deliveryCount + ", linkCredit=" + _linkCredit + ", available=" + _available
+ + ", drain=" + _drain + ", echo=" + _echo + ", properties=" + _properties + '}';
+ }
+
+ @Override
+ public void encode(Encoder encoder)
+ {
+ encoder.putDescriptor();
+ encoder.putUlong(0x0000000000000013L);
+ encoder.putList();
+ // unsigned int ?
+ encoder.putLong(_nextIncomingId);
+ encoder.putLong(_incomingWindow);
+ encoder.putLong(_nextOutgoingId);
+ encoder.putLong(_outgoingWindow);
+ encoder.putLong(_handle);
+ encoder.putLong(_deliveryCount);
+ encoder.putLong(_linkCredit);
+ encoder.putLong(_available);
+ if (_drain)
+ {
+ encoder.putBoolean(true);
+ }
+ if (_echo)
+ {
+ encoder.putBoolean(true);
+ }
+ if (_properties != null && _properties.size() > 0)
+ {
+ encoder.putMap();
+ // ..... handle map
+ encoder.end();
+ }
+ encoder.end();
+ }
+
+ public static final class Factory implements PerformativeFactory
+ {
+ public Object create(Object in) throws DecodeException
+ {
+ List<Object> l = (List<Object>) in;
+
+ if (l.size() <= 3)
+ {
+ throw new DecodeException("The outgoing-window field cannot be omitted");
+ }
+
+ Flow flow = new Flow();
+
+ switch (11 - l.size())
+ {
+
+ case 0:
+ flow.setProperties(((Map<Object, Object>) l.get(10)));
+ case 1:
+ flow.setEcho(l.get(9) == null ? false : (Boolean) l.get(9));
+ case 2:
+ flow.setDrain(l.get(8) == null ? false : (Boolean) l.get(8));
+ case 3:
+ flow.setAvailable((int) l.get(7));
+ case 4:
+ flow.setLinkCredit((int) l.get(6));
+ case 5:
+ flow.setDeliveryCount((int) l.get(5));
+ case 6:
+ flow.setHandle((int) l.get(4));
+ case 7:
+ flow.setOutgoingWindow((int) l.get(3));
+ case 8:
+ flow.setNextOutgoingId((int) l.get(2));
+ case 9:
+ flow.setIncomingWindow((int) l.get(1));
+ case 10:
+ flow.setNextIncomingId((int) l.get(0));
+ }
+
+ return flow;
+ }
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/98807684/proton-j/src/main/java/org/apache/qpid/proton/codec2/DecodeException.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec2/DecodeException.java b/proton-j/src/main/java/org/apache/qpid/proton/codec2/DecodeException.java
new file mode 100644
index 0000000..f568542
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec2/DecodeException.java
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.proton.codec2;
+
+@SuppressWarnings("serial")
+public class DecodeException extends Exception
+{
+
+ public DecodeException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public DecodeException(String message)
+ {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/98807684/proton-j/src/main/java/org/apache/qpid/proton/codec2/Decoder.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec2/Decoder.java b/proton-j/src/main/java/org/apache/qpid/proton/codec2/Decoder.java
index d61fdef..5a14081 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec2/Decoder.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec2/Decoder.java
@@ -20,18 +20,22 @@
*/
package org.apache.qpid.proton.codec2;
+
/**
* Decoder
- *
+ *
*/
public interface Decoder
{
-
Type getType();
int getSize();
+ byte getByte();
+
+ short getShort();
+
int getInt();
long getLong();
@@ -50,4 +54,9 @@ public interface Decoder
long getLoBits();
+ boolean getBoolean();
+
+ char getChar();
+
+ void decode(DataHandler handler);
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/98807684/proton-j/src/main/java/org/apache/qpid/proton/codec2/Encodable.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec2/Encodable.java b/proton-j/src/main/java/org/apache/qpid/proton/codec2/Encodable.java
new file mode 100644
index 0000000..4d749e1
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec2/Encodable.java
@@ -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.proton.codec2;
+
+public interface Encodable
+{
+ void encode(Encoder encoder);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/98807684/proton-j/src/main/java/org/apache/qpid/proton/codec2/POJOBuilder.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec2/POJOBuilder.java b/proton-j/src/main/java/org/apache/qpid/proton/codec2/POJOBuilder.java
index c95844b..0e04cd5 100644
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec2/POJOBuilder.java
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec2/POJOBuilder.java
@@ -29,7 +29,6 @@ import java.util.*;
public class POJOBuilder implements DataHandler
{
-
public static class Described {
private Object descriptor;
@@ -62,7 +61,7 @@ public class POJOBuilder implements DataHandler
private class DescribedBuilder implements Builder {
private Object descriptor;
- private Described described;
+ private Object described;
private boolean first = true;
public DescribedBuilder() {}
@@ -72,12 +71,28 @@ public class POJOBuilder implements DataHandler
descriptor = o;
first = false;
} else {
- described = new Described(descriptor, o);
+ PerformativeFactory factory = TypeRegistry.lookup(descriptor);
+ if (factory != null)
+ {
+ try
+ {
+ described = factory.create(o);
+ }
+ catch (DecodeException e)
+ {
+ // TODO handle exception
+ e.printStackTrace();
+ }
+ }
+ else
+ {
+ described = new Described(descriptor, o);
+ }
end();
}
}
- public Described build() {
+ public Object build() {
return described;
}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/98807684/proton-j/src/main/java/org/apache/qpid/proton/codec2/PerformativeFactory.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec2/PerformativeFactory.java b/proton-j/src/main/java/org/apache/qpid/proton/codec2/PerformativeFactory.java
new file mode 100644
index 0000000..e428207
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec2/PerformativeFactory.java
@@ -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.proton.codec2;
+
+public interface PerformativeFactory
+{
+ public Object create(Object in) throws DecodeException;
+}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/98807684/proton-j/src/main/java/org/apache/qpid/proton/codec2/TransportTypesDecoder.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec2/TransportTypesDecoder.java b/proton-j/src/main/java/org/apache/qpid/proton/codec2/TransportTypesDecoder.java
deleted file mode 100644
index a262760..0000000
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec2/TransportTypesDecoder.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- *
- * 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.proton.codec2;
-
-import org.apache.qpid.proton.amqp.transport2.Flow;
-
-public class TransportTypesDecoder
-{
- public static Open decodeOpen(Decoder decoder)
- {
-
- }
-
- public static Flow decodeFlow(Decoder decoder)
- {
- final Flow flow = new Flow();
- DataHandler dh = new AbstractDataHandler()
- {
-
- int index = 0;
-
- public void onLong(org.apache.qpid.proton.codec2.Decoder d)
- {
- switch (index)
- {
- case 0:
- flow.setNextIncomingId(d.getLongBits());
- index++;
- break;
- case 1:
- flow.setIncomingWindow(d.getLongBits());
- index++;
- break;
- case 2:
- flow.setNextOutgoingId(d.getLongBits());
- index++;
- break;
- case 3:
- flow.setOutgoingWindow(d.getLongBits());
- index++;
- break;
- case 4:
- flow.setHandle(d.getLongBits());
- index++;
- break;
- case 5:
- flow.setDeliveryCount(d.getLongBits());
- index++;
- break;
- case 6:
- flow.setLinkCredit(d.getLongBits());
- index++;
- break;
- case 7:
- flow.setAvailable(d.getLongBits());
- index++;
- break;
- }
- }
-
- public void onBoolean(org.apache.qpid.proton.codec2.Decoder d)
- {
- switch (index)
- {
- case 8:
- flow.setDrain(); // what should be used here?
- index++;
- break;
- case 9:
- flow.setEcho(); // what should be used here?
- index++;
- break;
- }
- }
-
- public void onMap(org.apache.qpid.proton.codec2.Decoder d)
- {
- flow.setProperties(decodeMap(d)); //
- }
- };
-
- return flow;
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/98807684/proton-j/src/main/java/org/apache/qpid/proton/codec2/TransportTypesEncoder.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec2/TransportTypesEncoder.java b/proton-j/src/main/java/org/apache/qpid/proton/codec2/TransportTypesEncoder.java
deleted file mode 100644
index c7c888c..0000000
--- a/proton-j/src/main/java/org/apache/qpid/proton/codec2/TransportTypesEncoder.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- *
- * 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.proton.codec2;
-
-import org.apache.qpid.proton.amqp.transport2.Flow;
-
-public class TransportTypesEncoder
-{
- public static void encodeOpen(Encoder encoder, Open open)
- {
-
- }
-
- public static void encodeFlow(Encoder encoder, Flow flow)
- {
- encoder.putDescriptor();
- encoder.putUlong(0x0000000000000013L);
- encoder.putList();
- // unsigned int ?
- encoder.putLong(flow.getNextIncomingId());
- encoder.putLong(flow.getIncomingWindow());
- encoder.putLong(flow.getNextOutgoingId());
- encoder.putLong(flow.getOutgoingWindow());
- encoder.putLong(flow.getHandle());
- encoder.putLong(flow.getDeliveryCount());
- encoder.putLong(flow.getLinkCredit());
- encoder.putLong(flow.getAvailable());
- if (flow.getDrain())
- {
- encoder.putBoolean(true);
- }
- if (flow.getEcho())
- {
- encoder.putBoolean(true);
- }
- if (flow.getProperties() != null && flow.getProperties().size() > 0)
- {
- encoder.putMap();
- // ..... handle map
- encoder.end();
- }
- encoder.end();
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/98807684/proton-j/src/main/java/org/apache/qpid/proton/codec2/TypeRegistry.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/codec2/TypeRegistry.java b/proton-j/src/main/java/org/apache/qpid/proton/codec2/TypeRegistry.java
new file mode 100644
index 0000000..85eb4aa
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/codec2/TypeRegistry.java
@@ -0,0 +1,63 @@
+/*
+ *
+ * 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.proton.codec2;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TypeRegistry
+{
+ private static Map<String, PerformativeFactory> _typeRegByStrCode = new HashMap<String, PerformativeFactory>();
+
+ private static Map<Long, PerformativeFactory> _typeRegByLongCode = new HashMap<Long, PerformativeFactory>();
+
+ public static void registerType(long longCode, String strCode, PerformativeFactory factory)
+ {
+ _typeRegByStrCode.put(strCode, factory);
+ _typeRegByLongCode.put(longCode, factory);
+ }
+
+ public static PerformativeFactory lookup(Object code)
+ {
+ if (code instanceof Long)
+ {
+ return lookup((Long) code);
+ }
+ else if (code instanceof String)
+ {
+ return lookup((String) code);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ static PerformativeFactory lookup(long code)
+ {
+ return _typeRegByLongCode.get(code);
+ }
+
+ static PerformativeFactory lookup(String code)
+ {
+ return _typeRegByStrCode.get(code);
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org