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 2012/12/13 20:28:03 UTC
svn commit: r1421436 - in
/qpid/proton/branches/jni-binding/proton-c/bindings/java: ./
jni/src/main/java/org/apache/qpid/proton/data/
jni/src/main/java/org/apache/qpid/proton/data/jni/
jni/src/main/java/org/apache/qpid/proton/engine/ jni/src/main/java/...
Author: rgodfrey
Date: Thu Dec 13 19:27:56 2012
New Revision: 1421436
URL: http://svn.apache.org/viewvc?rev=1421436&view=rev
Log:
NO-JIRA : added simple JNI implementations
Added:
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/data/
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/data/jni/
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIConnection.java
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIDelivery.java
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNILink.java
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIReceiver.java
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISasl.java
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISender.java
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISession.java
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISsl.java
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNITransport.java
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/StateConverter.java
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/message/
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/message/jni/
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/message/jni/JNIMessage.java
Removed:
qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/
Modified:
qpid/proton/branches/jni-binding/proton-c/bindings/java/ (props changed)
Propchange: qpid/proton/branches/jni-binding/proton-c/bindings/java/
------------------------------------------------------------------------------
--- svn:externals (added)
+++ svn:externals Thu Dec 13 19:27:56 2012
@@ -0,0 +1 @@
+../../../proton-j/proton-api api
Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIConnection.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIConnection.java?rev=1421436&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIConnection.java (added)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIConnection.java Thu Dec 13 19:27:56 2012
@@ -0,0 +1,189 @@
+/*
+ *
+ * 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.engine.jni;
+
+import java.util.EnumSet;
+import org.apache.qpid.proton.engine.Connection;
+import org.apache.qpid.proton.engine.Delivery;
+import org.apache.qpid.proton.engine.EndpointError;
+import org.apache.qpid.proton.engine.EndpointState;
+import org.apache.qpid.proton.engine.Link;
+import org.apache.qpid.proton.engine.Session;
+import org.apache.qpid.proton.jni.Proton;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_connection_t;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_delivery_t;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_link_t;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_session_t;
+
+public class JNIConnection implements Connection
+{
+ private SWIGTYPE_p_pn_connection_t _impl;
+ private Object _context;
+
+ public JNIConnection()
+ {
+ this(Proton.pn_connection());
+ }
+
+ public JNIConnection(SWIGTYPE_p_pn_connection_t connection_t)
+ {
+ _impl = connection_t;
+ Proton.pn_connection_set_context(_impl, this);
+ }
+
+
+
+ @Override
+ public Session session()
+ {
+ return new JNISession(Proton.pn_session(_impl));
+ }
+
+ @Override
+ public Session sessionHead(EnumSet<EndpointState> local, EnumSet<EndpointState> remote)
+ {
+ return JNISession.getSession(Proton.pn_session_head(_impl, StateConverter.getStateMask(local, remote)));
+ }
+
+ @Override
+ public Link linkHead(EnumSet<EndpointState> local, EnumSet<EndpointState> remote)
+ {
+ return JNILink.getLink(Proton.pn_link_head(_impl, StateConverter.getStateMask(local, remote)));
+ }
+
+ @Override
+ public Delivery getWorkHead()
+ {
+ return JNIDelivery.getDelivery(Proton.pn_work_head(_impl));
+
+ }
+
+ @Override
+ public void setContainer(String container)
+ {
+ Proton.pn_connection_set_container(_impl, container);
+ }
+
+ @Override
+ public void setHostname(String hostname)
+ {
+ Proton.pn_connection_set_hostname(_impl, hostname);
+ }
+
+ @Override
+ public String getRemoteContainer()
+ {
+ return Proton.pn_connection_remote_container(_impl);
+ }
+
+ @Override
+ public String getRemoteHostname()
+ {
+ return Proton.pn_connection_remote_hostname(_impl);
+ }
+
+ @Override
+ public EndpointState getLocalState()
+ {
+ return StateConverter.getLocalState(Proton.pn_connection_state(_impl));
+ }
+
+ @Override
+ public EndpointState getRemoteState()
+ {
+ return StateConverter.getRemoteState(Proton.pn_connection_state(_impl));
+ }
+
+ @Override
+ public EndpointError getLocalError()
+ {
+ //TODO
+ return null;
+ }
+
+ @Override
+ public EndpointError getRemoteError()
+ {
+ //TODO
+ return null;
+ }
+
+ @Override
+ public void free()
+ {
+ if(_impl != null)
+ {
+ Proton.pn_connection_set_context(_impl, null);
+ Proton.pn_connection_free(_impl);
+ _impl = null;
+ }
+ }
+
+ @Override
+ public void open()
+ {
+ Proton.pn_connection_open(_impl);
+ }
+
+ @Override
+ public void close()
+ {
+ Proton.pn_connection_close(_impl);
+ }
+
+ @Override
+ public void setContext(Object o)
+ {
+ _context = o;
+ }
+
+ @Override
+ public Object getContext()
+ {
+ return _context;
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ free();
+ super.finalize();
+ }
+
+ SWIGTYPE_p_pn_connection_t getImpl()
+ {
+ return _impl;
+ }
+
+ public static JNIConnection getConnection(SWIGTYPE_p_pn_connection_t connection_t)
+ {
+ if(connection_t != null)
+ {
+ JNIConnection connectionObj = (JNIConnection) Proton.pn_connection_get_context(connection_t);
+ if(connectionObj == null)
+ {
+ connectionObj = new JNIConnection(connection_t);
+ }
+ return connectionObj;
+ }
+ return null;
+ }
+}
Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIDelivery.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIDelivery.java?rev=1421436&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIDelivery.java (added)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIDelivery.java Thu Dec 13 19:27:56 2012
@@ -0,0 +1,229 @@
+/*
+ *
+ * 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.engine.jni;
+
+import org.apache.qpid.proton.engine.Delivery;
+import org.apache.qpid.proton.engine.Link;
+import org.apache.qpid.proton.jni.Proton;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_delivery_t;
+import org.apache.qpid.proton.jni.pn_delivery_tag_t;
+import org.apache.qpid.proton.jni.pn_disposition_t;
+import org.apache.qpid.proton.amqp.messaging.Accepted;
+import org.apache.qpid.proton.amqp.messaging.Modified;
+import org.apache.qpid.proton.amqp.messaging.Received;
+import org.apache.qpid.proton.amqp.messaging.Rejected;
+import org.apache.qpid.proton.amqp.messaging.Released;
+import org.apache.qpid.proton.amqp.transport.DeliveryState;
+
+public class JNIDelivery implements Delivery
+{
+ private SWIGTYPE_p_pn_delivery_t _impl;
+ private Object _context;
+ private JNILink _link;
+
+ public JNIDelivery(SWIGTYPE_p_pn_delivery_t delivery_t)
+ {
+ _impl = delivery_t;
+ Proton.pn_delivery_set_context(_impl, this);
+ _link = JNILink.getLink(Proton.pn_delivery_link(_impl));
+ }
+
+ static Delivery getDelivery(SWIGTYPE_p_pn_delivery_t delivery_t)
+ {
+ if(delivery_t != null)
+ {
+ Delivery deliveryObj = (Delivery) Proton.pn_delivery_get_context(delivery_t);
+ if(deliveryObj == null)
+ {
+ deliveryObj = new JNIDelivery(delivery_t);
+ }
+ return deliveryObj;
+ }
+ return null;
+ }
+
+
+ public Object getContext()
+ {
+ return _context;
+ }
+
+ @Override
+ public byte[] getTag()
+ {
+ // TODO - pn_delivery_tag_t should be bytes not string
+ return Proton.pn_delivery_tag(_impl);
+
+ }
+
+ @Override
+ public Link getLink()
+ {
+ return _link;
+ }
+
+ @Override
+ public DeliveryState getLocalState()
+ {
+ return convertDisposition(Proton.pn_delivery_local_state(_impl));
+ }
+
+ @Override
+ public DeliveryState getRemoteState()
+ {
+ return convertDisposition(Proton.pn_delivery_remote_state(_impl));
+ }
+
+ @Override
+ public boolean remotelySettled()
+ {
+ return Proton.pn_delivery_settled(_impl);
+ }
+
+ @Override
+ public int getMessageFormat()
+ {
+ return 0; //TODO
+ }
+
+ @Override
+ public void disposition(DeliveryState state)
+ {
+ Proton.pn_delivery_update(_impl, convertState(state));
+ //TODO
+ }
+
+ private static pn_disposition_t convertState(DeliveryState state)
+ {
+ //TODO - disposition properties conversion
+ if(state instanceof Accepted)
+ {
+ return pn_disposition_t.PN_ACCEPTED;
+ }
+ else if(state instanceof Rejected)
+ {
+ return pn_disposition_t.PN_REJECTED;
+ }
+ else if(state instanceof Modified)
+ {
+ return pn_disposition_t.PN_MODIFIED;
+ }
+ else if(state instanceof Received)
+ {
+ return pn_disposition_t.PN_RECEIVED;
+ }
+ else if(state instanceof Released)
+ {
+ return pn_disposition_t.PN_RELEASED;
+ }
+
+ return null;
+ }
+
+ private static DeliveryState convertDisposition(pn_disposition_t disposition)
+ {
+ //TODO - disposition properties conversion
+ if(pn_disposition_t.PN_ACCEPTED.equals(disposition))
+ {
+ return Accepted.getInstance();
+ }
+ else if(pn_disposition_t.PN_REJECTED.equals(disposition))
+ {
+ return new Rejected();
+ }
+ else if(pn_disposition_t.PN_MODIFIED.equals(disposition))
+ {
+ return new Modified();
+ }
+ else if(pn_disposition_t.PN_MODIFIED.equals(disposition))
+ {
+ return new Modified();
+ }
+ else if(pn_disposition_t.PN_RELEASED.equals(disposition))
+ {
+ return new Released();
+ }
+
+ return null;
+ }
+
+ @Override
+ public void settle()
+ {
+ Proton.pn_delivery_settle(_impl);
+ }
+
+ @Override
+ public void free()
+ {
+ if(_impl != null)
+ {
+ Proton.pn_delivery_set_context(_impl, null);
+// Proton.pn_delivery_free(_impl);
+ _impl = null;
+ }
+ }
+
+ @Override
+ public Delivery getWorkNext()
+ {
+ return getDelivery(Proton.pn_work_next(_impl));
+ }
+
+ @Override
+ public boolean isWritable()
+ {
+ return Proton.pn_delivery_writable(_impl);
+ }
+
+ @Override
+ public boolean isReadable()
+ {
+ return Proton.pn_delivery_readable(_impl);
+ }
+
+ public void setContext(Object context)
+ {
+ _context = context;
+ }
+
+ @Override
+ public boolean isUpdated()
+ {
+ return Proton.pn_delivery_updated(_impl);
+ }
+
+ @Override
+ public boolean isSettled()
+ {
+ return Proton.pn_delivery_settled(_impl);
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ if(isSettled())
+ {
+ free();
+ }
+ super.finalize();
+ }
+}
Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNILink.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNILink.java?rev=1421436&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNILink.java (added)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNILink.java Thu Dec 13 19:27:56 2012
@@ -0,0 +1,473 @@
+/*
+ *
+ * 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.engine.jni;
+
+import java.util.EnumSet;
+import java.util.Iterator;
+import org.apache.qpid.proton.engine.Delivery;
+import org.apache.qpid.proton.engine.EndpointError;
+import org.apache.qpid.proton.engine.EndpointState;
+import org.apache.qpid.proton.engine.Link;
+import org.apache.qpid.proton.engine.Session;
+import org.apache.qpid.proton.jni.Proton;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_link_t;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_session_t;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_terminus_t;
+import org.apache.qpid.proton.jni.pn_durability_t;
+import org.apache.qpid.proton.jni.pn_expiry_policy_t;
+import org.apache.qpid.proton.jni.pn_terminus_type_t;
+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.messaging.TerminusDurability;
+import org.apache.qpid.proton.amqp.messaging.TerminusExpiryPolicy;
+import org.apache.qpid.proton.amqp.transaction.Coordinator;
+import org.apache.qpid.proton.amqp.transport.ReceiverSettleMode;
+import org.apache.qpid.proton.amqp.transport.SenderSettleMode;
+import org.apache.qpid.proton.amqp.transport.Source;
+import org.apache.qpid.proton.amqp.transport.Target;
+
+abstract class JNILink implements Link
+{
+ private SWIGTYPE_p_pn_link_t _impl;
+ private Object _context;
+ private JNISession _session;
+
+ public JNILink(SWIGTYPE_p_pn_link_t link_t)
+ {
+ _impl = link_t;
+ Proton.pn_link_set_context(_impl, this);
+ _session = JNISession.getSession(Proton.pn_link_session(_impl));
+ }
+
+ @Override
+ public String getName()
+ {
+ return Proton.pn_link_name(_impl);
+ }
+
+ @Override
+ public Delivery delivery(byte[] tag, int offset, int length)
+ {
+ byte[] dup = new byte[length];
+ System.arraycopy(tag,offset,dup,0,length);
+ return JNIDelivery.getDelivery(Proton.pn_delivery(_impl, dup));
+ }
+
+ @Override
+ public Delivery delivery(byte[] tag)
+ {
+ return JNIDelivery.getDelivery(Proton.pn_delivery(_impl, tag));
+ }
+
+ @Override
+ public Iterator<Delivery> unsettled()
+ {
+
+ return null; //TODO
+ }
+
+ @Override
+ public Delivery current()
+ {
+ return JNIDelivery.getDelivery(Proton.pn_link_current(_impl));
+ }
+
+ @Override
+ public boolean advance()
+ {
+ return Proton.pn_link_advance(_impl);
+ }
+
+ @Override
+ public Source getSource()
+ {
+ return convertSource(Proton.pn_link_source(_impl));
+ }
+
+ @Override
+ public Target getTarget()
+ {
+ return convertTarget(Proton.pn_link_target(_impl));
+ }
+
+ @Override
+ public void setSource(Source source)
+ {
+ SWIGTYPE_p_pn_terminus_t source_t = Proton.pn_link_source(_impl);
+
+ org.apache.qpid.proton.amqp.messaging.Source s = (org.apache.qpid.proton.amqp.messaging.Source) source;
+ Proton.pn_terminus_set_address(source_t,s.getAddress());
+ Proton.pn_terminus_set_dynamic(source_t,s.getDynamic());
+ setDurability(source_t, s.getDurable() == null ? null : s.getDurable().getValue());
+ setExpiryPolicy(source_t, s.getExpiryPolicy() == null ? null : s.getExpiryPolicy().getPolicy());
+ if(s.getTimeout() != null)
+ {
+ Proton.pn_terminus_set_timeout(source_t, s.getTimeout().longValue());
+ }
+ Proton.pn_terminus_set_type(source_t, pn_terminus_type_t.PN_SOURCE);
+
+ //TODO - capabilities
+
+ }
+
+ private static void setDurability(SWIGTYPE_p_pn_terminus_t terminus, UnsignedInteger durable)
+ {
+ if(durable != null)
+ {
+ if(durable.equals(TerminusDurability.NONE))
+ {
+ Proton.pn_terminus_set_durability(terminus, pn_durability_t.PN_NONDURABLE);
+ }
+ else if(durable.equals(TerminusDurability.CONFIGURATION))
+ {
+ Proton.pn_terminus_set_durability(terminus, pn_durability_t.PN_CONFIGURATION);
+ }
+ else if(durable.equals(TerminusDurability.UNSETTLED_STATE))
+ {
+ Proton.pn_terminus_set_durability(terminus, pn_durability_t.PN_DELIVERIES);
+ }
+ }
+ }
+
+ private static void setExpiryPolicy(SWIGTYPE_p_pn_terminus_t terminus, Symbol policy)
+ {
+
+ if(TerminusExpiryPolicy.NEVER.equals(policy))
+ {
+ Proton.pn_terminus_set_expiry_policy(terminus, pn_expiry_policy_t.PN_NEVER);
+ }
+ else if(TerminusExpiryPolicy.CONNECTION_CLOSE.equals(policy))
+ {
+ Proton.pn_terminus_set_expiry_policy(terminus, pn_expiry_policy_t.PN_CONNECTION_CLOSE);
+ }
+ else if(TerminusExpiryPolicy.SESSION_END.equals(policy))
+ {
+ Proton.pn_terminus_set_expiry_policy(terminus, pn_expiry_policy_t.PN_SESSION_CLOSE);
+ }
+ else if(TerminusExpiryPolicy.LINK_DETACH.equals(policy))
+ {
+ Proton.pn_terminus_set_expiry_policy(terminus, pn_expiry_policy_t.PN_LINK_CLOSE);
+ }
+
+ }
+
+ @Override
+ public void setTarget(Target target)
+ {
+ SWIGTYPE_p_pn_terminus_t target_t = Proton.pn_link_target(_impl);
+
+ if(target instanceof org.apache.qpid.proton.amqp.messaging.Target)
+ {
+ org.apache.qpid.proton.amqp.messaging.Target t = (org.apache.qpid.proton.amqp.messaging.Target) target;
+ Proton.pn_terminus_set_address(target_t, t.getAddress());
+ Proton.pn_terminus_set_dynamic(target_t, t.getDynamic());
+ setDurability(target_t, t.getDurable() == null ? null : t.getDurable().getValue());
+ setExpiryPolicy(target_t, t.getExpiryPolicy() == null ? null : t.getExpiryPolicy().getPolicy());
+ if(t.getTimeout() != null)
+ {
+ Proton.pn_terminus_set_timeout(target_t, t.getTimeout().longValue());
+ }
+ Proton.pn_terminus_set_type(target_t, pn_terminus_type_t.PN_TARGET);
+ }
+ else if(target instanceof Coordinator)
+ {
+ //TODO
+ Proton.pn_terminus_set_type(target_t, pn_terminus_type_t.PN_COORDINATOR);
+ }
+
+ }
+
+ @Override
+ public Source getRemoteSource()
+ {
+ return convertSource(Proton.pn_link_remote_source(_impl));
+ }
+
+ private Source convertSource(SWIGTYPE_p_pn_terminus_t source_t)
+ {
+ if(source_t != null)
+ {
+ org.apache.qpid.proton.amqp.messaging.Source s = new org.apache.qpid.proton.amqp.messaging.Source();
+
+ s.setAddress(Proton.pn_terminus_get_address(source_t));
+ s.setDynamic(Proton.pn_terminus_is_dynamic(source_t));
+ s.setTimeout(UnsignedInteger.valueOf(Proton.pn_terminus_get_timeout(source_t)));
+ s.setDurable(convertDurability(source_t));
+ s.setExpiryPolicy(convertExpiryPolicy(source_t));
+
+
+
+ return s;
+ }
+ else
+ {
+ return null;
+ }//TODO
+ }
+
+ private static TerminusExpiryPolicy convertExpiryPolicy(SWIGTYPE_p_pn_terminus_t source_t)
+ {
+ pn_expiry_policy_t expiry = Proton.pn_terminus_get_expiry_policy(source_t);
+ TerminusExpiryPolicy policy = null;
+ if(pn_expiry_policy_t.PN_NEVER.equals(expiry))
+ {
+ policy = TerminusExpiryPolicy.NEVER;
+ }
+ else if(pn_expiry_policy_t.PN_CONNECTION_CLOSE.equals(expiry))
+ {
+ policy = TerminusExpiryPolicy.CONNECTION_CLOSE;
+ }
+ else if (pn_expiry_policy_t.PN_SESSION_CLOSE.equals(expiry))
+ {
+ policy = TerminusExpiryPolicy.SESSION_END;
+ }
+ else if (pn_expiry_policy_t.PN_LINK_CLOSE.equals(expiry))
+ {
+ policy = TerminusExpiryPolicy.LINK_DETACH;
+ }
+ return policy;
+ }
+
+ private static TerminusDurability convertDurability(SWIGTYPE_p_pn_terminus_t source_t)
+ {
+ pn_durability_t durability = Proton.pn_terminus_get_durability(source_t);
+ if(pn_durability_t.PN_NONDURABLE.equals(durability))
+ {
+ return TerminusDurability.NONE;
+ }
+ else if(pn_durability_t.PN_CONFIGURATION.equals(durability))
+ {
+ return TerminusDurability.CONFIGURATION;
+ }
+ else if(pn_durability_t.PN_DELIVERIES.equals(durability))
+ {
+ return TerminusDurability.UNSETTLED_STATE;
+ }
+
+ return null;
+ }
+
+ @Override
+ public Target getRemoteTarget()
+ {
+ return convertTarget(Proton.pn_link_remote_target(_impl));
+ }
+
+ private Target convertTarget(SWIGTYPE_p_pn_terminus_t target_t)
+ {
+ if(target_t != null)
+ {
+ pn_terminus_type_t pn_terminus_type = Proton.pn_terminus_get_type(target_t);
+ if(pn_terminus_type_t.PN_TARGET.equals(pn_terminus_type) || pn_terminus_type_t.PN_UNSPECIFIED.equals(pn_terminus_type))
+ {
+ org.apache.qpid.proton.amqp.messaging.Target t = new org.apache.qpid.proton.amqp.messaging.Target();
+
+ t.setAddress(Proton.pn_terminus_get_address(target_t));
+ t.setDynamic(Proton.pn_terminus_is_dynamic(target_t));
+ t.setTimeout(UnsignedInteger.valueOf(Proton.pn_terminus_get_timeout(target_t)));
+ t.setDurable(convertDurability(target_t));
+ t.setExpiryPolicy(convertExpiryPolicy(target_t));
+
+ return t;
+ }
+ else if(pn_terminus_type_t.PN_COORDINATOR.equals(pn_terminus_type))
+ {
+ Coordinator c = new Coordinator();
+
+ // TODO
+
+ return c;
+ }
+ }
+
+ return null;
+ //TODO
+ }
+
+ @Override
+ public Link next(EnumSet<EndpointState> local, EnumSet<EndpointState> remote)
+ {
+ return getLink(Proton.pn_link_next(_impl, StateConverter.getStateMask(local, remote)));
+ }
+
+ static JNILink getLink(SWIGTYPE_p_pn_link_t link_t)
+ {
+ if(link_t != null)
+ {
+ JNILink link = (JNILink) Proton.pn_link_get_context(link_t);
+ if(link == null)
+ {
+ if(Proton.pn_link_is_receiver(link_t))
+ {
+ link = new JNIReceiver(link_t);
+ }
+ else if(Proton.pn_link_is_sender(link_t))
+ {
+ link = new JNISender(link_t);
+ }
+
+ }
+ return link;
+ }
+ return null;
+ }
+
+
+ @Override
+ public int getCredit()
+ {
+ return Proton.pn_link_credit(_impl);
+ }
+
+ @Override
+ public int getQueued()
+ {
+ return Proton.pn_link_queued(_impl);
+ }
+
+ @Override
+ public int getUnsettled()
+ {
+ return Proton.pn_link_unsettled(_impl);
+ }
+
+ @Override
+ public Session getSession()
+ {
+ return _session;
+ }
+
+ @Override
+ public SenderSettleMode getSenderSettleMode()
+ {
+ // TODO
+ return null;
+ }
+
+ @Override
+ public void setSenderSettleMode(SenderSettleMode senderSettleMode)
+ {
+ //TODO
+ }
+
+ @Override
+ public SenderSettleMode getRemoteSenderSettleMode()
+ {
+ return null; //TODO
+ }
+
+ @Override
+ public void setRemoteSenderSettleMode(SenderSettleMode remoteSenderSettleMode)
+ {
+ //TODO
+ }
+
+ @Override
+ public ReceiverSettleMode getReceiverSettleMode()
+ {
+ return null; //TODO
+ }
+
+ @Override
+ public void setReceiverSettleMode(ReceiverSettleMode receiverSettleMode)
+ {
+ //TODO
+ }
+
+ @Override
+ public ReceiverSettleMode getRemoteReceiverSettleMode()
+ {
+ return null; //TODO
+ }
+
+ @Override
+ public EndpointState getLocalState()
+ {
+ return StateConverter.getLocalState(Proton.pn_link_state(_impl));
+ }
+
+ @Override
+ public EndpointState getRemoteState()
+ {
+ return StateConverter.getRemoteState(Proton.pn_link_state(_impl));
+ }
+
+ @Override
+ public EndpointError getLocalError()
+ {
+ return null; //TODO
+ }
+
+ @Override
+ public EndpointError getRemoteError()
+ {
+ return null; //TODO
+ }
+
+ @Override
+ public void free()
+ {
+ if(_impl != null)
+ {
+ Proton.pn_link_set_context(_impl, null);
+ Proton.pn_link_free(_impl);
+ _impl = null;
+ }
+
+ }
+
+ @Override
+ public void open()
+ {
+ Proton.pn_link_open(_impl);
+ }
+
+ @Override
+ public void close()
+ {
+ Proton.pn_link_close(_impl);
+ }
+
+ @Override
+ public void setContext(Object o)
+ {
+ _context = o;
+ }
+
+ @Override
+ public Object getContext()
+ {
+ return _context;
+ }
+
+ SWIGTYPE_p_pn_link_t getImpl()
+ {
+ return _impl;
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ free();
+ super.finalize();
+ }
+}
Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIReceiver.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIReceiver.java?rev=1421436&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIReceiver.java (added)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIReceiver.java Thu Dec 13 19:27:56 2012
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.engine.jni;
+
+import java.nio.ByteBuffer;
+import org.apache.qpid.proton.engine.Receiver;
+import org.apache.qpid.proton.jni.Proton;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_link_t;
+
+public class JNIReceiver extends JNILink implements Receiver
+{
+ public JNIReceiver(SWIGTYPE_p_pn_link_t link_t)
+ {
+ super(link_t);
+ }
+
+ @Override
+ public void flow(int credits)
+ {
+ Proton.pn_link_flow(getImpl(), credits);
+ }
+
+ @Override
+ public int recv(byte[] bytes, int offset, int size)
+ {
+ return Proton.pn_link_recv(getImpl(), ByteBuffer.wrap(bytes,offset,size));
+ }
+
+ @Override
+ public void drain(int credit)
+ {
+ Proton.pn_link_drain(getImpl(), credit);
+ }
+}
Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISasl.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISasl.java?rev=1421436&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISasl.java (added)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISasl.java Thu Dec 13 19:27:56 2012
@@ -0,0 +1,175 @@
+/*
+ *
+ * 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.engine.jni;
+
+import java.nio.ByteBuffer;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.qpid.proton.engine.Sasl;
+import org.apache.qpid.proton.jni.Proton;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_sasl_t;
+import org.apache.qpid.proton.jni.pn_sasl_outcome_t;
+import org.apache.qpid.proton.jni.pn_sasl_state_t;
+
+public class JNISasl implements Sasl
+{
+ private final SWIGTYPE_p_pn_sasl_t _impl;
+
+ JNISasl(SWIGTYPE_p_pn_sasl_t sasl)
+ {
+ _impl = sasl;
+ }
+
+ @Override
+ public int input(byte[] bytes, int offset, int size)
+ {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public int output(byte[] bytes, int offset, int size)
+ {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ public SaslState getState()
+ {
+ return convertState(Proton.pn_sasl_state(_impl));
+ }
+
+ private static final Map<pn_sasl_state_t, SaslState> _states = new HashMap<pn_sasl_state_t, SaslState>();
+
+ static
+ {
+ _states.put(pn_sasl_state_t.PN_SASL_CONF, SaslState.PN_SASL_CONF);
+ _states.put(pn_sasl_state_t.PN_SASL_FAIL, SaslState.PN_SASL_FAIL);
+ _states.put(pn_sasl_state_t.PN_SASL_IDLE, SaslState.PN_SASL_IDLE);
+ _states.put(pn_sasl_state_t.PN_SASL_PASS, SaslState.PN_SASL_PASS);
+ _states.put(pn_sasl_state_t.PN_SASL_STEP, SaslState.PN_SASL_STEP);
+ }
+
+ private SaslState convertState(pn_sasl_state_t pn_sasl_state_t)
+ {
+ return _states.get(pn_sasl_state_t);
+ }
+
+ @Override
+ public void setMechanisms(String[] mechanisms)
+ {
+ StringBuilder build = new StringBuilder();
+ for(String mech : mechanisms)
+ {
+ if(build.length() > 0)
+ {
+ build.append(' ');
+ }
+ build.append(mech);
+ }
+ build.append((char)0);
+
+ Proton.pn_sasl_mechanisms(_impl, build.toString());
+ }
+
+ @Override
+ public String[] getRemoteMechanisms()
+ {
+ String mechs = Proton.pn_sasl_remote_mechanisms(_impl);
+ return mechs == null ? null : mechs.split(" ");
+ }
+
+ @Override
+ public int pending()
+ {
+ return (int) Proton.pn_sasl_pending(_impl);
+ }
+
+ @Override
+ public int recv(byte[] bytes, int offset, int size)
+ {
+ return Proton.pn_sasl_recv(_impl, ByteBuffer.wrap(bytes, offset, size));
+ }
+
+ @Override
+ public int send(byte[] bytes, int offset, int size)
+ {
+ return Proton.pn_sasl_send(_impl, ByteBuffer.wrap(bytes, offset, size));
+ }
+
+ @Override
+ public void done(SaslOutcome outcome)
+ {
+ Proton.pn_sasl_done(_impl, convertOutcome(outcome));
+ }
+
+
+ private static final EnumMap<SaslOutcome, pn_sasl_outcome_t> _outcomes =
+ new EnumMap<SaslOutcome,pn_sasl_outcome_t>(SaslOutcome.class);
+
+ private static final Map<pn_sasl_outcome_t, SaslOutcome> _pn_outcomes =
+ new HashMap<pn_sasl_outcome_t, SaslOutcome>();
+
+ private static void mapOutcome(SaslOutcome a, pn_sasl_outcome_t b)
+ {
+ _outcomes.put(a,b);
+ _pn_outcomes.put(b,a);
+ }
+
+ static
+ {
+ mapOutcome(SaslOutcome.PN_SASL_AUTH, pn_sasl_outcome_t.PN_SASL_AUTH);
+ mapOutcome(SaslOutcome.PN_SASL_NONE, pn_sasl_outcome_t.PN_SASL_NONE);
+ mapOutcome(SaslOutcome.PN_SASL_OK, pn_sasl_outcome_t.PN_SASL_OK);
+ mapOutcome(SaslOutcome.PN_SASL_PERM, pn_sasl_outcome_t.PN_SASL_PERM);
+ mapOutcome(SaslOutcome.PN_SASL_SYS, pn_sasl_outcome_t.PN_SASL_SYS);
+ mapOutcome(SaslOutcome.PN_SASL_TEMP, pn_sasl_outcome_t.PN_SASL_TEMP);
+ }
+
+ private static pn_sasl_outcome_t convertOutcome(SaslOutcome outcome)
+ {
+ return _outcomes.get(outcome);
+ }
+
+ @Override
+ public void plain(String username, String password)
+ {
+ Proton.pn_sasl_plain(_impl, username, password);
+ }
+
+ @Override
+ public SaslOutcome getOutcome()
+ {
+ return _pn_outcomes.get(Proton.pn_sasl_outcome(_impl));
+ }
+
+ @Override
+ public void client()
+ {
+ Proton.pn_sasl_client(_impl);
+ }
+
+ @Override
+ public void server()
+ {
+ Proton.pn_sasl_server(_impl);
+ }
+}
Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISender.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISender.java?rev=1421436&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISender.java (added)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISender.java Thu Dec 13 19:27:56 2012
@@ -0,0 +1,59 @@
+/*
+ *
+ * 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.engine.jni;
+
+import java.nio.ByteBuffer;
+import org.apache.qpid.proton.engine.Sender;
+import org.apache.qpid.proton.jni.Proton;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_link_t;
+
+public class JNISender extends JNILink implements Sender
+{
+ JNISender(SWIGTYPE_p_pn_link_t link_t)
+ {
+ super(link_t);
+
+ }
+
+ @Override
+ public void offer(int credits)
+ {
+ // TODO
+ }
+
+ @Override
+ public int send(byte[] bytes, int offset, int length)
+ {
+ return Proton.pn_link_send(getImpl(), ByteBuffer.wrap(bytes,offset,length));
+ }
+
+ @Override
+ public void abort()
+ {
+ // TODO
+ }
+
+ @Override
+ public void drained()
+ {
+ Proton.pn_link_drained(getImpl());
+ }
+}
Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISession.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISession.java?rev=1421436&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISession.java (added)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISession.java Thu Dec 13 19:27:56 2012
@@ -0,0 +1,158 @@
+/*
+ *
+ * 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.engine.jni;
+
+import java.util.EnumSet;
+import org.apache.qpid.proton.engine.Connection;
+import org.apache.qpid.proton.engine.EndpointError;
+import org.apache.qpid.proton.engine.EndpointState;
+import org.apache.qpid.proton.engine.Receiver;
+import org.apache.qpid.proton.engine.Sender;
+import org.apache.qpid.proton.engine.Session;
+import org.apache.qpid.proton.jni.Proton;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_session_t;
+
+public class JNISession implements Session
+{
+ private SWIGTYPE_p_pn_session_t _impl;
+ private Object _context;
+ private JNIConnection _connection;
+
+ JNISession(SWIGTYPE_p_pn_session_t session_t)
+ {
+ _impl = session_t;
+ Proton.pn_session_set_context(_impl, this);
+ _connection = JNIConnection.getConnection(Proton.pn_session_connection(_impl));
+ }
+
+ @Override
+ public Sender sender(String name)
+ {
+ return new JNISender(Proton.pn_sender(_impl, name));
+ }
+
+ @Override
+ public Receiver receiver(String name)
+ {
+ //TODO
+ return new JNIReceiver(Proton.pn_receiver(_impl, name));
+ }
+
+ @Override
+ public Session next(EnumSet<EndpointState> local, EnumSet<EndpointState> remote)
+ {
+ SWIGTYPE_p_pn_session_t session = Proton.pn_session_next(_impl, StateConverter.getStateMask(local, remote));
+ if(session != null)
+ {
+ return (Session) Proton.pn_session_get_context(session);
+ }
+ return null;
+ }
+
+ @Override
+ public Connection getConnection()
+ {
+ return _connection;
+ }
+
+ @Override
+ public EndpointState getLocalState()
+ {
+ return StateConverter.getLocalState(Proton.pn_session_state(_impl));
+ }
+
+ @Override
+ public EndpointState getRemoteState()
+ {
+ return StateConverter.getRemoteState(Proton.pn_session_state(_impl));
+ }
+
+ @Override
+ public EndpointError getLocalError()
+ {
+ //TODO
+ return null;
+ }
+
+ @Override
+ public EndpointError getRemoteError()
+ {
+ //TODO
+ return null;
+ }
+
+ @Override
+ public void free()
+ {
+ if(_impl != null)
+ {
+ Proton.pn_session_set_context(_impl, null);
+ Proton.pn_session_free(_impl);
+ _impl = null;
+ }
+
+ }
+
+ @Override
+ public void open()
+ {
+ Proton.pn_session_open(_impl);
+ }
+
+ @Override
+ public void close()
+ {
+ Proton.pn_session_close(_impl);
+ }
+
+ @Override
+ public void setContext(Object o)
+ {
+ _context = o;
+ }
+
+ @Override
+ public Object getContext()
+ {
+ return _context;
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ free();
+ super.finalize();
+ }
+
+ static JNISession getSession(SWIGTYPE_p_pn_session_t session_t)
+ {
+ if(session_t != null)
+ {
+ JNISession sessionObj = (JNISession) Proton.pn_session_get_context(session_t);
+ if(sessionObj == null)
+ {
+ sessionObj = new JNISession(session_t);
+ }
+ return sessionObj;
+ }
+ return null;
+ }
+}
Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISsl.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISsl.java?rev=1421436&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISsl.java (added)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISsl.java Thu Dec 13 19:27:56 2012
@@ -0,0 +1,177 @@
+/*
+ *
+ * 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.engine.jni;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+
+import org.apache.qpid.proton.engine.Ssl;
+import org.apache.qpid.proton.jni.Proton;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_ssl_t;
+import org.apache.qpid.proton.jni.pn_ssl_mode_t;
+import org.apache.qpid.proton.jni.pn_ssl_verify_mode_t;
+
+class JNISsl implements Ssl
+{
+ private final SWIGTYPE_p_pn_ssl_t _impl;
+ private Mode _mode;
+ private String _certificateFile;
+ private String _privateKeyFile;
+ private String _privateKeyPassword;
+ private VerifyMode _verifyMode;
+
+ JNISsl(SWIGTYPE_p_pn_ssl_t impl)
+ {
+ _impl = impl;
+ }
+
+ @Override
+ public void init(Mode mode)
+ {
+ Proton.pn_ssl_init(_impl, convertMode(mode));
+
+ }
+
+ private pn_ssl_mode_t convertMode(Mode mode)
+ {
+ _mode = mode;
+ pn_ssl_mode_t cMode = null;
+ switch(mode)
+ {
+ case CLIENT:
+ cMode = pn_ssl_mode_t.PN_SSL_MODE_CLIENT;
+ break;
+ case SERVER:
+ cMode = pn_ssl_mode_t.PN_SSL_MODE_SERVER;
+ break;
+ }
+ return cMode;
+ }
+
+ @Override
+ public Mode getMode()
+ {
+ return _mode;
+ }
+
+ @Override
+ public void setCredentials(String certificate_file, String private_key_file, String password)
+ {
+ _certificateFile = certificate_file;
+ _privateKeyFile = private_key_file;
+ _privateKeyPassword = password;
+ Proton.pn_ssl_set_credentials(_impl,certificate_file,private_key_file,password);
+
+ }
+
+ @Override
+ public String getPrivateKeyFile()
+ {
+ return _privateKeyFile;
+ }
+
+ @Override
+ public String getPrivateKeyPassword()
+ {
+ return _privateKeyPassword;
+ }
+
+ @Override
+ public String getCertificateFile()
+ {
+ return _certificateFile;
+ }
+
+ @Override
+ public void setTrustedCaDb(String certificate_db)
+ {
+ Proton.pn_ssl_set_trusted_ca_db(_impl, certificate_db);
+
+ }
+
+ @Override
+ public String getTrustedCaDb()
+ {
+ return _certificateFile;
+ }
+
+ @Override
+ public void allowUnsecuredClient(boolean allowUnsecured)
+ {
+ Proton.pn_ssl_allow_unsecured_client(_impl);
+
+ }
+
+ @Override
+ public void setPeerAuthentication(VerifyMode mode)
+ {
+ _verifyMode = mode;
+ Proton.pn_ssl_set_peer_authentication(_impl,convertVerifyMode(mode),_certificateFile);
+
+ }
+
+ private pn_ssl_verify_mode_t convertVerifyMode(VerifyMode mode)
+ {
+ pn_ssl_verify_mode_t cMode = null;
+ switch(mode)
+ {
+ case ANONYMOUS_PEER:
+ cMode = pn_ssl_verify_mode_t.PN_SSL_ANONYMOUS_PEER;
+ break;
+ case VERIFY_PEER:
+ cMode = pn_ssl_verify_mode_t.PN_SSL_VERIFY_PEER;
+ break;
+ }
+
+ return cMode;
+ }
+
+ @Override
+ public VerifyMode getPeerAuthentication()
+ {
+ return _verifyMode;
+ }
+
+ @Override
+ public String getCipherName()
+ {
+ byte[] data = new byte[1024];
+ boolean b = Proton.pn_ssl_get_cipher_name(_impl, ByteBuffer.wrap(data));
+ return b ? asString(data) : null;
+
+ }
+
+ private String asString(byte[] data)
+ {
+ int i = -1;
+ while(data[++i] != 0);
+ return new String(data,0,i,Charset.forName("US-ASCII"));
+ }
+
+ @Override
+ public String getProtocolName()
+ {
+ byte[] data = new byte[1024];
+ boolean b = Proton.pn_ssl_get_protocol_name(_impl, ByteBuffer.wrap(data));
+ return b ? asString(data) : null;
+ }
+}
Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNITransport.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNITransport.java?rev=1421436&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNITransport.java (added)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNITransport.java Thu Dec 13 19:27:56 2012
@@ -0,0 +1,191 @@
+/*
+ *
+ * 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.engine.jni;
+
+import java.nio.ByteBuffer;
+
+import org.apache.qpid.proton.engine.*;
+import org.apache.qpid.proton.jni.Proton;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_connection_t;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_error_t;
+import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_transport_t;
+
+public class JNITransport implements Transport
+{
+
+ private SWIGTYPE_p_pn_transport_t _impl;
+ private JNISasl _sasl;
+ private Object _context;
+ private JNISsl _ssl;
+
+
+ public JNITransport()
+ {
+ _impl = Proton.pn_transport();
+// Proton.pn_transport_trace(_impl,Proton.PN_TRACE_FRM);
+ }
+
+ @Override
+ public void bind(Connection connection)
+ {
+ JNIConnection jniConn = (JNIConnection)connection;
+ SWIGTYPE_p_pn_connection_t connImpl = jniConn.getImpl();
+ Proton.pn_transport_bind(_impl, connImpl);
+ }
+
+ @Override
+ public int input(byte[] bytes, int offset, int size)
+ {
+ int i = Proton.pn_transport_input(_impl, ByteBuffer.wrap(bytes, offset, size));
+ if(i == Proton.PN_ERR)
+ {
+ SWIGTYPE_p_pn_error_t err = Proton.pn_transport_error(_impl);
+ String errorText = Proton.pn_error_text(err);
+ Proton.pn_error_clear(err);
+ throw new TransportException(errorText);
+ }
+ //System.err.println("**RG** input: " + i);
+ return i;
+ }
+
+ @Override
+ public int output(byte[] bytes, int offset, int size)
+ {
+ /*int i = Proton.pn_transport_output(_impl, ByteBuffer.wrap(bytes, offset, size));
+ return i;*/
+ return Proton.pn_transport_output(_impl, ByteBuffer.wrap(bytes, offset, size));
+ }
+
+ @Override
+ public Sasl sasl()
+ {
+ if(_sasl == null)
+ {
+ _sasl = new JNISasl( Proton.pn_sasl(_impl));
+ }
+ return _sasl;
+
+ }
+
+ @Override
+ public Ssl ssl()
+ {
+ // TODO
+ if(_ssl == null)
+ {
+ _ssl = new JNISsl( Proton.pn_ssl( _impl ));
+ }
+ return _ssl;
+ }
+
+ @Override
+ public EndpointState getLocalState()
+ {
+ return null; //TODO
+ }
+
+ @Override
+ public EndpointState getRemoteState()
+ {
+ return null; //TODO
+ }
+
+ @Override
+ public EndpointError getLocalError()
+ {
+ return null; //TODO
+ }
+
+ @Override
+ public EndpointError getRemoteError()
+ {
+ return null; //TODO
+ }
+
+ @Override
+ public void free()
+ {
+ Proton.pn_transport_free(_impl);
+ }
+
+ @Override
+ public void open()
+ {
+ }
+
+ @Override
+ public void close()
+ {
+ }
+
+ @Override
+ public void setContext(Object o)
+ {
+ _context = o;
+ }
+
+ @Override
+ public Object getContext()
+ {
+ return _context;
+ }
+
+ @Override
+ protected void finalize() throws Throwable
+ {
+ free();
+ super.finalize();
+ }
+
+ public static void main(String args[])
+ {
+ System.loadLibrary("protonjni");
+ JNITransport t1 = new JNITransport();
+ JNITransport t2 = new JNITransport();
+ JNIConnection conn1 = new JNIConnection();
+ JNIConnection conn2 = new JNIConnection();
+ t1.bind(conn1);
+ t2.bind(conn2);
+
+ conn1.open();
+ conn2.open();
+
+ pump(t1, t2);
+
+
+
+ }
+
+ private static void pump(JNITransport t1, JNITransport t2)
+ {
+ int len = 0;
+ int len2 = 0;
+ byte[] buf = new byte[10240];
+ do
+ {
+ len = t1.output(buf,0,10240);
+ if(len>0) t2.input(buf,0,len);
+ len2 = t2.output(buf,0,10240);
+ if(len2>0) t1.input(buf,0,len2);
+ }
+ while(len != 0 || len2 != 0);
+ }
+}
Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/StateConverter.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/StateConverter.java?rev=1421436&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/StateConverter.java (added)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/StateConverter.java Thu Dec 13 19:27:56 2012
@@ -0,0 +1,98 @@
+/*
+ *
+ * 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.engine.jni;
+
+import java.util.EnumSet;
+import org.apache.qpid.proton.engine.EndpointState;
+import org.apache.qpid.proton.jni.Proton;
+
+class StateConverter
+{
+ public static EndpointState getLocalState(int state)
+ {
+ state = state & Proton.PN_LOCAL_MASK;
+ if(state == Proton.PN_LOCAL_UNINIT)
+ {
+ return EndpointState.UNINITIALIZED;
+ }
+ else if(state == Proton.PN_LOCAL_ACTIVE)
+ {
+ return EndpointState.ACTIVE;
+ }
+ else if(state == Proton.PN_LOCAL_CLOSED)
+ {
+ return EndpointState.CLOSED;
+ }
+ //TODO
+ return null;
+ }
+
+
+ public static EndpointState getRemoteState(int state)
+ {
+ state = state & Proton.PN_REMOTE_MASK;
+ if(state == Proton.PN_REMOTE_UNINIT)
+ {
+ return EndpointState.UNINITIALIZED;
+ }
+ else if(state == Proton.PN_REMOTE_ACTIVE)
+ {
+ return EndpointState.ACTIVE;
+ }
+ else if(state == Proton.PN_REMOTE_CLOSED)
+ {
+ return EndpointState.CLOSED;
+ }
+ //TODO
+ return null;
+ }
+
+ public static int getStateMask(EnumSet<EndpointState> local, EnumSet<EndpointState> remote)
+ {
+ int state = 0;
+ if(local.contains(EndpointState.UNINITIALIZED))
+ {
+ state &= Proton.PN_LOCAL_UNINIT;
+ }
+ if(local.contains(EndpointState.ACTIVE))
+ {
+ state &= Proton.PN_LOCAL_ACTIVE;
+ }
+ if(local.contains(EndpointState.CLOSED))
+ {
+ state &= Proton.PN_LOCAL_CLOSED;
+ }
+ if(remote.contains(EndpointState.UNINITIALIZED))
+ {
+ state &= Proton.PN_REMOTE_UNINIT;
+ }
+ if(remote.contains(EndpointState.ACTIVE))
+ {
+ state &= Proton.PN_REMOTE_ACTIVE;
+ }
+ if(remote.contains(EndpointState.CLOSED))
+ {
+ state &= Proton.PN_REMOTE_CLOSED;
+ }
+
+ return state;
+ }
+}
Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/message/jni/JNIMessage.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/message/jni/JNIMessage.java?rev=1421436&view=auto
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/message/jni/JNIMessage.java (added)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/message/jni/JNIMessage.java Thu Dec 13 19:27:56 2012
@@ -0,0 +1,788 @@
+/*
+ *
+ * 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.message.jni;
+
+import java.io.DataInput;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.util.Date;
+import java.util.UUID;
+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;
+import org.apache.qpid.proton.jni.pn_bytes_t;
+import org.apache.qpid.proton.jni.pn_format_t;
+import org.apache.qpid.proton.jni.pn_type_t;
+import org.apache.qpid.proton.message.Message;
+import org.apache.qpid.proton.message.MessageError;
+import org.apache.qpid.proton.message.MessageFormat;
+import org.apache.qpid.proton.amqp.Binary;
+import org.apache.qpid.proton.amqp.Decimal128;
+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.amqp.messaging.ApplicationProperties;
+import org.apache.qpid.proton.amqp.messaging.DeliveryAnnotations;
+import org.apache.qpid.proton.amqp.messaging.Header;
+import org.apache.qpid.proton.amqp.messaging.Footer;
+import org.apache.qpid.proton.amqp.messaging.MessageAnnotations;
+import org.apache.qpid.proton.amqp.messaging.Properties;
+import org.apache.qpid.proton.amqp.messaging.Section;
+
+public class JNIMessage implements Message
+{
+
+ public static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
+ public static final Charset ASCII_CHARSET = Charset.forName("US-ASCII");
+ private SWIGTYPE_p_pn_message_t _impl;
+
+ JNIMessage()
+ {
+ _impl = Proton.pn_message();
+ }
+
+
+ @Override
+ public boolean isDurable()
+ {
+ return Proton.pn_message_is_durable(_impl);
+ }
+
+ @Override
+ public long getDeliveryCount()
+ {
+ return Proton.pn_message_get_delivery_count(_impl);
+ }
+
+ @Override
+ public short getPriority()
+ {
+ return Proton.pn_message_get_priority(_impl);
+ }
+
+ @Override
+ public boolean isFirstAcquirer()
+ {
+ return Proton.pn_message_is_first_acquirer(_impl);
+ }
+
+ @Override
+ public long getTtl()
+ {
+ return Proton.pn_message_get_ttl(_impl);
+ }
+
+ @Override
+ public void setDurable(boolean durable)
+ {
+ Proton.pn_message_set_durable(_impl, durable);
+ }
+
+ @Override
+ public void setTtl(long ttl)
+ {
+ Proton.pn_message_set_ttl(_impl, ttl);
+ }
+
+ @Override
+ public void setDeliveryCount(long deliveryCount)
+ {
+ Proton.pn_message_set_delivery_count(_impl, deliveryCount);
+ }
+
+ @Override
+ public void setFirstAcquirer(boolean firstAcquirer)
+ {
+ Proton.pn_message_set_first_acquirer(_impl, firstAcquirer);
+ }
+
+ @Override
+ public void setPriority(short priority)
+ {
+ Proton.pn_message_set_priority(_impl, priority);
+ }
+
+ @Override
+ public Object getMessageId()
+ {
+ return convert(Proton.pn_message_get_id(_impl));
+ }
+
+ private pn_atom_t convertToAtom(Object o)
+ {
+ pn_atom_t atom = new pn_atom_t();
+
+//PN_NULL
+ if(o == null)
+ {
+ atom.setType(pn_type_t.PN_NULL);
+ }
+//PN_BOOL
+ else if(o instanceof Boolean)
+ {
+ atom.setType(pn_type_t.PN_BOOL);
+ atom.getU().setAs_bool((Boolean)o);
+ }
+//PN_UBYTE
+ else if(o instanceof UnsignedByte)
+ {
+ atom.setType(pn_type_t.PN_UBYTE);
+ atom.getU().setAs_ubyte(((UnsignedByte) o).shortValue());
+ }
+//PN_BYTE
+ else if(o instanceof Byte)
+ {
+ atom.setType(pn_type_t.PN_BYTE);
+ atom.getU().setAs_byte((Byte) o);
+ }
+//PN_USHORT
+ else if(o instanceof UnsignedShort)
+ {
+ atom.setType(pn_type_t.PN_USHORT);
+ atom.getU().setAs_ushort(((UnsignedShort) o).intValue());
+ }
+//PN_SHORT
+ else if(o instanceof Short)
+ {
+ atom.setType(pn_type_t.PN_SHORT);
+ atom.getU().setAs_short((Short) o);
+ }
+//PN_UINT
+ else if(o instanceof UnsignedInteger)
+ {
+ atom.setType(pn_type_t.PN_UINT);
+ atom.getU().setAs_uint(((UnsignedInteger) o).longValue());
+ }
+//PN_INT
+ else if(o instanceof Integer)
+ {
+ atom.setType(pn_type_t.PN_INT);
+ atom.getU().setAs_int((Integer) o);
+ }
+//PN_CHAR
+ else if(o instanceof Character)
+ {
+ atom.setType(pn_type_t.PN_CHAR);
+ atom.getU().setAs_char((Character) o);
+ }
+//PN_ULONG
+ else if(o instanceof UnsignedLong)
+ {
+ atom.setType(pn_type_t.PN_ULONG);
+ atom.getU().setAs_ulong(((UnsignedLong) o).bigIntegerValue());
+ }
+//PN_LONG
+ else if(o instanceof Long)
+ {
+ atom.setType(pn_type_t.PN_LONG);
+ atom.getU().setAs_long((Long) o);
+ }
+//PN_TIMESTAMP
+ else if(o instanceof Date)
+ {
+ atom.setType(pn_type_t.PN_TIMESTAMP);
+ atom.getU().setAs_timestamp(((Date)o).getTime());
+ }
+//PN_FLOAT
+ else if(o instanceof Float)
+ {
+ atom.setType(pn_type_t.PN_FLOAT);
+ atom.getU().setAs_float((Float) o);
+ }
+//PN_DOUBLE
+ else if(o instanceof Double)
+ {
+ atom.setType(pn_type_t.PN_DOUBLE);
+ atom.getU().setAs_double((Double) o);
+ }
+//PN_DECIMAL32
+ // TODO
+//PN_DECIMAL64
+ // TODO
+//PN_DECIMAL128
+ // TODO
+//PN_UUID
+ else if (o instanceof UUID)
+ {
+ byte[] bytes = new byte[16];
+ ByteBuffer buf = ByteBuffer.wrap(bytes);
+ UUID uuid = (UUID) o;
+ buf.putLong(uuid.getMostSignificantBits());
+ buf.putLong(uuid.getLeastSignificantBits());
+ atom.setType(pn_type_t.PN_UUID);
+ pn_bytes_t val = Proton.pn_bytes(bytes.length, bytes);
+ atom.getU().setAs_bytes(val);
+ val.delete();
+ }
+//PN_BINARY
+ else if(o instanceof byte[] || o instanceof Binary)
+ {
+ byte[] bytes = (o instanceof byte[]) ? (byte[])o : ((Binary)o).getArray();
+ atom.setType(pn_type_t.PN_BINARY);
+ pn_bytes_t val = Proton.pn_bytes(bytes.length, bytes);
+ atom.getU().setAs_bytes(val);
+ val.delete();
+ }
+//PN_STRING
+ else if(o instanceof String)
+ {
+ byte[] bytes = ((String)o).getBytes(UTF8_CHARSET);
+ atom.setType(pn_type_t.PN_STRING);
+ pn_bytes_t val = Proton.pn_bytes(bytes.length, bytes);
+ atom.getU().setAs_bytes(val);
+ val.delete();
+ }
+//PN_SYMBOL
+ else if(o instanceof Symbol)
+ {
+ byte[] bytes = ((Symbol)o).toString().getBytes(ASCII_CHARSET);
+ atom.setType(pn_type_t.PN_STRING);
+ pn_bytes_t val = Proton.pn_bytes(bytes.length, bytes);
+ atom.getU().setAs_bytes(val);
+ val.delete();
+ }
+//PN_DESCRIBED
+ // TODO
+//PN_ARRAY
+ // TODO
+//PN_LIST
+ // TODO
+//PN_MAP
+ // TODO
+
+ return atom;
+ }
+
+ private Object convert(pn_atom_t atom)
+ {
+ if(atom != null)
+ {
+ pn_type_t type = atom.getType();
+ pn_atom_t_u value = atom.getU();
+
+ if(pn_type_t.PN_BINARY.equals(type))
+ {
+ new Binary(Proton.pn_bytes_to_array(value.getAs_bytes()));
+ }
+ else if(pn_type_t.PN_STRING.equals(type))
+ {
+ return new String(Proton.pn_bytes_to_array(value.getAs_bytes()), UTF8_CHARSET);
+ }
+ else if(pn_type_t.PN_SYMBOL.equals(type))
+ {
+ return Symbol.valueOf(new String(Proton.pn_bytes_to_array(value.getAs_bytes()), ASCII_CHARSET));
+ }
+ else if(pn_type_t.PN_ARRAY.equals(type))
+ {
+ // TODO
+ }
+ else if(pn_type_t.PN_BOOL.equals(type))
+ {
+ return value.getAs_bool();
+ }
+ else if(pn_type_t.PN_BYTE.equals(type))
+ {
+ return value.getAs_byte();
+ }
+ else if(pn_type_t.PN_CHAR.equals(type))
+ {
+ return (char) value.getAs_char();
+ }
+ else if(pn_type_t.PN_DECIMAL128.equals(type))
+ {
+ // TODO
+ }
+ else if(pn_type_t.PN_DECIMAL64.equals(type))
+ {
+ // TODO
+ }
+ else if(pn_type_t.PN_DECIMAL32.equals(type))
+ {
+ // TODO
+ }
+ else if(pn_type_t.PN_DESCRIBED.equals(type))
+ {
+ // TODO
+ }
+ else if(pn_type_t.PN_DOUBLE.equals(type))
+ {
+ return value.getAs_double();
+ }
+ else if(pn_type_t.PN_FLOAT.equals(type))
+ {
+ return value.getAs_float();
+ }
+ else if(pn_type_t.PN_INT.equals(type))
+ {
+ return value.getAs_int();
+ }
+ else if(pn_type_t.PN_LIST.equals(type))
+ {
+ // TODO
+ }
+ else if(pn_type_t.PN_LONG.equals(type))
+ {
+ return value.getAs_long();
+ }
+ else if(pn_type_t.PN_MAP.equals(type))
+ {
+ // TODO
+ }
+ else if(pn_type_t.PN_NULL.equals(type))
+ {
+ return null;
+ }
+ else if(pn_type_t.PN_SHORT.equals(type))
+ {
+ return value.getAs_short();
+ }
+ else if(pn_type_t.PN_TIMESTAMP.equals(type))
+ {
+ return new Date(value.getAs_timestamp());
+ }
+ else if(pn_type_t.PN_UBYTE.equals(type))
+ {
+ return UnsignedByte.valueOf((byte) value.getAs_ubyte());
+ }
+ else if(pn_type_t.PN_UINT.equals(type))
+ {
+ return UnsignedInteger.valueOf(value.getAs_uint());
+ }
+ else if(pn_type_t.PN_ULONG.equals(type))
+ {
+ return new UnsignedLong(value.getAs_ulong().longValue());
+ }
+ else if(pn_type_t.PN_USHORT.equals(type))
+ {
+ return UnsignedShort.valueOf((short) value.getAs_ushort());
+ }
+ else if(pn_type_t.PN_UUID.equals(type))
+ {
+ byte[] b = Proton.pn_bytes_to_array(value.getAs_bytes());
+ ByteBuffer buf = ByteBuffer.wrap(b);
+ return new UUID(buf.getLong(), buf.getLong());
+ }
+
+ }
+ return null; //TODO
+ }
+
+ @Override
+ public long getGroupSequence()
+ {
+ return Proton.pn_message_get_group_sequence(_impl);
+ }
+
+ @Override
+ public String getReplyToGroupId()
+ {
+ return Proton.pn_message_get_reply_to_group_id(_impl);
+ }
+
+ @Override
+ public long getCreationTime()
+ {
+ return Proton.pn_message_get_creation_time(_impl);
+ }
+
+ @Override
+ public String getAddress()
+ {
+ return Proton.pn_message_get_address(_impl);
+ }
+
+ @Override
+ public byte[] getUserId()
+ {
+
+ return Proton.pn_bytes_to_array(Proton.pn_message_get_user_id(_impl));
+
+ }
+
+ @Override
+ public String getReplyTo()
+ {
+ return Proton.pn_message_get_reply_to(_impl);
+ }
+
+ @Override
+ public String getGroupId()
+ {
+ return Proton.pn_message_get_group_id(_impl);
+ }
+
+ @Override
+ public String getContentType()
+ {
+ return Proton.pn_message_get_content_type(_impl);
+ }
+
+ @Override
+ public long getExpiryTime()
+ {
+ return Proton.pn_message_get_expiry_time(_impl);
+ }
+
+ @Override
+ public Object getCorrelationId()
+ {
+ return convert(Proton.pn_message_get_correlation_id(_impl));
+ }
+
+ @Override
+ public String getContentEncoding()
+ {
+ return Proton.pn_message_get_content_encoding(_impl);
+ }
+
+ @Override
+ public String getSubject()
+ {
+ return Proton.pn_message_get_subject(_impl);
+ }
+
+ @Override
+ public void setGroupSequence(long groupSequence)
+ {
+ Proton.pn_message_set_group_sequence(_impl, (int) groupSequence);
+ }
+
+ @Override
+ public void setUserId(byte[] userId)
+ {
+ pn_bytes_t val = Proton.pn_bytes(userId.length, userId);
+
+ Proton.pn_message_set_user_id(_impl, val);
+
+ val.delete();
+ }
+
+ @Override
+ public void setCreationTime(long creationTime)
+ {
+ Proton.pn_message_set_creation_time(_impl, creationTime);
+ }
+
+ @Override
+ public void setSubject(String subject)
+ {
+ Proton.pn_message_set_subject(_impl, subject);
+ }
+
+ @Override
+ public void setGroupId(String groupId)
+ {
+ Proton.pn_message_set_group_id(_impl, groupId);
+ }
+
+ @Override
+ public void setAddress(String to)
+ {
+ Proton.pn_message_set_address(_impl, to);
+ }
+
+ @Override
+ public void setExpiryTime(long absoluteExpiryTime)
+ {
+ Proton.pn_message_set_expiry_time(_impl,absoluteExpiryTime);
+ }
+
+ @Override
+ public void setReplyToGroupId(String replyToGroupId)
+ {
+ Proton.pn_message_set_reply_to_group_id(_impl, replyToGroupId);
+ }
+
+ @Override
+ public void setContentEncoding(String contentEncoding)
+ {
+ Proton.pn_message_set_content_encoding(_impl, contentEncoding);
+ }
+
+ @Override
+ public void setContentType(String contentType)
+ {
+ Proton.pn_message_set_content_type(_impl, contentType);
+ }
+
+ @Override
+ public void setReplyTo(String replyTo)
+ {
+ Proton.pn_message_set_reply_to(_impl, replyTo);
+ }
+
+ @Override
+ public void setCorrelationId(Object correlationId)
+ {
+ Proton.pn_message_set_correlation_id(_impl, convertToAtom(correlationId));
+ }
+
+ @Override
+ public void setMessageId(Object messageId)
+ {
+
+ Proton.pn_message_set_id(_impl, convertToAtom(messageId));
+
+ }
+
+ @Override
+ public int decode(byte[] data, int offset, int length)
+ {
+ return Proton.pn_message_decode(_impl, ByteBuffer.wrap(data,offset,length));
+ }
+
+ @Override
+ public int encode(byte[] data, int offset, int length)
+ {
+ ByteBuffer buffer = ByteBuffer.wrap(data, offset, length);
+ int status = Proton.pn_message_encode(_impl, buffer);
+ return status == 0 ? buffer.position() : status;
+
+ }
+
+ @Override
+ public void setMessageFormat(MessageFormat format)
+ {
+ Proton.pn_message_set_format(_impl, convertMessageFormat(format));
+ }
+
+ private pn_format_t convertMessageFormat(MessageFormat format)
+ {
+ switch(format)
+ {
+ case AMQP:
+ return pn_format_t.PN_AMQP;
+ case DATA:
+ return pn_format_t.PN_DATA;
+ case JSON:
+ return pn_format_t.PN_JSON;
+ case TEXT:
+ return pn_format_t.PN_TEXT;
+ }
+ // TODO
+ return pn_format_t.PN_AMQP;
+ }
+
+ @Override
+ public MessageFormat getMessageFormat()
+ {
+ return convertMessageFormat(Proton.pn_message_get_format(_impl));
+ }
+
+ private MessageFormat convertMessageFormat(pn_format_t format)
+ {
+ if(format == pn_format_t.PN_AMQP)
+ {
+ return MessageFormat.AMQP;
+ }
+ if(format == pn_format_t.PN_DATA)
+ {
+ return MessageFormat.DATA;
+ }
+ if(format == pn_format_t.PN_JSON)
+ {
+ return MessageFormat.JSON;
+ }
+ if(format == pn_format_t.PN_TEXT)
+ {
+ return MessageFormat.TEXT;
+ }
+ // TODO
+ return MessageFormat.AMQP;
+ }
+
+ @Override
+ public void clear()
+ {
+ Proton.pn_message_clear(_impl);
+ }
+
+ @Override
+ public MessageError getError()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+
+ @Override
+ public void load(Object data)
+ {
+ byte[] bytes;
+
+ if(data instanceof byte[])
+ {
+ bytes = (byte[])data;
+ }
+ else if(data instanceof Binary)
+ {
+ bytes = ((Binary)data).getArray();
+ }
+ else if(data instanceof String)
+ {
+
+ byte[] temp = ((String)data).getBytes(UTF8_CHARSET);
+ if(getMessageFormat() == MessageFormat.DATA)
+ {
+ bytes = temp;
+ }
+ else
+ {
+ // String needs to be null terminated
+ bytes = new byte[temp.length+1];
+ System.arraycopy(temp,0,bytes,0,temp.length);
+ }
+
+ }
+ else
+ {
+ bytes = new byte[getMessageFormat() == MessageFormat.DATA ? 0 : 1];
+ }
+ int rval = Proton.pn_message_load(_impl, ByteBuffer.wrap(bytes));
+
+ }
+
+ @Override
+ public Object save()
+ {
+
+ int size;
+ int sz = 16;
+ ByteBuffer buf;
+ byte[] data;
+ do
+ {
+ sz = sz*2;
+ data = new byte[sz];
+ buf = ByteBuffer.wrap(data);
+ size = Proton.pn_message_save(_impl, buf);
+ }
+ while(size == Proton.PN_OVERFLOW);
+
+ byte[] rval = new byte[buf.position()];
+ buf.flip();
+ buf.get(rval);
+
+ return rval;
+ }
+
+ public String toAMQPFormat(Object value)
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public Object parseAMQPFormat(String value)
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public void setFooter(Footer footer)
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+
+ public Header getHeader()
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public DeliveryAnnotations getDeliveryAnnotations()
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public MessageAnnotations getMessageAnnotations()
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public Properties getProperties()
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public ApplicationProperties getApplicationProperties()
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public Section getBody()
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public Footer getFooter()
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public void setHeader(Header header)
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public void setDeliveryAnnotations(DeliveryAnnotations deliveryAnnotations)
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public void setMessageAnnotations(MessageAnnotations messageAnnotations)
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public void setProperties(Properties properties)
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public void setApplicationProperties(ApplicationProperties applicationProperties)
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public void setBody(Section body)
+ {
+ //TODO
+ throw new UnsupportedOperationException();
+ }
+
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org