You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2013/02/03 23:57:26 UTC
svn commit: r1441982 - in /qpid/proton/trunk: proton-c/bindings/java/
proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/
proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/
proton-c/bindings/java/src/main/java/org/apa...
Author: rgodfrey
Date: Sun Feb 3 22:57:25 2013
New Revision: 1441982
URL: http://svn.apache.org/viewvc?rev=1441982&view=rev
Log:
PROTON-192 : Add initial support for Messenger and Data to the Java/JNI Binding
Added:
qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/
qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/
qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java
qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIDataFactory.java
qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/messenger/jni/JNIMessenger.java
qpid/proton/trunk/proton-c/bindings/java/src/main/resources/META-INF/services/org.apache.qpid.proton.codec.DataFactory
- copied, changed from r1441742, qpid/proton/trunk/proton-c/bindings/java/src/main/resources/META-INF/services/org.apache.qpid.proton.engine.EngineFactory
qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/UnknownDescribedType.java
qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/codec/
qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/codec/Data.java
qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/codec/DataFactory.java
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataFactoryImpl.java
qpid/proton/trunk/proton-j/proton/src/main/resources/META-INF/services/org.apache.qpid.proton.codec.DataFactory
Modified:
qpid/proton/trunk/proton-c/bindings/java/java.i
qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/message/jni/JNIMessage.java
qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/messenger/jni/JNIMessengerFactory.java
qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal128.java
qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal32.java
qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal64.java
qpid/proton/trunk/proton-j/proton-api/src/main/resources/proton.py
Modified: qpid/proton/trunk/proton-c/bindings/java/java.i
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/java/java.i?rev=1441982&r1=1441981&r2=1441982&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/java/java.i (original)
+++ qpid/proton/trunk/proton-c/bindings/java/java.i Sun Feb 3 22:57:25 2013
@@ -32,8 +32,24 @@
#include <proton/driver.h>
#include <proton/driver_extras.h>
#include <proton/messenger.h>
-
%}
+/* Swig makes the assumption that all char[x] definitions have 0 as their last element... this is not true for Proton */
+%typemap(memberin) char [ANY] {
+ if($input) {
+ memcpy((char*)$1, (const char *)$input, $1_dim0);
+ } else {
+ $1[0] = 0;
+ }
+}
+
+%typemap(globalin) char [ANY] {
+ if($input) {
+ memcpy((char*)$1, (const char *)$input, $1_dim0);
+ } else {
+ $1[0] = 0;
+ }
+}
+
/* SWIG 1.x does not include the following necessary typemaps */
#if (SWIG_VERSION >> 16) < 2
%typemap(jni) (char *STRING, size_t LENGTH) "jbyteArray"
@@ -51,6 +67,10 @@
%apply (char *STRING, size_t LENGTH) { (char *STRING, int LENGTH) }
#endif
+JAVA_ARRAYS_DECL(char, jbyte, Byte, Byte)
+JAVA_ARRAYS_IMPL(char, jbyte, Byte, Byte)
+JAVA_ARRAYS_TYPEMAPS(char, byte, jbyte, Byte, "[B") /* char[ANY] */
+
%typemap(in) (char *DATA, size_t SIZE) (char *data, jobject arr, jboolean isDirect) {
/* %typemap(in) void * */
jclass bbclass = JCALL1(GetObjectClass,jenv, $input);
@@ -435,6 +455,9 @@ int pn_message_save_amqp(pn_message_t *m
int pn_message_save_json(pn_message_t *msg, char *OUTPUT, size_t *OUTPUT_SIZE);
%ignore pn_message_save_json;
+int pn_data_format(pn_data_t *data, char *DATA, size_t *SIZE);
+%ignore pn_data_format;
+
bool pn_ssl_get_cipher_name(pn_ssl_t *ssl, char *DATA, size_t SIZE);
%ignore pn_ssl_get_cipher_name;
Added: qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java?rev=1441982&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java (added)
+++ qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java Sun Feb 3 22:57:25 2013
@@ -0,0 +1,1120 @@
+/*
+ *
+ * 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.codec.jni;
+
+import java.lang.reflect.Array;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.qpid.proton.ProtonCEquivalent;
+import org.apache.qpid.proton.amqp.Binary;
+import org.apache.qpid.proton.amqp.Decimal128;
+import org.apache.qpid.proton.amqp.Decimal32;
+import org.apache.qpid.proton.amqp.Decimal64;
+import org.apache.qpid.proton.amqp.DescribedType;
+import org.apache.qpid.proton.amqp.Symbol;
+import org.apache.qpid.proton.amqp.UnsignedByte;
+import org.apache.qpid.proton.amqp.UnsignedInteger;
+import org.apache.qpid.proton.amqp.UnsignedLong;
+import org.apache.qpid.proton.amqp.UnsignedShort;
+import org.apache.qpid.proton.codec.Data;
+import org.apache.qpid.proton.jni.Proton;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_data_t;
+import org.apache.qpid.proton.jni.pn_bytes_t;
+import org.apache.qpid.proton.jni.pn_decimal128_t;
+import org.apache.qpid.proton.jni.pn_type_t;
+import org.apache.qpid.proton.jni.pn_uuid_t;
+
+public class JNIData implements Data
+{
+ public static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
+ public static final Charset ASCII_CHARSET = Charset.forName("US-ASCII");
+
+
+ private final SWIGTYPE_p_pn_data_t _impl;
+ private static final Map<DataType, Class> CLASSMAP = new EnumMap<DataType,Class>(DataType.class);
+
+ static
+ {
+ CLASSMAP.put(DataType.NULL, Void.class);
+ CLASSMAP.put(DataType.BOOL, Boolean.class);
+ CLASSMAP.put(DataType.UBYTE, UnsignedByte.class);
+ CLASSMAP.put(DataType.BYTE, Byte.class);
+ CLASSMAP.put(DataType.USHORT, UnsignedShort.class);
+ CLASSMAP.put(DataType.SHORT, Short.class);
+ CLASSMAP.put(DataType.UINT, UnsignedInteger.class);
+ CLASSMAP.put(DataType.INT, Integer.class);
+ CLASSMAP.put(DataType.CHAR, Character.class);
+ CLASSMAP.put(DataType.ULONG, UnsignedLong.class);
+ CLASSMAP.put(DataType.LONG, Long.class);
+ CLASSMAP.put(DataType.TIMESTAMP, Date.class);
+ CLASSMAP.put(DataType.FLOAT, Float.class);
+ CLASSMAP.put(DataType.DOUBLE, Double.class);
+ CLASSMAP.put(DataType.DECIMAL32, Decimal32.class);
+ CLASSMAP.put(DataType.DECIMAL64, Decimal64.class);
+ CLASSMAP.put(DataType.DECIMAL128, Decimal128.class);
+ CLASSMAP.put(DataType.UUID, UUID.class);
+ CLASSMAP.put(DataType.BINARY, Binary.class);
+ CLASSMAP.put(DataType.STRING, String.class);
+ CLASSMAP.put(DataType.SYMBOL, Symbol.class);
+ CLASSMAP.put(DataType.DESCRIBED, DescribedType.class);
+ CLASSMAP.put(DataType.ARRAY, Object[].class);
+ CLASSMAP.put(DataType.LIST, List.class);
+ CLASSMAP.put(DataType.MAP, Map.class);
+ }
+
+ private static final Map<Class, DataType> REVERSE_CLASSMAP = new HashMap<Class, DataType>();
+
+ static
+ {
+ for(Map.Entry<DataType, Class> entry : CLASSMAP.entrySet())
+ {
+ REVERSE_CLASSMAP.put(entry.getValue(), entry.getKey());
+ }
+ }
+
+ public JNIData(long capacity)
+ {
+ _impl = Proton.pn_data(capacity);
+ }
+
+ public JNIData(SWIGTYPE_p_pn_data_t impl)
+ {
+ _impl = impl;
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_free")
+ public void free()
+ {
+ //TODO
+ Proton.pn_data_free(_impl);
+
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_clear")
+ public void clear()
+ {
+ //TODO
+ Proton.pn_data_clear(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_size")
+ public long size()
+ {
+ return Proton.pn_data_size(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_rewind")
+ public void rewind()
+ {
+ Proton.pn_data_rewind(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_next")
+ public DataType next()
+ {
+ final boolean next = Proton.pn_data_next(_impl);
+ return next ? type() : null;
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_prev")
+ public DataType prev()
+ {
+ return Proton.pn_data_prev(_impl) ? type() : null;
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_next")
+ public boolean enter()
+ {
+ return Proton.pn_data_enter(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_exit")
+ public boolean exit()
+ {
+ return Proton.pn_data_exit(_impl);
+ }
+
+ static final Map<pn_type_t, DataType> TYPEMAP = new HashMap<pn_type_t, DataType>();
+ static final Map<DataType, pn_type_t> REVERSE_TYPEMAP = new EnumMap<DataType,pn_type_t>(DataType.class);
+ static
+ {
+ TYPEMAP.put(pn_type_t.PN_NULL, DataType.NULL);
+ TYPEMAP.put(pn_type_t.PN_BOOL, DataType.BOOL);
+ TYPEMAP.put(pn_type_t.PN_UBYTE, DataType.UBYTE);
+ TYPEMAP.put(pn_type_t.PN_BYTE, DataType.BYTE);
+ TYPEMAP.put(pn_type_t.PN_USHORT, DataType.USHORT);
+ TYPEMAP.put(pn_type_t.PN_SHORT, DataType.SHORT);
+ TYPEMAP.put(pn_type_t.PN_UINT, DataType.UINT);
+ TYPEMAP.put(pn_type_t.PN_INT, DataType.INT);
+ TYPEMAP.put(pn_type_t.PN_CHAR, DataType.CHAR);
+ TYPEMAP.put(pn_type_t.PN_ULONG, DataType.ULONG);
+ TYPEMAP.put(pn_type_t.PN_LONG, DataType.LONG);
+ TYPEMAP.put(pn_type_t.PN_TIMESTAMP, DataType.TIMESTAMP);
+ TYPEMAP.put(pn_type_t.PN_FLOAT, DataType.FLOAT);
+ TYPEMAP.put(pn_type_t.PN_DOUBLE, DataType.DOUBLE);
+ TYPEMAP.put(pn_type_t.PN_DECIMAL32, DataType.DECIMAL32);
+ TYPEMAP.put(pn_type_t.PN_DECIMAL64, DataType.DECIMAL64);
+ TYPEMAP.put(pn_type_t.PN_DECIMAL128, DataType.DECIMAL128);
+ TYPEMAP.put(pn_type_t.PN_UUID, DataType.UUID);
+ TYPEMAP.put(pn_type_t.PN_BINARY, DataType.BINARY);
+ TYPEMAP.put(pn_type_t.PN_STRING, DataType.STRING);
+ TYPEMAP.put(pn_type_t.PN_SYMBOL, DataType.SYMBOL);
+ TYPEMAP.put(pn_type_t.PN_DESCRIBED, DataType.DESCRIBED);
+ TYPEMAP.put(pn_type_t.PN_ARRAY, DataType.ARRAY);
+ TYPEMAP.put(pn_type_t.PN_LIST, DataType.LIST);
+ TYPEMAP.put(pn_type_t.PN_MAP, DataType.MAP);
+
+ REVERSE_TYPEMAP.put(DataType.NULL, pn_type_t.PN_NULL);
+ REVERSE_TYPEMAP.put(DataType.BOOL, pn_type_t.PN_BOOL);
+ REVERSE_TYPEMAP.put(DataType.UBYTE, pn_type_t.PN_UBYTE);
+ REVERSE_TYPEMAP.put(DataType.BYTE, pn_type_t.PN_BYTE);
+ REVERSE_TYPEMAP.put(DataType.USHORT, pn_type_t.PN_USHORT);
+ REVERSE_TYPEMAP.put(DataType.SHORT, pn_type_t.PN_SHORT);
+ REVERSE_TYPEMAP.put(DataType.UINT, pn_type_t.PN_UINT);
+ REVERSE_TYPEMAP.put(DataType.INT, pn_type_t.PN_INT);
+ REVERSE_TYPEMAP.put(DataType.CHAR, pn_type_t.PN_CHAR);
+ REVERSE_TYPEMAP.put(DataType.ULONG, pn_type_t.PN_ULONG);
+ REVERSE_TYPEMAP.put(DataType.LONG, pn_type_t.PN_LONG);
+ REVERSE_TYPEMAP.put(DataType.TIMESTAMP, pn_type_t.PN_TIMESTAMP);
+ REVERSE_TYPEMAP.put(DataType.FLOAT, pn_type_t.PN_FLOAT);
+ REVERSE_TYPEMAP.put(DataType.DOUBLE, pn_type_t.PN_DOUBLE);
+ REVERSE_TYPEMAP.put(DataType.DECIMAL32, pn_type_t.PN_DECIMAL32);
+ REVERSE_TYPEMAP.put(DataType.DECIMAL64, pn_type_t.PN_DECIMAL64);
+ REVERSE_TYPEMAP.put(DataType.DECIMAL128, pn_type_t.PN_DECIMAL128);
+ REVERSE_TYPEMAP.put(DataType.UUID, pn_type_t.PN_UUID);
+ REVERSE_TYPEMAP.put(DataType.BINARY, pn_type_t.PN_BINARY);
+ REVERSE_TYPEMAP.put(DataType.STRING, pn_type_t.PN_STRING);
+ REVERSE_TYPEMAP.put(DataType.SYMBOL, pn_type_t.PN_SYMBOL);
+ REVERSE_TYPEMAP.put(DataType.DESCRIBED, pn_type_t.PN_DESCRIBED);
+ REVERSE_TYPEMAP.put(DataType.ARRAY, pn_type_t.PN_ARRAY);
+ REVERSE_TYPEMAP.put(DataType.LIST, pn_type_t.PN_LIST);
+ REVERSE_TYPEMAP.put(DataType.MAP, pn_type_t.PN_MAP);
+
+ }
+
+
+ @Override
+ @ProtonCEquivalent("pn_data_type")
+ public DataType type()
+ {
+ try
+ {
+ pn_type_t dataType = Proton.pn_data_type(_impl);
+ final DataType type = TYPEMAP.get(dataType);
+ return type;
+ }
+ catch(IllegalArgumentException e)
+ {
+ return null;
+ }
+
+
+ }
+
+ @Override
+ public Binary encode()
+ {
+ int size = 1024;
+ long rval = Proton.PN_OVERFLOW;
+ ByteBuffer buf = null;
+ while(rval == Proton.PN_OVERFLOW)
+ {
+ buf = ByteBuffer.allocate(size);
+ rval = encode(buf);
+ }
+ return new Binary(buf.array(), buf.arrayOffset(), buf.arrayOffset()+(int)rval);
+ }
+
+
+ @Override
+ @ProtonCEquivalent("pn_data_encode")
+ public long encode(final ByteBuffer buf)
+ {
+ return Proton.pn_data_encode(_impl, buf);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_decode")
+ public long decode(final ByteBuffer buf)
+ {
+ int rval = Proton.pn_data_decode(_impl, buf);
+ return rval;
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_list")
+ public void putList()
+ {
+ Proton.pn_data_put_list(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_map")
+ public void putMap()
+ {
+ Proton.pn_data_put_map(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_array")
+ public void putArray(final boolean described, final DataType type)
+ {
+ Proton.pn_data_put_array(_impl, described, REVERSE_TYPEMAP.get(type));
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_described")
+ public void putDescribed()
+ {
+ Proton.pn_data_put_described(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_null")
+ public void putNull()
+ {
+ Proton.pn_data_put_null(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_bool")
+ public void putBoolean(final boolean b)
+ {
+ Proton.pn_data_put_bool(_impl, b);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_ubyte")
+ public void putUnsignedByte(final UnsignedByte ub)
+ {
+ Proton.pn_data_put_ubyte(_impl, ub.shortValue());
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_byte")
+ public void putByte(final byte b)
+ {
+ Proton.pn_data_put_byte(_impl, b);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_ushort")
+ public void putUnsignedShort(final UnsignedShort us)
+ {
+ Proton.pn_data_put_ushort(_impl, us.intValue());
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_short")
+ public void putShort(final short s)
+ {
+ Proton.pn_data_put_short(_impl, s);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_uint")
+ public void putUnsignedInteger(final UnsignedInteger ui)
+ {
+ Proton.pn_data_put_uint(_impl, ui.intValue());
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_int")
+ public void putInt(final int i)
+ {
+ Proton.pn_data_put_int(_impl, i);
+ }
+
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_char")
+ public void putChar(final int c)
+ {
+ Proton.pn_data_put_char(_impl, c);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_ulong")
+ public void putUnsignedLong(final UnsignedLong ul)
+ {
+ Proton.pn_data_put_ulong(_impl, ul.bigIntegerValue());
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_long")
+ public void putLong(final long l)
+ {
+ Proton.pn_data_put_long(_impl, l);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_timestamp")
+ public void putTimestamp(final Date t)
+ {
+ Proton.pn_data_put_timestamp(_impl, t.getTime());
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_float")
+ public void putFloat(final float f)
+ {
+ Proton.pn_data_put_float(_impl, f);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_double")
+ public void putDouble(final double d)
+ {
+ Proton.pn_data_put_double(_impl, d);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_decimal32")
+ public void putDecimal32(final Decimal32 d)
+ {
+ Proton.pn_data_put_decimal32(_impl, d.getBits());
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_decimal64")
+ public void putDecimal64(final Decimal64 d)
+ {
+ BigInteger bi = BigInteger.valueOf(d.getBits());
+ Proton.pn_data_put_decimal64(_impl, bi);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_decimal128")
+ public void putDecimal128(final Decimal128 d)
+ {
+ byte[] data = new byte[16];
+ ByteBuffer buf = ByteBuffer.wrap(data);
+ buf.putLong(d.getMostSignificantBits());
+ buf.putLong(d.getLeastSignificantBits());
+ pn_decimal128_t decimal128_t = new pn_decimal128_t();
+ decimal128_t.setBytes(data);
+ Proton.pn_data_put_decimal128(_impl,decimal128_t);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_uuid")
+ public void putUUID(final UUID u)
+ {
+ final pn_uuid_t uuid = new pn_uuid_t();
+ byte[] data = new byte[16];
+ ByteBuffer buf = ByteBuffer.wrap(data);
+ buf.putLong(u.getMostSignificantBits());
+ buf.putLong(u.getLeastSignificantBits());
+ uuid.setBytes(data);
+
+ Proton.pn_data_put_uuid(_impl, uuid);
+
+ //TODO
+ }
+
+ @Override
+ public void putBinary(final byte[] bytes)
+ {
+ putBinary(new Binary(bytes));
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_binary")
+ public void putBinary(final Binary bytes)
+ {
+ pn_bytes_t bytes_t = new pn_bytes_t();
+ bytes_t.setSize(bytes.getLength());
+ byte[] data = new byte[bytes.getLength()];
+ System.arraycopy(bytes.getArray(),bytes.getArrayOffset(),data,0,bytes.getLength());
+ bytes_t.setStart(data);
+ Proton.pn_data_put_binary(_impl, bytes_t);
+ //TODO
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_string")
+ public void putString(final String string)
+ {
+ byte[] data = string.getBytes(UTF8_CHARSET);
+ pn_bytes_t bytes_t = new pn_bytes_t();
+ bytes_t.setStart(data);
+ bytes_t.setSize(data.length);
+ Proton.pn_data_put_string(_impl, bytes_t);
+
+ //TODO
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_put_symbol")
+ public void putSymbol(final Symbol symbol)
+ {
+ byte[] data = symbol.toString().getBytes(ASCII_CHARSET);
+ pn_bytes_t bytes_t = new pn_bytes_t();
+ bytes_t.setStart(data);
+ bytes_t.setSize(data.length);
+ Proton.pn_data_put_symbol(_impl, bytes_t);
+ //TODO
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_list")
+ public long getList()
+ {
+ return Proton.pn_data_get_list(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_map")
+ public long getMap()
+ {
+ return Proton.pn_data_get_map(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_array")
+ public long getArray()
+ {
+ return Proton.pn_data_get_array(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_is_array_described")
+ public boolean isArrayDescribed()
+ {
+ return Proton.pn_data_is_array_described(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_array_type")
+ public DataType getArrayType()
+ {
+ return TYPEMAP.get(Proton.pn_data_get_array_type(_impl));
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_is_described")
+ public boolean isDescribed()
+ {
+ return Proton.pn_data_is_described(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_is_null")
+ public boolean isNull()
+ {
+ return Proton.pn_data_is_null(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_bool")
+ public boolean getBoolean()
+ {
+ return Proton.pn_data_get_bool(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_ubyte")
+ public UnsignedByte getUnsignedByte()
+ {
+ return UnsignedByte.valueOf((byte) Proton.pn_data_get_ubyte(_impl));
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_byte")
+ public byte getByte()
+ {
+ return Proton.pn_data_get_byte(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_ushort")
+ public UnsignedShort getUnsignedShort()
+ {
+ return UnsignedShort.valueOf((short) Proton.pn_data_get_ushort(_impl));
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_short")
+ public short getShort()
+ {
+ return Proton.pn_data_get_short(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_uint")
+ public UnsignedInteger getUnsignedInteger()
+ {
+ return UnsignedInteger.valueOf(Proton.pn_data_get_uint(_impl));
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_int")
+ public int getInt()
+ {
+ return Proton.pn_data_get_int(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_char")
+ public int getChar()
+ {
+ final int c = (int) Proton.pn_data_get_char(_impl);
+ return c;
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_ulong")
+ public UnsignedLong getUnsignedLong()
+ {
+ return UnsignedLong.valueOf(Proton.pn_data_get_ulong(_impl).toString());
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_long")
+ public long getLong()
+ {
+ return Proton.pn_data_get_long(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_timestamp")
+ public Date getTimestamp()
+ {
+ return new Date(Proton.pn_data_get_timestamp(_impl));
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_float")
+ public float getFloat()
+ {
+ return Proton.pn_data_get_float(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_double")
+ public double getDouble()
+ {
+ return Proton.pn_data_get_double(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_decimal32")
+ public Decimal32 getDecimal32()
+ {
+ return new Decimal32((int)Proton.pn_data_get_decimal32(_impl));
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_decimal64")
+ public Decimal64 getDecimal64()
+ {
+ return new Decimal64(Proton.pn_data_get_decimal64(_impl).longValue());
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_decimal128")
+ public Decimal128 getDecimal128()
+ {
+ pn_decimal128_t b = Proton.pn_data_get_decimal128(_impl);
+ ByteBuffer buf = ByteBuffer.wrap(b.getBytes());
+ return new Decimal128(buf.getLong(),buf.getLong());
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_uuid")
+ public UUID getUUID()
+ {
+ pn_uuid_t u = Proton.pn_data_get_uuid(_impl);
+ ByteBuffer buf = ByteBuffer.wrap(u.getBytes());
+ long msb = buf.getLong();
+ long lsb = buf.getLong();
+
+ final UUID uuid = new UUID(msb, lsb);
+ return uuid;
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_binary")
+ public Binary getBinary()
+ {
+ pn_bytes_t b = Proton.pn_data_get_binary(_impl);
+ return new Binary(b.getStart());
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_string")
+ public String getString()
+ {
+ pn_bytes_t b = Proton.pn_data_get_string(_impl);
+ return new String(b.getStart(), UTF8_CHARSET);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_get_symbol")
+ public Symbol getSymbol()
+ {
+ pn_bytes_t b = Proton.pn_data_get_symbol(_impl);
+ return Symbol.valueOf(new String(b.getStart(), UTF8_CHARSET));
+ }
+
+ @Override
+ public void putObject(final Object o)
+ {
+ if(o == null)
+ {
+ putNull();
+ }
+ else if(o instanceof Boolean)
+ {
+ putBoolean((Boolean) o);
+ }
+ else if(o instanceof UnsignedByte)
+ {
+ putUnsignedByte((UnsignedByte)o);
+ }
+ else if(o instanceof Byte)
+ {
+ putByte((Byte)o);
+ }
+ else if(o instanceof UnsignedShort)
+ {
+ putUnsignedShort((UnsignedShort)o);
+ }
+ else if(o instanceof Short)
+ {
+ putShort((Short)o);
+ }
+ else if(o instanceof UnsignedInteger)
+ {
+ putUnsignedInteger((UnsignedInteger)o);
+ }
+ else if(o instanceof Integer)
+ {
+ putInt((Integer)o);
+ }
+ else if(o instanceof Character)
+ {
+ putChar((Character)o);
+ }
+ else if(o instanceof UnsignedLong)
+ {
+ putUnsignedLong((UnsignedLong)o);
+ }
+ else if(o instanceof Long)
+ {
+ putLong((Long)o);
+ }
+ else if(o instanceof Date)
+ {
+ putTimestamp((Date)o);
+ }
+ else if(o instanceof Float)
+ {
+ putFloat((Float)o);
+ }
+ else if(o instanceof Double)
+ {
+ putDouble((Double)o);
+ }
+ else if(o instanceof Decimal32)
+ {
+ putDecimal32((Decimal32)o);
+ }
+ else if(o instanceof Decimal64)
+ {
+ putDecimal64((Decimal64)o);
+ }
+ else if(o instanceof Decimal128)
+ {
+ putDecimal128((Decimal128)o);
+ }
+ else if(o instanceof UUID)
+ {
+ putUUID((UUID)o);
+ }
+ else if(o instanceof Binary)
+ {
+ putBinary((Binary)o);
+ }
+ else if(o instanceof String)
+ {
+ putString((String)o);
+ }
+ else if(o instanceof Symbol)
+ {
+ putSymbol((Symbol)o);
+ }
+ else if(o instanceof DescribedType)
+ {
+ putDescribedType((DescribedType)o);
+ }
+// TODO- ARRAY,
+ else if(o instanceof Object[])
+ {
+ putJavaArray((Object[]) o);
+ }
+ else if(o instanceof List)
+ {
+ putJavaList((List)o);
+ }
+ else if(o instanceof Map)
+ {
+ putJavaMap((Map)o);
+ }
+//
+ //TODO
+ }
+
+ @Override
+ public void putJavaMap(final Map<Object, Object> map)
+ {
+ putMap();
+ enter();
+ for(Map.Entry<Object, Object> entry : map.entrySet())
+ {
+ putObject(entry.getKey());
+ putObject(entry.getValue());
+ }
+ exit();
+ }
+
+ @Override
+ public void putJavaList(final List<Object> list)
+ {
+ putList();
+ enter();
+ for(Object element : list)
+ {
+ putObject(element);
+ }
+ exit();
+ }
+
+ @Override
+ public void putJavaArray(final Object[] array)
+ {
+ //TODO
+ Class eltClazz = array.getClass().getComponentType();
+ boolean described = eltClazz.isInstance(DescribedType.class);
+ putArray(described, getType(described ? ((DescribedType) array[0]).getDescribed().getClass() : eltClazz));
+ enter();
+ for(Object elt : array)
+ {
+ putObject(elt);
+ }
+ exit();
+ }
+
+
+
+ private DataType getType(final Class aClass)
+ {
+ if(aClass.isInstance(Map.class))
+ {
+ return DataType.MAP;
+ }
+ if(aClass.isInstance(List.class))
+ {
+ return DataType.LIST;
+ }
+ DataType t = REVERSE_CLASSMAP.get(aClass);
+ if(t != null)
+ {
+ return t;
+ }
+ return null; //TODO
+ }
+
+ @Override
+ public void putDescribedType(final DescribedType dt)
+ {
+ putDescribed();
+ enter();
+ putObject(dt.getDescriptor());
+ putObject(dt.getDescribed());
+ exit();
+ }
+
+ @Override
+ public Object getObject()
+ {
+
+ final DataType type = type();
+ if(type == null)
+ {
+ return null;
+ }
+
+ switch(type)
+ {
+ case NULL:
+ return null;
+
+ case BOOL:
+ return getBoolean();
+
+ case UBYTE:
+ return getUnsignedByte();
+
+ case BYTE:
+ return getByte();
+
+ case USHORT:
+ return getUnsignedShort();
+
+ case SHORT:
+ return getShort();
+
+ case UINT:
+ return getUnsignedInteger();
+
+ case INT:
+ return getInt();
+
+ case CHAR:
+ return getChar();
+
+ case ULONG:
+ return getUnsignedLong();
+
+ case LONG:
+ return getLong();
+
+ case TIMESTAMP:
+ return getTimestamp();
+
+ case FLOAT:
+ return getFloat();
+
+ case DOUBLE:
+ return getDouble();
+
+ case DECIMAL32:
+ return getDecimal32();
+
+ case DECIMAL64:
+ return getDecimal64();
+
+ case DECIMAL128:
+ return getDecimal128();
+
+ case UUID:
+ return getUUID();
+
+ case BINARY:
+ return getBinary();
+
+ case STRING:
+ return getString();
+
+ case SYMBOL:
+ return getSymbol();
+
+ case DESCRIBED:
+ return getDescribedType();
+
+ case ARRAY:
+ return getJavaArray();
+
+ case LIST:
+ return getJavaList();
+
+ case MAP:
+ return getJavaMap();
+ }
+ return null;
+ }
+
+ @Override
+ public Map<Object, Object> getJavaMap()
+ {
+ int count = (int) getMap();
+ Map<Object,Object> map = new LinkedHashMap<Object, Object>(count);
+ enter();
+ for(int i = 0; i < count; i+=2)
+ {
+ next();
+ Object key = getObject();
+
+ Object value = next() != null ? getObject() : null;
+
+ }
+ exit();
+ return map;
+ }
+
+ @Override
+ public List<Object> getJavaList()
+ {
+ int count = (int) getList();
+ List<Object> list = new ArrayList<Object>(count);
+ enter();
+ for(int i = 0; i < count; i++)
+ {
+ next();
+ list.add(getObject());
+ }
+ exit();
+ return list;
+ }
+
+ @Override
+ public Object[] getJavaArray()
+ {
+ int count = (int) getArray();
+ boolean described = isArrayDescribed();
+
+ Object descriptor;
+ enter();
+ DataType t = next();
+ Object[] arr;
+ if(described)
+ {
+ descriptor = getObject();
+ next();
+ arr = new DescribedType[count];
+ }
+ else
+ {
+ descriptor = null;
+ Class clazz = CLASSMAP.get(t);
+ arr = (Object[]) Array.newInstance(clazz, count);
+ }
+
+
+ for(int i = 0; i < count; i++)
+ {
+ arr[i] = described ? new DataDescribedType(descriptor,getObject()) : getObject();
+ next();
+ }
+ exit();
+ return arr;
+ }
+
+ @Override
+ public DescribedType getDescribedType()
+ {
+ enter();
+ final Object descriptor = getObject();
+ final Object described = getObject();
+ exit();
+ return new DataDescribedType(descriptor, described);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_copy")
+ public void copy(final Data src)
+ {
+ Proton.pn_data_copy(_impl, ((JNIData) src)._impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_append")
+ public void append(final Data src)
+ {
+ Proton.pn_data_append(_impl, ((JNIData) src)._impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_appendn")
+ public void appendn(final Data src, final int limit)
+ {
+ Proton.pn_data_appendn(_impl, ((JNIData) src)._impl, limit);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_narrow")
+ public void narrow()
+ {
+ Proton.pn_data_narrow(_impl);
+ }
+
+ @Override
+ @ProtonCEquivalent("pn_data_widen")
+ public void widen()
+ {
+ Proton.pn_data_widen(_impl);
+ }
+
+ @ProtonCEquivalent("pn_data_format")
+ public String toString()
+ {
+ int size = 16;
+
+ byte[] data;
+ while(true)
+ {
+ data = new byte[size];
+ ByteBuffer buf = ByteBuffer.wrap(data);
+ if(Proton.pn_data_format(_impl,buf) != Proton.PN_OVERFLOW)
+ {
+ break;
+ };
+ size = size*2;
+ }
+ return new String(data);
+ }
+
+ private static class DataDescribedType implements DescribedType
+ {
+ private final Object _descriptor;
+ private final Object _described;
+
+ public DataDescribedType(final Object descriptor, final Object described)
+ {
+ _descriptor = descriptor;
+ _described = described;
+ }
+
+ @Override
+ public Object getDescriptor()
+ {
+ return _descriptor;
+ }
+
+ @Override
+ public Object getDescribed()
+ {
+ return _described;
+ }
+ }
+}
Added: qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIDataFactory.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIDataFactory.java?rev=1441982&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIDataFactory.java (added)
+++ qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIDataFactory.java Sun Feb 3 22:57:25 2013
@@ -0,0 +1,34 @@
+/*
+ *
+ * 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.codec.jni;
+
+import org.apache.qpid.proton.codec.Data;
+import org.apache.qpid.proton.codec.DataFactory;
+import org.apache.qpid.proton.jni.JNIFactory;
+
+public class JNIDataFactory extends JNIFactory implements DataFactory
+{
+ @Override
+ public Data createData(long capacity)
+ {
+ return new JNIData(capacity);
+ }
+}
Modified: qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/message/jni/JNIMessage.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/message/jni/JNIMessage.java?rev=1441982&r1=1441981&r2=1441982&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/message/jni/JNIMessage.java (original)
+++ qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/message/jni/JNIMessage.java Sun Feb 3 22:57:25 2013
@@ -32,14 +32,20 @@ import org.apache.qpid.proton.amqp.Unsig
import org.apache.qpid.proton.amqp.UnsignedInteger;
import org.apache.qpid.proton.amqp.UnsignedLong;
import org.apache.qpid.proton.amqp.UnsignedShort;
+import org.apache.qpid.proton.amqp.messaging.AmqpSequence;
+import org.apache.qpid.proton.amqp.messaging.AmqpValue;
import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
+import org.apache.qpid.proton.amqp.messaging.Data;
import org.apache.qpid.proton.amqp.messaging.DeliveryAnnotations;
import org.apache.qpid.proton.amqp.messaging.Footer;
import org.apache.qpid.proton.amqp.messaging.Header;
import org.apache.qpid.proton.amqp.messaging.MessageAnnotations;
import org.apache.qpid.proton.amqp.messaging.Properties;
import org.apache.qpid.proton.amqp.messaging.Section;
+import org.apache.qpid.proton.codec.jni.JNIData;
+import org.apache.qpid.proton.codec.jni.JNIDataFactory;
import org.apache.qpid.proton.jni.Proton;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_data_t;
import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_message_t;
import org.apache.qpid.proton.jni.pn_atom_t;
import org.apache.qpid.proton.jni.pn_atom_t_u;
@@ -62,6 +68,11 @@ public class JNIMessage implements Messa
_impl = Proton.pn_message();
}
+ public JNIMessage(SWIGTYPE_p_pn_message_t impl)
+ {
+ _impl = impl;
+ }
+
@Override
@ProtonCEquivalent("pn_message_is_durable")
public boolean isDurable()
@@ -791,8 +802,12 @@ public class JNIMessage implements Messa
@ProtonCEquivalent("pn_message_body")
public Section getBody()
{
- //TODO
- throw new UnsupportedOperationException();
+ SWIGTYPE_p_pn_data_t body = Proton.pn_message_body(_impl);
+ JNIData data = new JNIData(body);
+ data.rewind();
+
+ // TODO
+ return data.next() == null ? null : new AmqpValue(data.getObject());
}
public Footer getFooter()
@@ -804,38 +819,64 @@ public class JNIMessage implements Messa
public void setHeader(Header header)
{
//TODO
- throw new UnsupportedOperationException();
+ //throw new UnsupportedOperationException();
}
public void setDeliveryAnnotations(DeliveryAnnotations deliveryAnnotations)
{
//TODO
- throw new UnsupportedOperationException();
+ //throw new UnsupportedOperationException();
}
public void setMessageAnnotations(MessageAnnotations messageAnnotations)
{
//TODO
- throw new UnsupportedOperationException();
+ //throw new UnsupportedOperationException();
}
public void setProperties(Properties properties)
{
//TODO
- throw new UnsupportedOperationException();
+ //throw new UnsupportedOperationException();
}
public void setApplicationProperties(ApplicationProperties applicationProperties)
{
//TODO
- throw new UnsupportedOperationException();
+ //throw new UnsupportedOperationException();
}
public void setBody(Section body)
{
+ JNIData data = new JNIData(Proton.pn_message_body(_impl));
+ data.clear();
+ if(body instanceof Data)
+ {
+ data.putDescribed();
+ data.enter();
+ data.putUnsignedLong(UnsignedLong.valueOf(0x0000000000000075L));
+ data.putBinary(((Data) body).getValue());
+ data.exit();
+ }
+ else if(body instanceof AmqpSequence)
+ {
+ // TODO
+ }
+ else if(body instanceof AmqpValue)
+ {
+ data.putDescribed();
+ data.enter();
+ data.putUnsignedLong(UnsignedLong.valueOf(0x0000000000000077L));
+ data.putObject(((AmqpValue) body).getValue());
+ data.exit();
+ }
+
//TODO
- throw new UnsupportedOperationException();
}
+ public SWIGTYPE_p_pn_message_t getImpl()
+ {
+ return _impl;
+ }
}
Added: qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/messenger/jni/JNIMessenger.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/messenger/jni/JNIMessenger.java?rev=1441982&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/messenger/jni/JNIMessenger.java (added)
+++ qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/messenger/jni/JNIMessenger.java Sun Feb 3 22:57:25 2013
@@ -0,0 +1,262 @@
+/*
+ *
+ * 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.messenger.jni;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.concurrent.TimeoutException;
+import org.apache.qpid.proton.ProtonCEquivalent;
+import org.apache.qpid.proton.jni.Proton;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_message_t;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_messenger_t;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_subscription_t;
+import org.apache.qpid.proton.jni.pn_status_t;
+import org.apache.qpid.proton.message.Message;
+import org.apache.qpid.proton.message.jni.JNIMessage;
+import org.apache.qpid.proton.messenger.Messenger;
+import org.apache.qpid.proton.messenger.MessengerException;
+import org.apache.qpid.proton.messenger.Status;
+import org.apache.qpid.proton.messenger.Tracker;
+
+class JNIMessenger implements Messenger
+{
+ private SWIGTYPE_p_pn_messenger_t _impl;
+
+ JNIMessenger()
+ {
+ this(java.util.UUID.randomUUID().toString());
+ }
+
+ JNIMessenger(final String name)
+ {
+ _impl = Proton.pn_messenger(name);
+ }
+
+ @Override
+ public void put(final Message message) throws MessengerException
+ {
+ SWIGTYPE_p_pn_message_t message_t = (message instanceof JNIMessage) ? ((JNIMessage)message).getImpl() : convertMessage(message);
+ int err = Proton.pn_messenger_put(_impl, message_t);
+ //TODO - error handling
+ }
+
+ private SWIGTYPE_p_pn_message_t convertMessage(final Message message)
+ {
+ int length = 512;
+ int encoded;
+ byte[] data;
+ do
+ {
+ length = length*2;
+ data = new byte[length];
+ encoded = message.encode(data,0,length);
+ }
+ while (encoded == length || encoded < 0);
+
+ final SWIGTYPE_p_pn_message_t message_t = Proton.pn_message();
+ Proton.pn_message_decode(message_t, ByteBuffer.wrap(data, 0, encoded));
+
+ return message_t;
+ }
+
+ @Override
+ public void send() throws TimeoutException
+ {
+ int err = Proton.pn_messenger_send(_impl);
+ //TODO - error handling
+ }
+
+ @Override
+ public void subscribe(final String source) throws MessengerException
+ {
+ SWIGTYPE_p_pn_subscription_t sub = Proton.pn_messenger_subscribe(_impl, source);
+ // TODO
+ }
+
+ @Override
+ public void recv(final int count) throws TimeoutException
+ {
+ int err = Proton.pn_messenger_recv(_impl, count);
+ //TODO
+ }
+
+ @Override
+ public Message get()
+ {
+ SWIGTYPE_p_pn_message_t msg = Proton.pn_message();
+ // TODO - error handling... null?
+ int err = Proton.pn_messenger_get(_impl, msg);
+ return new JNIMessage(msg);
+ }
+
+ @Override
+ public void start() throws IOException
+ {
+ // TODO - error handling
+ int err = Proton.pn_messenger_start(_impl);
+ }
+
+ @Override
+ public void stop()
+ {
+ int err = Proton.pn_messenger_stop(_impl);
+ //TODO - error handling
+ }
+
+ @Override
+ public void setTimeout(final long timeInMillis)
+ {
+ int err = Proton.pn_messenger_set_timeout(_impl, (int) timeInMillis);
+ //TODO - error handling
+ }
+
+ @Override
+ public long getTimeout()
+ {
+ return Proton.pn_messenger_get_timeout(_impl);
+ }
+
+ @Override
+ public int outgoing()
+ {
+ return Proton.pn_messenger_outgoing(_impl);
+ }
+
+ @Override
+ public int incoming()
+ {
+ return Proton.pn_messenger_incoming(_impl);
+ }
+
+ @Override
+ public int getIncomingWindow()
+ {
+ return Proton.pn_messenger_get_incoming_window(_impl);
+ }
+
+ @Override
+ public void setIncomingWindow(final int window)
+ {
+ int err = Proton.pn_messenger_set_incoming_window(_impl, window);
+ //TODO - error handling
+ }
+
+ @Override
+ public int getOutgoingWindow()
+ {
+ return Proton.pn_messenger_get_outgoing_window(_impl);
+ }
+
+ @Override
+ public void setOutgoingWindow(final int window)
+ {
+ int err = Proton.pn_messenger_set_outgoing_window(_impl, window);
+ //TODO
+ }
+
+ @Override
+ public Tracker incomingTracker()
+ {
+ return new JNITracker(Proton.pn_messenger_incoming_tracker(_impl));
+ }
+
+ @Override
+ public Tracker outgoingTracker()
+ {
+ return new JNITracker(Proton.pn_messenger_outgoing_tracker(_impl));
+ }
+
+ @Override
+ public void reject(final Tracker tracker, final int flags)
+ {
+ int err = Proton.pn_messenger_reject(_impl, ((JNITracker) tracker).getTracker(), flags);
+ //TODO - error handling
+ }
+
+ @Override
+ public void accept(final Tracker tracker, final int flags)
+ {
+ int err = Proton.pn_messenger_accept(_impl, ((JNITracker) tracker).getTracker(), flags);
+ //TODO - error handling
+ }
+
+ @Override
+ public void settle(final Tracker tracker, final int flags)
+ {
+ int err = Proton.pn_messenger_settle(_impl, ((JNITracker) tracker).getTracker(), flags);
+ //TODO - error handling
+ }
+
+ @Override
+ public Status getStatus(final Tracker tracker)
+ {
+ pn_status_t status = Proton.pn_messenger_status(_impl, ((JNITracker) tracker).getTracker());
+ if(status == pn_status_t.PN_STATUS_ACCEPTED)
+ {
+ return Status.ACCEPTED;
+ }
+ else if(status == pn_status_t.PN_STATUS_PENDING)
+ {
+ return Status.PENDING;
+ }
+ else if(status == pn_status_t.PN_STATUS_REJECTED)
+ {
+ return Status.REJECTED;
+ }
+ else if(status == pn_status_t.PN_STATUS_UNKNOWN)
+ {
+ return Status.UNKNOWN;
+ }
+
+ return Status.UNKNOWN; //TODO - is this correct?
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ free();
+ super.finalize();
+ }
+
+ public void free()
+ {
+ if(_impl != null)
+ {
+ Proton.pn_messenger_free(_impl);
+ _impl = null;
+ }
+ }
+
+ private class JNITracker implements Tracker
+ {
+ private final long _tracker;
+
+ public JNITracker(final long tracker)
+ {
+ _tracker = tracker;
+ }
+
+ public long getTracker()
+ {
+ return _tracker;
+ }
+ }
+}
Modified: qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/messenger/jni/JNIMessengerFactory.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/messenger/jni/JNIMessengerFactory.java?rev=1441982&r1=1441981&r2=1441982&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/messenger/jni/JNIMessengerFactory.java (original)
+++ qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/messenger/jni/JNIMessengerFactory.java Sun Feb 3 22:57:25 2013
@@ -29,13 +29,13 @@ public class JNIMessengerFactory impleme
@Override
public Messenger createMessenger()
{
- throw new ProtonUnsupportedOperationException();
+ return new JNIMessenger();
}
@Override
public Messenger createMessenger(String name)
{
- throw new ProtonUnsupportedOperationException();
+ return new JNIMessenger(name);
}
}
Copied: qpid/proton/trunk/proton-c/bindings/java/src/main/resources/META-INF/services/org.apache.qpid.proton.codec.DataFactory (from r1441742, qpid/proton/trunk/proton-c/bindings/java/src/main/resources/META-INF/services/org.apache.qpid.proton.engine.EngineFactory)
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/java/src/main/resources/META-INF/services/org.apache.qpid.proton.codec.DataFactory?p2=qpid/proton/trunk/proton-c/bindings/java/src/main/resources/META-INF/services/org.apache.qpid.proton.codec.DataFactory&p1=qpid/proton/trunk/proton-c/bindings/java/src/main/resources/META-INF/services/org.apache.qpid.proton.engine.EngineFactory&r1=1441742&r2=1441982&rev=1441982&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/java/src/main/resources/META-INF/services/org.apache.qpid.proton.engine.EngineFactory (original)
+++ qpid/proton/trunk/proton-c/bindings/java/src/main/resources/META-INF/services/org.apache.qpid.proton.codec.DataFactory Sun Feb 3 22:57:25 2013
@@ -1 +1 @@
-org.apache.qpid.proton.engine.jni.JNIEngineFactory
\ No newline at end of file
+org.apache.qpid.proton.codec.jni.JNIDataFactory
\ No newline at end of file
Modified: qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal128.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal128.java?rev=1441982&r1=1441981&r2=1441982&view=diff
==============================================================================
--- qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal128.java (original)
+++ qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal128.java Sun Feb 3 22:57:25 2013
@@ -22,6 +22,7 @@
package org.apache.qpid.proton.amqp;
import java.math.BigDecimal;
+import java.nio.ByteBuffer;
public final class Decimal128 extends Number
{
@@ -47,6 +48,16 @@ public final class Decimal128 extends Nu
}
+ public Decimal128(byte[] data)
+ {
+ this(ByteBuffer.wrap(data));
+ }
+
+ private Decimal128(final ByteBuffer buffer)
+ {
+ this(buffer.getLong(),buffer.getLong());
+ }
+
private static long calculateMostSignificantBits(final BigDecimal underlying)
{
return 0; //TODO.
@@ -95,4 +106,47 @@ public final class Decimal128 extends Nu
{
return _lsb;
}
+
+ public byte[] asBytes()
+ {
+ byte[] bytes = new byte[16];
+ ByteBuffer buf = ByteBuffer.wrap(bytes);
+ buf.putLong(getMostSignificantBits());
+ buf.putLong(getLeastSignificantBits());
+ return bytes;
+ }
+
+ @Override
+ public boolean equals(final Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ final Decimal128 that = (Decimal128) o;
+
+ if (_lsb != that._lsb)
+ {
+ return false;
+ }
+ if (_msb != that._msb)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = (int) (_msb ^ (_msb >>> 32));
+ result = 31 * result + (int) (_lsb ^ (_lsb >>> 32));
+ return result;
+ }
}
Modified: qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal32.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal32.java?rev=1441982&r1=1441981&r2=1441982&view=diff
==============================================================================
--- qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal32.java (original)
+++ qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal32.java Sun Feb 3 22:57:25 2013
@@ -79,4 +79,32 @@ public final class Decimal32 extends Num
{
return _bits;
}
+
+ @Override
+ public boolean equals(final Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ final Decimal32 decimal32 = (Decimal32) o;
+
+ if (_bits != decimal32._bits)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return _bits;
+ }
}
Modified: qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal64.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal64.java?rev=1441982&r1=1441981&r2=1441982&view=diff
==============================================================================
--- qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal64.java (original)
+++ qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/Decimal64.java Sun Feb 3 22:57:25 2013
@@ -81,4 +81,32 @@ public final class Decimal64 extends Num
{
return _bits;
}
+
+ @Override
+ public boolean equals(final Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ final Decimal64 decimal64 = (Decimal64) o;
+
+ if (_bits != decimal64._bits)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return (int) (_bits ^ (_bits >>> 32));
+ }
}
Added: qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/UnknownDescribedType.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/UnknownDescribedType.java?rev=1441982&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/UnknownDescribedType.java (added)
+++ qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/amqp/UnknownDescribedType.java Sun Feb 3 22:57:25 2013
@@ -0,0 +1,88 @@
+/*
+ *
+ * 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;
+
+public class UnknownDescribedType implements DescribedType
+{
+ private final Object _descriptor;
+ private final Object _described;
+
+ public UnknownDescribedType(final Object descriptor, final Object described)
+ {
+ _descriptor = descriptor;
+ _described = described;
+ }
+
+ @Override
+ public Object getDescriptor()
+ {
+ return _descriptor;
+ }
+
+ @Override
+ public Object getDescribed()
+ {
+ return _described;
+ }
+
+ @Override
+ public boolean equals(final Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ final UnknownDescribedType that = (UnknownDescribedType) o;
+
+ if (_described != null ? !_described.equals(that._described) : that._described != null)
+ {
+ return false;
+ }
+ if (_descriptor != null ? !_descriptor.equals(that._descriptor) : that._descriptor != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = _descriptor != null ? _descriptor.hashCode() : 0;
+ result = 31 * result + (_described != null ? _described.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "UnknownDescribedType{" +
+ "descriptor=" + _descriptor +
+ ", described=" + _described +
+ '}';
+ }
+}
Added: qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/codec/Data.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/codec/Data.java?rev=1441982&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/codec/Data.java (added)
+++ qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/codec/Data.java Sun Feb 3 22:57:25 2013
@@ -0,0 +1,168 @@
+/*
+ *
+ * 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.codec;
+
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.qpid.proton.amqp.Binary;
+import org.apache.qpid.proton.amqp.Decimal128;
+import org.apache.qpid.proton.amqp.Decimal32;
+import org.apache.qpid.proton.amqp.Decimal64;
+import org.apache.qpid.proton.amqp.DescribedType;
+import org.apache.qpid.proton.amqp.Symbol;
+import org.apache.qpid.proton.amqp.UnsignedByte;
+import org.apache.qpid.proton.amqp.UnsignedInteger;
+import org.apache.qpid.proton.amqp.UnsignedLong;
+import org.apache.qpid.proton.amqp.UnsignedShort;
+
+public interface Data
+{
+
+
+ enum DataType
+ {
+ NULL,
+ BOOL,
+ UBYTE,
+ BYTE,
+ USHORT,
+ SHORT,
+ UINT,
+ INT,
+ CHAR,
+ ULONG,
+ LONG,
+ TIMESTAMP,
+ FLOAT,
+ DOUBLE,
+ DECIMAL32,
+ DECIMAL64,
+ DECIMAL128,
+ UUID,
+ BINARY,
+ STRING,
+ SYMBOL,
+ DESCRIBED,
+ ARRAY,
+ LIST,
+ MAP
+ }
+
+ void free();
+// int errno();
+// String error();
+
+ void clear();
+ long size();
+ void rewind();
+ DataType next();
+ DataType prev();
+ boolean enter();
+ boolean exit();
+
+ DataType type();
+
+// int print();
+// int format(ByteBuffer buf);
+ Binary encode();
+ long encode(ByteBuffer buf);
+ long decode(ByteBuffer buf);
+
+ void putList();
+ void putMap();
+ void putArray(boolean described, DataType type);
+ void putDescribed();
+ void putNull();
+ void putBoolean(boolean b);
+ void putUnsignedByte(UnsignedByte ub);
+ void putByte(byte b);
+ void putUnsignedShort(UnsignedShort us);
+ void putShort(short s);
+ void putUnsignedInteger(UnsignedInteger ui);
+ void putInt(int i);
+ void putChar(int c);
+ void putUnsignedLong(UnsignedLong ul);
+ void putLong(long l);
+ void putTimestamp(Date t);
+ void putFloat(float f);
+ void putDouble(double d);
+ void putDecimal32(Decimal32 d);
+ void putDecimal64(Decimal64 d);
+ void putDecimal128(Decimal128 d);
+ void putUUID(UUID u);
+ void putBinary(Binary bytes);
+ void putBinary(byte[] bytes);
+ void putString(String string);
+ void putSymbol(Symbol symbol);
+ void putObject(Object o);
+ void putJavaMap(Map<Object, Object> map);
+ void putJavaList(List<Object> list);
+ void putJavaArray(Object[] array);
+ void putDescribedType(DescribedType dt);
+
+ long getList();
+ long getMap();
+ long getArray();
+ boolean isArrayDescribed();
+ DataType getArrayType();
+ boolean isDescribed();
+ boolean isNull();
+ boolean getBoolean();
+ UnsignedByte getUnsignedByte();
+ byte getByte();
+ UnsignedShort getUnsignedShort();
+ short getShort();
+ UnsignedInteger getUnsignedInteger();
+ int getInt();
+ int getChar();
+ UnsignedLong getUnsignedLong();
+ long getLong();
+ Date getTimestamp();
+ float getFloat();
+ double getDouble();
+ Decimal32 getDecimal32();
+ Decimal64 getDecimal64();
+ Decimal128 getDecimal128();
+ UUID getUUID();
+ Binary getBinary();
+ String getString();
+ Symbol getSymbol();
+ Object getObject();
+ Map<Object, Object> getJavaMap();
+ List<Object> getJavaList();
+ Object[] getJavaArray();
+ DescribedType getDescribedType();
+ //pnAtomT getAtom();
+
+ void copy(Data src);
+ void append(Data src);
+ void appendn(Data src, int limit);
+ void narrow();
+ void widen();
+
+ // void dump();
+
+
+}
Added: qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/codec/DataFactory.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/codec/DataFactory.java?rev=1441982&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/codec/DataFactory.java (added)
+++ qpid/proton/trunk/proton-j/proton-api/src/main/java/org/apache/qpid/proton/codec/DataFactory.java Sun Feb 3 22:57:25 2013
@@ -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.codec;
+
+public interface DataFactory
+{
+ Data createData(long capacity);
+}
Modified: qpid/proton/trunk/proton-j/proton-api/src/main/resources/proton.py
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton-api/src/main/resources/proton.py?rev=1441982&r1=1441981&r2=1441982&view=diff
==============================================================================
--- qpid/proton/trunk/proton-j/proton-api/src/main/resources/proton.py (original)
+++ qpid/proton/trunk/proton-j/proton-api/src/main/resources/proton.py Sun Feb 3 22:57:25 2013
@@ -17,6 +17,11 @@
#
from uuid import UUID
+import uuid
+try:
+ bytes()
+except NameError:
+ bytes = str
from org.apache.qpid.proton import ProtonFactoryLoader, ProtonUnsupportedOperationException
from org.apache.qpid.proton.engine import \
@@ -25,15 +30,30 @@ from org.apache.qpid.proton.engine impor
EndpointState, TransportException
from org.apache.qpid.proton.message import \
MessageFormat, MessageFactory, Message as JMessage
+from org.apache.qpid.proton.codec import \
+ DataFactory, Data as JData
from org.apache.qpid.proton.messenger import MessengerFactory, MessengerException, Status
from org.apache.qpid.proton.amqp.messaging import Source, Target, Accepted, AmqpValue
-from org.apache.qpid.proton.amqp import UnsignedInteger
-from jarray import zeros
-from java.util import EnumSet, UUID as JUUID
+from org.apache.qpid.proton.amqp import UnsignedInteger, UnsignedLong, UnsignedByte, UnsignedShort, Symbol, \
+ Decimal32, Decimal64, Decimal128
+from jarray import zeros, array
+from java.util import EnumSet, UUID as JUUID, Date as JDate
from java.util.concurrent import TimeoutException as Timeout
+from java.nio import ByteBuffer
+from java.lang import Character as JCharacter, String as JString, Integer as JInteger
LANGUAGE = "Java"
+
+class Constant(object):
+
+ def __init__(self, name):
+ self.name = name
+
+ def __repr__(self):
+ return self.name
+
+
class Skipped(Exception):
skipped = True
@@ -57,6 +77,8 @@ protonFactoryLoader = ProtonFactoryLoade
engineFactory = protonFactoryLoader.loadFactory(EngineFactory)
messageFactory = protonFactoryLoader.loadFactory(MessageFactory)
messengerFactory = protonFactoryLoader.loadFactory(MessengerFactory)
+dataFactory = protonFactoryLoader.loadFactory(DataFactory)
+
class Endpoint(object):
@@ -501,17 +523,453 @@ The idle timeout of the connection (in m
#return pn_transport_get_frames_input(self._trans)
raise Skipped()
+class UnmappedType:
+
+ def __init__(self, msg):
+ self.msg = msg
+
+ def __repr__(self):
+ return "UnmappedType(%s)" % self.msg
+
+
+class ulong(long):
+
+ def __repr__(self):
+ return "ulong(%s)" % long.__repr__(self)
+
+class timestamp(long):
+
+ def __repr__(self):
+ return "timestamp(%s)" % long.__repr__(self)
+
class symbol(unicode):
def __repr__(self):
return "symbol(%s)" % unicode.__repr__(self)
+class char(unicode):
+
+ def __repr__(self):
+ return "char(%s)" % unicode.__repr__(self)
+
+class Described(object):
+
+ def __init__(self, descriptor, value):
+ self.descriptor = descriptor
+ self.value = value
+
+ def __repr__(self):
+ return "Described(%r, %r)" % (self.descriptor, self.value)
+
+ def __eq__(self, o):
+ if isinstance(o, Described):
+ return self.descriptor == o.descriptor and self.value == o.value
+ else:
+ return False
+
+UNDESCRIBED = Constant("UNDESCRIBED")
+
+class Array(object):
+
+ def __init__(self, descriptor, type, *elements):
+ self.descriptor = descriptor
+ self.type = type
+ self.elements = elements
+
+ def __repr__(self):
+ if self.elements:
+ els = ", %s" % (", ".join(map(repr, self.elements)))
+ else:
+ els = ""
+ return "Array(%r, %r%s)" % (self.descriptor, self.type, els)
+
+ def __eq__(self, o):
+ if isinstance(o, Array):
+ return self.descriptor == o.descriptor and \
+ self.type == o.type and self.elements == o.elements
+ else:
+ return False
+
+
class Data(object):
+ NULL = JData.DataType.NULL;
+ BOOL = JData.DataType.BOOL;
+ UBYTE = JData.DataType.UBYTE;
+ BYTE = JData.DataType.BYTE;
+ USHORT = JData.DataType.USHORT;
+ SHORT = JData.DataType.SHORT;
+ UINT = JData.DataType.UINT;
+ INT = JData.DataType.INT;
+ CHAR = JData.DataType.CHAR;
+ ULONG = JData.DataType.ULONG;
+ LONG = JData.DataType.LONG;
+ TIMESTAMP = JData.DataType.TIMESTAMP;
+ FLOAT = JData.DataType.FLOAT;
+ DOUBLE = JData.DataType.DOUBLE;
+ DECIMAL32 = JData.DataType.DECIMAL32;
+ DECIMAL64 = JData.DataType.DECIMAL64;
+ DECIMAL128 = JData.DataType.DECIMAL128;
+ UUID = JData.DataType.UUID;
+ BINARY = JData.DataType.BINARY;
+ STRING = JData.DataType.STRING;
+ SYMBOL = JData.DataType.SYMBOL;
+ DESCRIBED = JData.DataType.DESCRIBED;
+ ARRAY = JData.DataType.ARRAY;
+ LIST = JData.DataType.LIST;
+ MAP = JData.DataType.MAP;
- SYMBOL = None
+ def __init__(self, capacity=16):
+ try:
+ self._data = dataFactory.createData(capacity)
+ except ProtonUnsupportedOperationException:
+ raise Skipped()
- def __init__(self, *args, **kwargs):
- raise Skipped()
+ def __del__(self):
+ if hasattr(self, "_data"):
+ pn_data_free(self._data)
+ del self._data
+
+ def clear(self):
+ self._data.clear()
+
+ def rewind(self):
+ self._data.rewind()
+
+ def next(self):
+ return self._data.next()
+
+ def prev(self):
+ return self._data.prev()
+
+ def enter(self):
+ return self._data.enter()
+
+ def exit(self):
+ return self._data.exit()
+
+ def type(self):
+ return self._data.type()
+
+ def encode(self):
+
+ b = self._data.encode()
+ return b.getArray().tostring()[b.getArrayOffset():b.getLength()]
+
+ def decode(self, encoded):
+ return self._data.decode(ByteBuffer.wrap(encoded))
+
+ def put_list(self):
+ self._data.putList()
+
+ def put_map(self):
+ self._data.putMap()
+
+ def put_array(self, described, element_type):
+ self._data.putArray(described, element_type)
+
+ def put_described(self):
+ self._data.putDescribed()
+
+ def put_null(self):
+ self._data.putNull()
+
+ def put_bool(self, b):
+ self._data.putBoolean(b)
+
+ def put_ubyte(self, ub):
+ self._data.putUnsignedByte(UnsignedByte.valueOf(ub))
+
+ def put_byte(self, b):
+ self._data.putByte(b)
+
+ def put_ushort(self, us):
+ self._data.putUnsignedShort(UnsignedShort.valueOf(us))
+
+ def put_short(self, s):
+ self._data.putShort(s)
+
+ def put_uint(self, ui):
+ self._data.putUnsignedInteger(UnsignedInteger.valueOf(ui))
+
+ def put_int(self, i):
+ self._data.putInt(i)
+
+ def put_char(self, c):
+ self._data.putChar(ord(c))
+
+ def put_ulong(self, ul):
+ self._data.putUnsignedLong(UnsignedLong.valueOf(ul))
+
+ def put_long(self, l):
+ self._data.putLong(l)
+
+ def put_timestamp(self, t):
+ self._data.putTimestamp(JDate(t))
+
+ def put_float(self, f):
+ self._data.putFloat(f)
+
+ def put_double(self, d):
+ self._data.putDouble(d)
+
+ def put_decimal32(self, d):
+ self._data.putDecimal32(Decimal32(d))
+
+ def put_decimal64(self, d):
+ self._data.putDecimal64(Decimal64(d))
+
+ def put_decimal128(self, d):
+ self._data.putDecimal128(Decimal128(d))
+
+ def put_uuid(self, u):
+ u = JUUID.fromString( str(u) )
+ self._data.putUUID(u)
+
+ def put_binary(self, b):
+ self._data.putBinary(b)
+
+ def put_string(self, s):
+ self._data.putString(s)
+
+ def put_symbol(self, s):
+ self._data.putSymbol(Symbol.valueOf(s))
+
+ def get_list(self):
+ return self._data.getList()
+
+ def get_map(self):
+ return self._data.getMap()
+
+ def get_array(self):
+ count = self._data.getArray()
+ described = self._data.isArrayDescribed()
+ type = self._data.getArrayType()
+ return count, described, type
+
+ def is_described(self):
+ return self._data.isDescribed()
+
+ def is_null(self):
+ return self._data.isNull()
+
+ def get_bool(self):
+ return self._data.getBoolean()
+
+ def get_ubyte(self):
+ return self._data.getUnsignedByte().shortValue()
+
+ def get_byte(self):
+ return self._data.getByte()
+
+ def get_ushort(self):
+ return self._data.getUnsignedShort().intValue()
+
+ def get_short(self):
+ return self._data.getShort()
+
+ def get_int(self):
+ return self._data.getInt()
+
+ def get_uint(self):
+ return self._data.getUnsignedInteger().longValue()
+
+ def get_char(self):
+ return char(unichr(self._data.getChar()))
+
+ def get_ulong(self):
+ return ulong(self._data.getUnsignedLong().longValue())
+
+ def get_long(self):
+ return self._data.getLong()
+
+ def get_timestamp(self):
+ return self._data.getTimestamp().getTime()
+
+ def get_float(self):
+ return self._data.getFloat()
+
+ def get_double(self):
+ return self._data.getDouble()
+
+ def get_decimal32(self):
+ return self._data.getDecimal32().getBits()
+
+ def get_decimal64(self):
+ return self._data.getDecimal64().getBits()
+
+ def get_decimal128(self):
+ return self._data.getDecimal128().asBytes().tostring()
+
+ def get_uuid(self):
+ return UUID(self._data.getUUID().toString() )
+
+ def get_binary(self):
+ b = self._data.getBinary()
+ return b.getArray().tostring()[b.getArrayOffset():b.getArrayOffset()+b.getLength()]
+
+ def get_string(self):
+ return self._data.getString()
+
+ def get_symbol(self):
+ return symbol(self._data.getSymbol().toString())
+
+ def put_dict(self, d):
+ self.put_map()
+ self.enter()
+ try:
+ for k, v in d.items():
+ self.put_object(k)
+ self.put_object(v)
+ finally:
+ self.exit()
+
+ def get_dict(self):
+ if self.enter():
+ try:
+ result = {}
+ while self.next():
+ k = self.get_object()
+ if self.next():
+ v = self.get_object()
+ else:
+ v = None
+ result[k] = v
+ finally:
+ self.exit()
+ return result
+
+ def put_sequence(self, s):
+ self.put_list()
+ self.enter()
+ try:
+ for o in s:
+ self.put_object(o)
+ finally:
+ self.exit()
+
+ def get_sequence(self):
+ if self.enter():
+ try:
+ result = []
+ while self.next():
+ result.append(self.get_object())
+ finally:
+ self.exit()
+ return result
+
+ def get_py_described(self):
+ if self.enter():
+ try:
+ self.next()
+ descriptor = self.get_object()
+ self.next()
+ value = self.get_object()
+ finally:
+ self.exit()
+ return Described(descriptor, value)
+
+ def put_py_described(self, d):
+ self.put_described()
+ self.enter()
+ try:
+ self.put_object(d.descriptor)
+ self.put_object(d.value)
+ finally:
+ self.exit()
+
+ def get_py_array(self):
+ count, described, type = self.get_array()
+ if self.enter():
+ try:
+ if described:
+ self.next()
+ descriptor = self.get_object()
+ else:
+ descriptor = UNDESCRIBED
+ elements = []
+ while self.next():
+ elements.append(self.get_object())
+ finally:
+ self.exit()
+ return Array(descriptor, type, *elements)
+
+ def put_py_array(self, a):
+ self.put_array(a.descriptor != UNDESCRIBED, a.type)
+ self.enter()
+ try:
+ for e in a.elements:
+ self.put_object(e)
+ finally:
+ self.exit()
+
+ put_mappings = {
+ None.__class__: lambda s, _: s.put_null(),
+ bool: put_bool,
+ dict: put_dict,
+ list: put_sequence,
+ tuple: put_sequence,
+ unicode: put_string,
+ bytes: put_binary,
+ symbol: put_symbol,
+ int: put_long,
+ char: put_char,
+ long: put_long,
+ ulong: put_ulong,
+ timestamp: put_timestamp,
+ float: put_double,
+ uuid.UUID: put_uuid,
+ Described: put_py_described,
+ Array: put_py_array
+ }
+
+ get_mappings = {
+ NULL: lambda s: None,
+ BOOL: get_bool,
+ BYTE: get_byte,
+ UBYTE: get_ubyte,
+ SHORT: get_short,
+ USHORT: get_ushort,
+ INT: get_int,
+ UINT: get_uint,
+ CHAR: get_char,
+ LONG: get_long,
+ ULONG: get_ulong,
+ TIMESTAMP: get_timestamp,
+ FLOAT: get_float,
+ DOUBLE: get_double,
+ DECIMAL32: get_decimal32,
+ DECIMAL64: get_decimal64,
+ DECIMAL128: get_decimal128,
+ UUID: get_uuid,
+ BINARY: get_binary,
+ STRING: get_string,
+ SYMBOL: get_symbol,
+ DESCRIBED: get_py_described,
+ ARRAY: get_py_array,
+ LIST: get_sequence,
+ MAP: get_dict
+ }
+
+ def put_object(self, obj):
+ putter = self.put_mappings[obj.__class__]
+ putter(self, obj)
+
+
+ def get_object(self):
+ type = self.type()
+ if type is None: return None
+ getter = self.get_mappings.get(type)
+ if getter:
+ return getter(self)
+ else:
+ self.dump()
+ return UnmappedType(str(type))
+
+ def copy(self, src):
+ self._data.copy(src._data)
+
+ def format(self):
+ return self._data.toString()
class Messenger(object):
@@ -918,16 +1376,19 @@ class Listener(object):
__all__ = [
"ACCEPTED",
+ "Array",
"LANGUAGE",
"MANUAL",
"PENDING",
"REJECTED",
"PN_SESSION_WINDOW",
+ "char",
"Condition",
"Connection",
"Connector",
"Data",
"Delivery",
+ "Described",
"Driver",
"Endpoint",
"Link",
@@ -947,7 +1408,10 @@ __all__ = [
"SSLSessionDetails",
"SSLUnavailable",
"symbol",
+ "timestamp",
"Terminus",
"Timeout",
"Transport",
- "TransportException"]
+ "TransportException",
+ "ulong",
+ "UNDESCRIBED"]
Added: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataFactoryImpl.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataFactoryImpl.java?rev=1441982&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataFactoryImpl.java (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/codec/impl/DataFactoryImpl.java Sun Feb 3 22:57:25 2013
@@ -0,0 +1,35 @@
+/*
+ *
+ * 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.codec.impl;
+
+import org.apache.qpid.proton.ProtonUnsupportedOperationException;
+import org.apache.qpid.proton.codec.Data;
+import org.apache.qpid.proton.codec.DataFactory;
+
+public class DataFactoryImpl implements DataFactory
+{
+ @Override
+ public Data createData(final long capacity)
+ {
+ // TODO
+ throw new ProtonUnsupportedOperationException();
+ }
+}
Added: qpid/proton/trunk/proton-j/proton/src/main/resources/META-INF/services/org.apache.qpid.proton.codec.DataFactory
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/resources/META-INF/services/org.apache.qpid.proton.codec.DataFactory?rev=1441982&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/resources/META-INF/services/org.apache.qpid.proton.codec.DataFactory (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/resources/META-INF/services/org.apache.qpid.proton.codec.DataFactory Sun Feb 3 22:57:25 2013
@@ -0,0 +1 @@
+org.apache.qpid.proton.codec.impl.DataFactoryImpl
\ 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