Search in sources :

Example 1 with SocketFactory

use of com.swiftmq.net.SocketFactory 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 SocketFactory

use of com.swiftmq.net.SocketFactory in project swiftmq-ce by iitsoftware.

the class Util method createConnection.

public static Connection createConnection(String containerId) throws Exception {
    AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
    Connection connection = null;
    SocketFactory socketFactory = null;
    if (System.getProperty("socketfactory") != null)
        socketFactory = (SocketFactory) Class.forName(System.getProperty("socketfactory")).newInstance();
    String hostname = System.getProperty("hostname", "localhost");
    int port = Integer.parseInt(System.getProperty("port", "5672"));
    boolean useSasl = Boolean.parseBoolean(System.getProperty("usesasl", "false"));
    if (useSasl) {
        boolean anonLogin = Boolean.parseBoolean(System.getProperty("anonlogin", "false"));
        if (anonLogin) {
            connection = new Connection(ctx, hostname, port, true);
        } else {
            String username = System.getProperty("username");
            TestCase.assertNotNull("missing property 'username'", username);
            String password = System.getProperty("password");
            TestCase.assertNotNull("missing property 'password'", password);
            connection = new Connection(ctx, hostname, port, username, password);
            String mechanism = System.getProperty("mechanism", "PLAIN");
            connection.setMechanism(mechanism);
        }
    } else {
        connection = new Connection(ctx, hostname, port, false);
    }
    if (containerId != null)
        connection.setContainerId(containerId);
    if (socketFactory != null)
        connection.setSocketFactory(socketFactory);
    long idleTimeout = Long.parseLong(System.getProperty("idletimeout", "60000"));
    if (idleTimeout > 0)
        connection.setIdleTimeout(idleTimeout);
    if (System.getProperty("maxframesize") != null)
        connection.setMaxFrameSize(Long.parseLong(System.getProperty("maxframesize")));
    connection.connect();
    return connection;
}
Also used : SocketFactory(com.swiftmq.net.SocketFactory) Connection(com.swiftmq.amqp.v100.client.Connection) AMQPContext(com.swiftmq.amqp.AMQPContext)

Example 3 with SocketFactory

use of com.swiftmq.net.SocketFactory 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 4 with SocketFactory

use of com.swiftmq.net.SocketFactory 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;
}
Also used : IntraVMConnection(com.swiftmq.net.client.IntraVMConnection) SocketFactory(com.swiftmq.net.SocketFactory) NetworkSwiftlet(com.swiftmq.swiftlet.net.NetworkSwiftlet) BlockingConnection(com.swiftmq.net.client.BlockingConnection) IOException(java.io.IOException) NamingException(javax.naming.NamingException) Socket(java.net.Socket)

Example 5 with SocketFactory

use of com.swiftmq.net.SocketFactory 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;
}
Also used : IntraVMConnection(com.swiftmq.net.client.IntraVMConnection) SocketFactory(com.swiftmq.net.SocketFactory) NetworkSwiftlet(com.swiftmq.swiftlet.net.NetworkSwiftlet) BlockingConnection(com.swiftmq.net.client.BlockingConnection) IOException(java.io.IOException) NamingException(javax.naming.NamingException) Socket(java.net.Socket)

Aggregations

SocketFactory (com.swiftmq.net.SocketFactory)8 IOException (java.io.IOException)5 NamingException (javax.naming.NamingException)5 Socket (java.net.Socket)4 BlockingConnection (com.swiftmq.net.client.BlockingConnection)3 IntraVMConnection (com.swiftmq.net.client.IntraVMConnection)3 NetworkSwiftlet (com.swiftmq.swiftlet.net.NetworkSwiftlet)3 SocketFactory2 (com.swiftmq.net.SocketFactory2)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 AMQPContext (com.swiftmq.amqp.AMQPContext)1 Connection (com.swiftmq.amqp.v100.client.Connection)1