Search in sources :

Example 11 with ConnectFuture

use of org.apache.mina.core.future.ConnectFuture in project opennms by OpenNMS.

the class ConnectionFactoryNewConnectorImpl method connect.

/**
 * <p>Connect to a remote socket. If org.opennms.netmgt.provision.maxConcurrentConnections
 * is set, this may block until a connection slot is available.</p>
 *
 * <p>You must dispose both the {@link ConnectionFactoryNewConnectorImpl} and {@link ConnectFuture} when done
 * by calling {@link #dispose(ConnectionFactoryNewConnectorImpl, ConnectFuture)}.</p>
 *
 * @param remoteAddress
 * 		Destination address
 * @param init
 * 		Initialiser for the IoSession
 * @return
 * 		ConnectFuture from a Mina connect call
 */
@Override
public ConnectFuture connect(SocketAddress remoteAddress, IoSessionInitializer<? extends ConnectFuture> init, IoHandler handler) {
    SocketConnector connector = getSocketConnector(getTimeout(), handler);
    InetSocketAddress localAddress = null;
    synchronized (m_portMutex) {
        if (m_port.get() == null) {
            // Fetch a new ephemeral port
            localAddress = new InetSocketAddress(0);
            m_port.set(localAddress.getPort());
        } else {
            localAddress = new InetSocketAddress(m_port.get());
        }
    }
    final ConnectFuture cf = connector.connect(remoteAddress, localAddress, init);
    cf.addListener(portSwitcher(connector, remoteAddress, init, handler));
    cf.addListener(connectorDisposer(connector));
    return cf;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ConnectFuture(org.apache.mina.core.future.ConnectFuture) NioSocketConnector(org.apache.mina.transport.socket.nio.NioSocketConnector) SocketConnector(org.apache.mina.transport.socket.SocketConnector)

Example 12 with ConnectFuture

use of org.apache.mina.core.future.ConnectFuture in project cxf by apache.

the class UDPConduit method close.

public void close(Message msg) throws IOException {
    super.close(msg);
    if (msg.getExchange().isOneWay() || msg.getExchange().getInMessage() == msg || msg.getExchange().getInFaultMessage() == msg) {
        String s = (String) msg.getExchange().get(HOST_PORT);
        ConnectFuture c = msg.getExchange().get(ConnectFuture.class);
        if (s != null && c != null) {
            c.getSession().removeAttribute(CXF_MESSAGE_ATTR);
            Queue<ConnectFuture> q = connections.get(s);
            if (q == null) {
                connections.putIfAbsent(s, new ArrayBlockingQueue<ConnectFuture>(10));
                q = connections.get(s);
            }
            if (!q.offer(c)) {
                c.getSession().closeOnFlush();
            }
        }
    }
}
Also used : ConnectFuture(org.apache.mina.core.future.ConnectFuture)

Example 13 with ConnectFuture

use of org.apache.mina.core.future.ConnectFuture in project pancm_project by xuwujing.

the class ClientTestServer method getIOSession.

/**
 * Get io session io session.
 *
 * @param connector the connector
 * @return the io session
 */
public IoSession getIOSession(IoConnector connector) {
    ConnectFuture future = connector.connect(new InetSocketAddress("192.168.2.55", 1255));
    // 等待是否连接成功,相当于是转异步执行为同步执行。
    future.awaitUninterruptibly();
    // 连接成功后获取会话对象。 如果没有上面的等待, 由于connect()方法是异步的, session可能会无法获取。
    IoSession session = null;
    try {
        session = future.getSession();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return session;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ConnectFuture(org.apache.mina.core.future.ConnectFuture) IoSession(org.apache.mina.core.session.IoSession)

Example 14 with ConnectFuture

use of org.apache.mina.core.future.ConnectFuture in project streamsx.topology by IBMStreams.

the class TCPTestClient method connect.

public synchronized void connect() throws InterruptedException {
    for (int i = 0; i < 5; i++) {
        try {
            TRACE.info("Attempting to connect to test collector: " + addr);
            ConnectFuture future = connector.connect(addr);
            future.awaitUninterruptibly();
            session = future.getSession();
            TRACE.info("Connected to test collector: " + addr);
            return;
        } catch (RuntimeIoException e) {
            e.printStackTrace(System.err);
            if (i < 4) {
                TRACE.warning("Failed to connect to test collector - retrying: " + addr);
                Thread.sleep(1000);
            } else {
                TRACE.severe("Failed to connect to test collector: " + addr);
                throw e;
            }
        }
    }
}
Also used : ConnectFuture(org.apache.mina.core.future.ConnectFuture) RuntimeIoException(org.apache.mina.core.RuntimeIoException)

Aggregations

ConnectFuture (org.apache.mina.core.future.ConnectFuture)14 InetSocketAddress (java.net.InetSocketAddress)8 IoSession (org.apache.mina.core.session.IoSession)3 IOException (java.io.IOException)2 RuntimeIoException (org.apache.mina.core.RuntimeIoException)2 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)2 NioSocketConnector (org.apache.mina.transport.socket.nio.NioSocketConnector)2 ConnectException (java.net.ConnectException)1 SocketAddress (java.net.SocketAddress)1 URI (java.net.URI)1 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SSLContext (javax.net.ssl.SSLContext)1 BinaryAttributeDetector (org.apache.directory.api.ldap.codec.api.BinaryAttributeDetector)1 DefaultConfigurableBinaryAttributeDetector (org.apache.directory.api.ldap.codec.api.DefaultConfigurableBinaryAttributeDetector)1 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)1 MessageDecorator (org.apache.directory.api.ldap.codec.api.MessageDecorator)1 SchemaBinaryAttributeDetector (org.apache.directory.api.ldap.codec.api.SchemaBinaryAttributeDetector)1 LdapOtherException (org.apache.directory.api.ldap.model.exception.LdapOtherException)1