Search in sources :

Example 1 with SocketFactory2

use of com.swiftmq.net.SocketFactory2 in project swiftmq-client by iitsoftware.

the class ConnectionFactoryImpl method createReconnector.

private Reconnector createReconnector() throws JMSException {
    PoolManager.setIntraVM(intraVM);
    Reconnector reconnector = null;
    if (intraVM) {
        try {
            List servers = new ArrayList();
            servers.add(new ServerEntry("intravm", 0));
            reconnector = new IntraVMReconnector(servers, null, false, 0, 0, Boolean.valueOf(System.getProperty("swiftmq.reconnect.debug", "false")).booleanValue());
        } catch (Exception e) {
            throw new JMSException("error creating intraVM connection, message: " + e.getMessage());
        }
    } else {
        try {
            List servers = new ArrayList();
            servers.add(new ServerEntry(hostname, port));
            if (reconnectEnabled && hostname2 != null)
                servers.add(new ServerEntry(hostname2, port2));
            Map parameters = new HashMap();
            parameters.put(SwiftMQConnectionFactory.TCP_NO_DELAY, Boolean.valueOf(System.getProperty("swiftmq.tcp.no.delay", "true")));
            parameters.put(SwiftMQConnectionFactory.INPUT_BUFFER_SIZE, new Integer(inputBufferSize));
            parameters.put(SwiftMQConnectionFactory.INPUT_EXTEND_SIZE, new Integer(inputExtendSize));
            parameters.put(SwiftMQConnectionFactory.OUTPUT_BUFFER_SIZE, new Integer(outputBufferSize));
            parameters.put(SwiftMQConnectionFactory.OUTPUT_EXTEND_SIZE, new Integer(outputExtendSize));
            SocketFactory sf = (SocketFactory) Class.forName(socketFactoryClass).newInstance();
            if (sf instanceof SocketFactory2)
                ((SocketFactory2) sf).setReceiveBufferSize(inputBufferSize);
            parameters.put(SwiftMQConnectionFactory.SOCKETFACTORY, sf);
            reconnector = new BlockingReconnector(servers, parameters, reconnectEnabled, maxRetries, retryDelay, Boolean.valueOf(System.getProperty("swiftmq.reconnect.debug", "false")).booleanValue());
        } catch (Exception e) {
            throw new JMSException("error creating socket connection to " + hostname + ":" + port + ", message: " + e.getMessage());
        }
    }
    return reconnector;
}
Also used : HashMap(java.util.HashMap) SocketFactory(com.swiftmq.net.SocketFactory) ArrayList(java.util.ArrayList) SocketFactory2(com.swiftmq.net.SocketFactory2) BlockingReconnector(com.swiftmq.net.client.BlockingReconnector) IntraVMReconnector(com.swiftmq.net.client.IntraVMReconnector) Reconnector(com.swiftmq.net.client.Reconnector) ServerEntry(com.swiftmq.net.client.ServerEntry) IOException(java.io.IOException) NamingException(javax.naming.NamingException) IntraVMReconnector(com.swiftmq.net.client.IntraVMReconnector) BlockingReconnector(com.swiftmq.net.client.BlockingReconnector) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with SocketFactory2

use of com.swiftmq.net.SocketFactory2 in project swiftmq-client by iitsoftware.

the class ConnectionFactoryImpl method createReconnector.

private Reconnector createReconnector() throws JMSException {
    PoolManager.setIntraVM(intraVM);
    Reconnector reconnector = null;
    if (intraVM) {
        try {
            List servers = new ArrayList();
            servers.add(new ServerEntry("intravm", 0));
            reconnector = new IntraVMReconnector(servers, null, false, 0, 0, Boolean.valueOf(System.getProperty("swiftmq.reconnect.debug", "false")).booleanValue());
        } catch (Exception e) {
            throw new JMSException("error creating intraVM connection, message: " + e.getMessage());
        }
    } else {
        try {
            List servers = new ArrayList();
            servers.add(new ServerEntry(hostname, port));
            if (reconnectEnabled && hostname2 != null)
                servers.add(new ServerEntry(hostname2, port2));
            Map parameters = new HashMap();
            parameters.put(SwiftMQConnectionFactory.TCP_NO_DELAY, Boolean.valueOf(System.getProperty("swiftmq.tcp.no.delay", "true")));
            parameters.put(SwiftMQConnectionFactory.INPUT_BUFFER_SIZE, new Integer(inputBufferSize));
            parameters.put(SwiftMQConnectionFactory.INPUT_EXTEND_SIZE, new Integer(inputExtendSize));
            parameters.put(SwiftMQConnectionFactory.OUTPUT_BUFFER_SIZE, new Integer(outputBufferSize));
            parameters.put(SwiftMQConnectionFactory.OUTPUT_EXTEND_SIZE, new Integer(outputExtendSize));
            SocketFactory sf = (SocketFactory) Class.forName(socketFactoryClass).newInstance();
            if (sf instanceof SocketFactory2)
                ((SocketFactory2) sf).setReceiveBufferSize(inputBufferSize);
            parameters.put(SwiftMQConnectionFactory.SOCKETFACTORY, sf);
            reconnector = new BlockingReconnector(servers, parameters, reconnectEnabled, maxRetries, retryDelay, Boolean.valueOf(System.getProperty("swiftmq.reconnect.debug", "false")).booleanValue());
        } catch (Exception e) {
            throw new JMSException("error creating socket connection to " + hostname + ":" + port + ", message: " + e.getMessage());
        }
    }
    return reconnector;
}
Also used : HashMap(java.util.HashMap) SocketFactory(com.swiftmq.net.SocketFactory) ArrayList(java.util.ArrayList) SocketFactory2(com.swiftmq.net.SocketFactory2) BlockingReconnector(com.swiftmq.net.client.BlockingReconnector) IntraVMReconnector(com.swiftmq.net.client.IntraVMReconnector) Reconnector(com.swiftmq.net.client.Reconnector) ServerEntry(com.swiftmq.net.client.ServerEntry) IOException(java.io.IOException) NamingException(javax.naming.NamingException) IntraVMReconnector(com.swiftmq.net.client.IntraVMReconnector) BlockingReconnector(com.swiftmq.net.client.BlockingReconnector) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with SocketFactory2

use of com.swiftmq.net.SocketFactory2 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;
}
Also used : ProtocolInputHandler(com.swiftmq.net.protocol.ProtocolInputHandler) ProtocolOutputHandler(com.swiftmq.net.protocol.ProtocolOutputHandler) POProtocolRequest(com.swiftmq.amqp.v100.client.po.POProtocolRequest) SocketFactory2(com.swiftmq.net.SocketFactory2) DataStreamOutputStream(com.swiftmq.tools.util.DataStreamOutputStream) RawOutputHandler(com.swiftmq.net.protocol.raw.RawOutputHandler) IOException(java.io.IOException) Semaphore(com.swiftmq.tools.concurrent.Semaphore) POAuthenticate(com.swiftmq.amqp.v100.client.po.POAuthenticate) POOpen(com.swiftmq.amqp.v100.client.po.POOpen) BlockingConnection(com.swiftmq.net.client.BlockingConnection) POObject(com.swiftmq.tools.pipeline.POObject)

Aggregations

SocketFactory2 (com.swiftmq.net.SocketFactory2)3 IOException (java.io.IOException)3 SocketFactory (com.swiftmq.net.SocketFactory)2 BlockingReconnector (com.swiftmq.net.client.BlockingReconnector)2 IntraVMReconnector (com.swiftmq.net.client.IntraVMReconnector)2 Reconnector (com.swiftmq.net.client.Reconnector)2 ServerEntry (com.swiftmq.net.client.ServerEntry)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 NamingException (javax.naming.NamingException)2 POAuthenticate (com.swiftmq.amqp.v100.client.po.POAuthenticate)1 POOpen (com.swiftmq.amqp.v100.client.po.POOpen)1 POProtocolRequest (com.swiftmq.amqp.v100.client.po.POProtocolRequest)1 BlockingConnection (com.swiftmq.net.client.BlockingConnection)1 ProtocolInputHandler (com.swiftmq.net.protocol.ProtocolInputHandler)1 ProtocolOutputHandler (com.swiftmq.net.protocol.ProtocolOutputHandler)1 RawOutputHandler (com.swiftmq.net.protocol.raw.RawOutputHandler)1 Semaphore (com.swiftmq.tools.concurrent.Semaphore)1