Package org.apache.mina.core.future

Examples of org.apache.mina.core.future.ConnectFuture


                        }

                        SerialPort serialPort = initializePort("Apache MINA",
                                portId, portAddress);

                        ConnectFuture future = new DefaultConnectFuture();
                        SerialSessionImpl session = new SerialSessionImpl(
                                this, getListeners(), portAddress, serialPort);
                        finishSessionInitialization(session, future, sessionInitializer);
                        session.start();
                        return future;
View Full Code Here


                    throws Exception {
                System.out.println("client idle:" + status);
            }
        });

        ConnectFuture future = connector.connect(
                new InetSocketAddress("127.0.0.1", port)).awaitUninterruptibly();
        IoSession session = future.getSession();
        assertNotNull(session);

        Thread.sleep((INTERVAL + TIMEOUT + 1) * 1000);

        assertFalse("got an exception on the client", gotException.get());
View Full Code Here

    private void testConnector(IoConnector connector, boolean useLocalAddress)
            throws Exception {
        IoSession session = null;
        if (!useLocalAddress) {
            ConnectFuture future = connector.connect(new InetSocketAddress(
                    "127.0.0.1", port));
            future.awaitUninterruptibly();
            session = future.getSession();
        } else {
            int clientPort = port;
            for (int i = 0; i < 65536; i++) {
                clientPort = AvailablePortFinder
                        .getNextAvailable(clientPort + 1);
                try {
                    ConnectFuture future = connector.connect(
                            new InetSocketAddress("127.0.0.1", port),
                            new InetSocketAddress(clientPort));
                    future.awaitUninterruptibly();
                    session = future.getSession();
                    break;
                } catch (RuntimeIoException e) {
                    // Try again until we succeed to bind.
                }
            }
View Full Code Here

        bind(true);
        IoConnector connector = newConnector();
        IoSession[] sessions = new IoSession[5];
        connector.setHandler(new IoHandlerAdapter());
        for (int i = 0; i < sessions.length; i++) {
            ConnectFuture future = connector.connect(createSocketAddress(port));
            future.awaitUninterruptibly();
            sessions[i] = future.getSession();
            Assert.assertTrue(sessions[i].isConnected());
            Assert.assertTrue(sessions[i].write(IoBuffer.allocate(1)).awaitUninterruptibly().isWritten());
        }

        // Wait for the server side sessions to be created.
View Full Code Here

        if(!addresses.isEmpty()) {
            for(ResolvedAddress address : addresses) {
                LOG.info("Connecting to XMPP server {} at {}", otherServer, address.getAddress());
               
                connector = createConnector(authenticatedLatch);
                ConnectFuture connectFuture = connector.connect(address.getAddress());
                if(connectFuture.awaitUninterruptibly(connectTimeout) && connectFuture.isConnected()) {
                    // success on the TCP/IP level, now wait for the XMPP handshake
   
                    try {
                        if(authenticatedLatch.await(xmppHandshakeTimeout, TimeUnit.MILLISECONDS)) {
                            // success, break out of connect loop
                            successfullyConnected = true;
                            break;
                        } else {
                            // attempt next
                            LOG.warn("XMPP handshake with {} at () timed out", otherServer, address.getAddress());
                        }
                    } catch (InterruptedException e) {
                        throw new RemoteServerTimeoutException("Connection to " + otherServer + " was interrupted", e);
                    }
                }

                lastException = connectFuture.getException();
                LOG.warn("Failed connecting to XMPP server " + otherServer + " at " + address.getAddress(), connectFuture.getException());
                connector.dispose();
                connector = null;
            }
        } else {
            // should never happen
View Full Code Here

        if (connectorConfig != null) {
            connector.getSessionConfig().setAll(connectorConfig);
        }

        connector.setHandler(new ResponseHandler());
        ConnectFuture future = connector.connect(address);
        future.awaitUninterruptibly();
        session = future.getSession();
    }
View Full Code Here

        connector.setHandler( this );

        SocketAddress address = new InetSocketAddress( hostName, port );

        LOG.debug( "trying to establish connection to the kerberso server {} running at port {}", hostName, port );
        ConnectFuture connectFuture = connector.connect( address );

        connectFuture.awaitUninterruptibly();

        if ( !connectFuture.isConnected() )
        {
            close();
            return false;
        }

        kerberosSession = connectFuture.getSession();

        return true;
    }
View Full Code Here

                    sendEof();
                }
            }
        };
        connector.setHandler(handler);
        ConnectFuture future = connector.connect(address);
        future.addListener(new IoFutureListener<ConnectFuture>() {
            public void operationComplete(ConnectFuture future) {
                if (future.isConnected()) {
                    ioSession = future.getSession();
                    f.setOpened();
                } else if (future.getException() != null) {
                    closeImmediately0();
                    if (future.getException() instanceof ConnectException) {
                        f.setException(new OpenChannelException(
                            SshConstants.SSH_OPEN_CONNECT_FAILED,
                            future.getException().getMessage(),
                            future.getException()));
                    } else {
                        f.setException(future.getException());
                    }
                }
            }
        });
        return f;
View Full Code Here

                    sendEof();
                }
            }
        };
        connector.setHandler(handler);
        ConnectFuture future = connector.connect(address.toInetSocketAddress());
        future.addListener(new IoFutureListener<ConnectFuture>() {
            public void operationComplete(ConnectFuture future) {
                if (future.isConnected()) {
                    ioSession = future.getSession();
                    f.setOpened();
                } else if (future.getException() != null) {
                    closeImmediately0();
                    if (future.getException() instanceof ConnectException) {
                        f.setException(new OpenChannelException(
                                SshConstants.SSH_OPEN_CONNECT_FAILED,
                                future.getException().getMessage(),
                                future.getException()));
                    } else {
                        f.setException(future.getException());
                    }
                }
            }
        });
        return f;
View Full Code Here

    private void testConnector(IoConnector connector, boolean useLocalAddress)
            throws Exception {
        IoSession session = null;
        if (!useLocalAddress) {
            ConnectFuture future = connector.connect(new InetSocketAddress(
                    "127.0.0.1", port));
            future.awaitUninterruptibly();
            session = future.getSession();
        } else {
            int clientPort = port;
            for (int i = 0; i < 65536; i++) {
                clientPort = AvailablePortFinder
                        .getNextAvailable(clientPort + 1);
                try {
                    ConnectFuture future = connector.connect(
                            new InetSocketAddress("127.0.0.1", port),
                            new InetSocketAddress(clientPort));
                    future.awaitUninterruptibly();
                    session = future.getSession();
                    break;
                } catch (RuntimeIoException e) {
                    // Try again until we succeed to bind.
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.mina.core.future.ConnectFuture

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.