use of com.swiftmq.net.client.BlockingConnection in project swiftmq-client by iitsoftware.
the class ConnectionFactoryImpl method createServerConnection.
private com.swiftmq.net.client.Connection createServerConnection() throws JMSException {
PoolManager.setIntraVM(intraVM);
com.swiftmq.net.client.Connection conn = null;
if (intraVM) {
try {
conn = new IntraVMConnection();
NetworkSwiftlet networkSwiftlet = (NetworkSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$net");
networkSwiftlet.connectIntraVMListener("sys$jms", (IntraVMConnection) conn);
} catch (Exception e) {
throw new JMSException("error creating intraVM connection, message: " + e.getMessage());
}
} else {
try {
if (socketFactory == null)
socketFactory = (SocketFactory) Class.forName(socketFactoryClass).newInstance();
Socket socket = socketFactory.createSocket(hostname, port);
conn = new BlockingConnection(socket, inputBufferSize, inputExtendSize, outputBufferSize, outputExtendSize);
} catch (Exception e) {
throw new JMSException("error creating socket connection to " + hostname + ":" + port + ", message: " + e.getMessage());
}
}
return conn;
}
use of com.swiftmq.net.client.BlockingConnection in project swiftmq-client by iitsoftware.
the class ConnectionFactoryImpl method createServerConnection.
private com.swiftmq.net.client.Connection createServerConnection() throws JMSException {
PoolManager.setIntraVM(intraVM);
com.swiftmq.net.client.Connection conn = null;
if (intraVM) {
try {
conn = new IntraVMConnection();
NetworkSwiftlet networkSwiftlet = (NetworkSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$net");
networkSwiftlet.connectIntraVMListener("sys$jms", (IntraVMConnection) conn);
} catch (Exception e) {
throw new JMSException("error creating intraVM connection, message: " + e.getMessage());
}
} else {
try {
if (socketFactory == null)
socketFactory = (SocketFactory) Class.forName(socketFactoryClass).newInstance();
Socket socket = socketFactory.createSocket(hostname, port);
conn = new BlockingConnection(socket, inputBufferSize, inputExtendSize, outputBufferSize, outputExtendSize);
} catch (Exception e) {
throw new JMSException("error creating socket connection to " + hostname + ":" + port + ", message: " + e.getMessage());
}
}
return conn;
}
use of com.swiftmq.net.client.BlockingConnection in project swiftmq-client by iitsoftware.
the class Connection method connect.
/**
* Performs the actual connect to the remote host, negotiates the protocol and authenticates the user
*
* @throws IOException if an IOExcption occurs
* @throws UnsupportedProtocolVersionException if the AMQP/SASL protocol version is not supported by the remote host
* @throws AuthenticationException if the user cannot be authenticated
* @throws ConnectionClosedException if the connection was closed
*/
public void connect() throws IOException, UnsupportedProtocolVersionException, AuthenticationException, ConnectionClosedException {
verifyState();
connectionDispatcher = new ConnectionDispatcher(ctx, hostname);
if (socketFactory instanceof SocketFactory2)
((SocketFactory2) socketFactory).setReceiveBufferSize(inputBufferSize);
networkConnection = new BlockingConnection(socketFactory.createSocket(hostname, port), connectionDispatcher, this) {
protected ProtocolOutputHandler createOutputHandler(int outputBufferSize, int outputExtendSize) {
return new RawOutputHandler(outputBufferSize, outputExtendSize) {
public void flush() throws IOException {
super.flush();
invokeOutputListener();
}
};
}
protected ProtocolInputHandler createInputHandler() {
return connectionDispatcher.getProtocolHandler();
}
};
connectionDispatcher.setMyConnection(this);
networkConnection.start();
dos = new DataStreamOutputStream(networkConnection.getOutputStream());
connectionPool = ctx.getConnectionPool();
connectionTask = new ConnectionTask();
connectionQueue = new ConnectionQueue();
connectionDispatcher.setOutboundHandler(connectionQueue);
connectionQueue.startQueue();
// SASL
if (doAuth) {
connectionDispatcher.setSaslActive(true);
Semaphore sem = new Semaphore();
POObject po = new POProtocolRequest(sem, Util.SASL_INIT);
connectionDispatcher.dispatch(po);
sem.waitHere();
sem.reset();
if (!po.isSuccess()) {
cancel();
throw new UnsupportedProtocolVersionException(po.getException());
}
po = new POAuthenticate(sem, mechanism, userName, password);
connectionDispatcher.dispatch(po);
sem.waitHere();
sem.reset();
if (!po.isSuccess()) {
cancel();
throw new AuthenticationException(po.getException());
}
}
// AMQP
Semaphore sem = new Semaphore();
POObject po = new POProtocolRequest(sem, Util.AMQP_INIT);
connectionDispatcher.dispatch(po);
sem.waitHere();
sem.reset();
if (!po.isSuccess()) {
cancel();
throw new UnsupportedProtocolVersionException(po.getException());
}
// Open
po = new POOpen(sem, containerId, maxFrameSize, 255, idleTimeout);
connectionDispatcher.dispatch(po);
sem.waitHere();
sem.reset();
if (!po.isSuccess()) {
cancel();
throw new IOException(po.getException());
}
connected = true;
}
use of com.swiftmq.net.client.BlockingConnection in project swiftmq-client by iitsoftware.
the class ConnectionFactoryImpl method createServerConnection.
private com.swiftmq.net.client.Connection createServerConnection() throws JMSException {
PoolManager.setIntraVM(intraVM);
com.swiftmq.net.client.Connection conn = null;
if (intraVM) {
try {
conn = new IntraVMConnection();
NetworkSwiftlet networkSwiftlet = (NetworkSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$net");
networkSwiftlet.connectIntraVMListener("sys$jms", (IntraVMConnection) conn);
} catch (Exception e) {
throw new JMSException("error creating intraVM connection, message: " + e.getMessage());
}
} else {
try {
if (socketFactory == null)
socketFactory = (SocketFactory) Class.forName(socketFactoryClass).newInstance();
Socket socket = socketFactory.createSocket(hostname, port, Boolean.valueOf(System.getProperty("swiftmq.tcp.no.delay", "true")).booleanValue());
conn = new BlockingConnection(socket, inputBufferSize, inputExtendSize, outputBufferSize, outputExtendSize);
} catch (Exception e) {
throw new JMSException("error creating socket connection to " + hostname + ":" + port + ", message: " + e.getMessage());
}
}
return conn;
}
Aggregations