Package org.apache.mina.core.future

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


            @Override
            public void sessionClosed(IoSession session) throws Exception {
                latch.countDown();
            }
        });
        ConnectFuture future = connector.connect(new InetSocketAddress("localhost", port));
        future.awaitUninterruptibly();
       
        IoSession session = future.getSession();
        session.write(file);
       
        latch.await();
       
        if (exception[0] != null) {
View Full Code Here


            assertEventExists(events, "DummyIoFilter.sessionOpened", remoteAddressClient, "user-" + i);
        }
    }

    private SocketAddress connectAndWrite(NioSocketConnector connector, int clientNr) {
        ConnectFuture connectFuture = connector.connect(new InetSocketAddress("localhost", port));
        connectFuture.awaitUninterruptibly(TIMEOUT);
        IoBuffer message = IoBuffer.allocate(4).putInt(clientNr).flip();
        IoSession session = connectFuture.getSession();
        session.write(message).awaitUninterruptibly(TIMEOUT);
        return session.getLocalAddress();
    }
View Full Code Here

                @Override
                public void exceptionCaught(IoSession session, Throwable cause) {
                    buf.append("X");
                }
            });
            ConnectFuture future = connector.connect(new InetSocketAddress(
                    "localhost", port));
            future.awaitUninterruptibly();
            buf.append("3");
            future.getSession().close(true);
            // sessionCreated() will fire before the connect future completes
            // but sessionOpened() may not
            Assert.assertTrue(Pattern.matches("12?32?", buf.toString()));
        } finally {
            acceptor.dispose();
View Full Code Here

                buf.append("Z");
            }
        });
       
        try {
            ConnectFuture future = connector.connect(new InetSocketAddress(
                    "localhost", port));
            future.awaitUninterruptibly();
            buf.append("1");
            try {
                future.getSession().close(true);
                fail();
            } catch (RuntimeIoException e) {
                // Signifies a successful test execution
                assertTrue(true);
            }
View Full Code Here

                   assertions[sessionCreatedInvokedBeforeCallback] = !assertions[callbackInvoked];
                   latch.countDown();
            }
        });
       
        ConnectFuture future = connector.connect(new InetSocketAddress("127.0.0.1", port), new IoSessionInitializer<ConnectFuture>() {
            public void initializeSession(IoSession session, ConnectFuture future) {
                assertions[callbackInvoked] = true;
                callbackFuture[0] = future;
                latch.countDown();
            }
View Full Code Here

        acceptor.setSessionRecycler(recycler);
        acceptor.bind(new InetSocketAddress(port));

        try {
            connector.setHandler(connectorHandler);
            ConnectFuture future = connector.connect(new InetSocketAddress(
                    "localhost", port));
            future.awaitUninterruptibly();

            // Write whatever to trigger the acceptor.
            future.getSession().write(IoBuffer.allocate(1))
                    .awaitUninterruptibly();

            // Close the client-side connection.
            // This doesn't mean that the acceptor-side connection is also closed.
            // The life cycle of the acceptor-side connection is managed by the recycler.
            future.getSession().close(true);
            future.getSession().getCloseFuture().awaitUninterruptibly();
            Assert.assertTrue(future.getSession().getCloseFuture().isClosed());

            // Wait until the acceptor-side connection is closed.
            while (acceptorHandler.session == null) {
                Thread.yield();
            }
View Full Code Here

        acceptor.setSessionRecycler(recycler);
        acceptor.bind(new InetSocketAddress(port));

        try {
            connector.setHandler(connectorHandler);
            ConnectFuture future = connector.connect(new InetSocketAddress(
                    "localhost", port));
            future.awaitUninterruptibly();
           
            // Write whatever to trigger the acceptor.
            future.getSession().write(IoBuffer.allocate(1)).awaitUninterruptibly();

            // Make sure the connection is closed before recycler closes it.
            while (acceptorHandler.session == null) {
                Thread.yield();
            }
            acceptorHandler.session.close(true);
            Assert.assertTrue(
                    acceptorHandler.session.getCloseFuture().awaitUninterruptibly(3000));
           
            IoSession oldSession = acceptorHandler.session;

            // Wait until all events are processed and clear the state.
            long startTime = System.currentTimeMillis();
            while (acceptorHandler.result.length() < 8) {
                Thread.yield();
                if (System.currentTimeMillis() - startTime > 5000) {
                    throw new Exception();
                }
            }
            acceptorHandler.result.setLength(0);
            acceptorHandler.session = null;
           
            // Write whatever to trigger the acceptor again.
            WriteFuture wf = future.getSession().write(
                    IoBuffer.allocate(1)).awaitUninterruptibly();
            Assert.assertTrue(wf.isWritten());
           
            // Make sure the connection is closed before recycler closes it.
            while (acceptorHandler.session == null) {
                Thread.yield();
            }
            acceptorHandler.session.close(true);
            Assert.assertTrue(
                    acceptorHandler.session.getCloseFuture().awaitUninterruptibly(3000));

            future.getSession().close(true).awaitUninterruptibly();
           
            Assert.assertNotSame(oldSession, acceptorHandler.session);
        } finally {
            acceptor.unbind();
        }
View Full Code Here

    }

    private void callNextExceptionCaught(Entry entry, IoSession session,
            Throwable cause) {
        // Notify the related future.
        ConnectFuture future = (ConnectFuture) session
                .removeAttribute(SESSION_CREATED_FUTURE);
        if (future == null) {
            try {
                IoFilter filter = entry.getFilter();
                NextFilter nextFilter = entry.getNextFilter();
                filter.exceptionCaught(nextFilter,
                        session, cause);
            } catch (Throwable e) {
                LOGGER
                        .warn(
                                "Unexpected exception from exceptionCaught handler.",
                                e);
            }
        } else {
            // Please note that this place is not the only place that
            // calls ConnectFuture.setException().
            session.close(true);
            future.setException(cause);
        }
    }
View Full Code Here

                throws Exception {
            try {
                session.getHandler().sessionCreated(session);
            } finally {
                // Notify the related future.
                ConnectFuture future = (ConnectFuture) session
                        .removeAttribute(SESSION_CREATED_FUTURE);
                if (future != null) {
                    future.setSession(session);
                }
            }
        }
View Full Code Here

        acceptor.setHandler(mockHandler);
        acceptor.bind(new InetSocketAddress(port));

        try {
            connector.setHandler(new IoHandlerAdapter());
            ConnectFuture future = connector.connect(
                    new InetSocketAddress("127.0.0.1", port));
            future.awaitUninterruptibly();

            WriteFuture writeFuture = future.getSession().write(
                    IoBuffer.allocate(16).putInt(0).flip());
            writeFuture.awaitUninterruptibly();
            Assert.assertTrue(writeFuture.isWritten());

            future.getSession().close(true);

            for (int i = 0; i < 30; i++) {
                if (result.length() == 2) {
                    break;
                }
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.