summaryrefslogtreecommitdiff
path: root/java/client/example
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2008-02-12 17:36:07 +0000
committerMartin Ritchie <ritchiem@apache.org>2008-02-12 17:36:07 +0000
commit031b02ced99d04d103c02575913ea238e48221ac (patch)
tree2d9d8547c55ca06b45983a479026e0489860ee0e /java/client/example
parent1df04df23ddda53cda350ddaeec692cb2f7cbed8 (diff)
downloadqpid-python-031b02ced99d04d103c02575913ea238e48221ac.tar.gz
QPID-784 : Added ability to provide existing Socket to Qpid Client Libraries to use as for connection.
Modified based on review by Robert Godfrey due to Thread safety around SocketTransportConnection.java and TransportConnection.java. Now use a safe Map to store all registered sockets in the TransportConnection.java these are then removed as used or on request. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2.1@620876 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/example')
-rw-r--r--java/client/example/src/main/java/org/apache/qpid/example/transport/ExistingSocketConnectorDemo.java16
1 files changed, 13 insertions, 3 deletions
diff --git a/java/client/example/src/main/java/org/apache/qpid/example/transport/ExistingSocketConnectorDemo.java b/java/client/example/src/main/java/org/apache/qpid/example/transport/ExistingSocketConnectorDemo.java
index 0979c9c6b8..d7eb138523 100644
--- a/java/client/example/src/main/java/org/apache/qpid/example/transport/ExistingSocketConnectorDemo.java
+++ b/java/client/example/src/main/java/org/apache/qpid/example/transport/ExistingSocketConnectorDemo.java
@@ -23,6 +23,7 @@ package org.apache.qpid.example.transport;
import org.apache.qpid.AMQException;
import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.jms.ConnectionListener;
import org.apache.qpid.url.URLSyntaxException;
@@ -36,6 +37,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.SocketChannel;
+import java.util.UUID;
/**
* This is a simple application that demonstrates how you can use the Qpid AMQP interfaces to use existing sockets as
@@ -66,9 +68,14 @@ public class ExistingSocketConnectorDemo implements ConnectionListener
MessageProducer _producer;
Session _session;
+ String Socket1_ID = UUID.randomUUID().toString();
+ String Socket2_ID = UUID.randomUUID().toString();
+
+
/** Here we can see the broker we are connecting to is set to be 'socket:///' signifying we will provide the socket. */
- public static final String CONNECTION = "amqp://guest:guest@id/test?brokerlist='socket:///'";
+ public final String CONNECTION = "amqp://guest:guest@id/test?brokerlist='socket://" + Socket1_ID + ";socket://" + Socket2_ID + "'";
+
public ExistingSocketConnectorDemo() throws IOException, URLSyntaxException, AMQException, JMSException
{
@@ -76,7 +83,10 @@ public class ExistingSocketConnectorDemo implements ConnectionListener
Socket socket = SocketChannel.open().socket();
socket.connect(new InetSocketAddress("localhost", 5672));
- _connection = new AMQConnection(CONNECTION, socket);
+ TransportConnection.registerOpenSocket(Socket1_ID, socket);
+
+
+ _connection = new AMQConnection(CONNECTION);
_session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -130,7 +140,7 @@ public class ExistingSocketConnectorDemo implements ConnectionListener
socket.connect(new InetSocketAddress("localhost", 5673));
// This is the new method to pass in an open socket for the connection to use.
- ((AMQConnection) _connection).setOpenSocket(socket);
+ TransportConnection.registerOpenSocket(Socket2_ID, socket);
}
catch (IOException e)
{