Package org.apache.mina.core.future

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


                    throws Exception {
                session.close(true);
            }
        });

        ConnectFuture future = connector.connect(new VmPipeAddress(1));

        future.awaitUninterruptibly();
        future.getSession().getCloseFuture().awaitUninterruptibly();
        acceptor.dispose();
        connector.dispose();

        // sessionClosed() might not be invoked yet
        // even if the connection is closed.
View Full Code Here


        vmPipeAcceptor.bind(vmPipeAddress);

        final VmPipeConnector vmPipeConnector = new VmPipeConnector();
        vmPipeConnector.getFilterChain().addLast("executor", new ExecutorFilter());
        vmPipeConnector.setHandler(new IoHandlerAdapter());
        ConnectFuture connectFuture = vmPipeConnector.connect(vmPipeAddress);
        connectFuture.awaitUninterruptibly();
        connectFuture.getSession().write(IoBuffer.wrap(new byte[1])).awaitUninterruptibly();
        connectFuture.getSession().close(false).awaitUninterruptibly();

        semaphore.tryAcquire(1, TimeUnit.SECONDS);
        vmPipeAcceptor.unbind(vmPipeAddress);
        assertEquals(1, connectFuture.getSession().getWrittenBytes());
        assertEquals("ABCD", stringBuffer.toString());
    }
View Full Code Here

                                fail("unexpected message received " + message);
                            }
                        }
                    });

                    ConnectFuture c2Future = c2.connect(address);

                    c2Future.await();

                    latch.await();

                    c2Future.getSession().write("please don't deadlock via c2");
                } else {
                    fail("unexpeced message received " + message);
                }
            }
        });

        ConnectFuture future = connector.connect(address);

        future.await();

        c1.set(future.getSession());
        c1.get().write("start");

        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();

        while (!messageCount.await(100, TimeUnit.MILLISECONDS)) {
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();
            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);
            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();
            assertTrue(wf.isWritten());
           
            // Make sure the connection is closed before recycler closes it.
            while (acceptorHandler.session == null) {
                Thread.yield();
            }
            acceptorHandler.session.close(true);
            assertTrue(
                    acceptorHandler.session.getCloseFuture().awaitUninterruptibly(3000));

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

        H handle = null;
        boolean success = false;
        try {
            handle = newHandle(localAddress);
            if (connect(handle, remoteAddress)) {
                ConnectFuture future = new DefaultConnectFuture();
                T session = newSession(processor, handle);
                initSession(session, future, sessionInitializer);
                // Forward the remaining process to the IoProcessor.
                session.getProcessor().add(session);
                success = true;
View Full Code Here

        }
      }
    };

    for (int i = 0; i < MSG_COUNT; i++) {
      ConnectFuture future = connector.connect(socketAddress);
      future.addListener(listener);
    }

    synchronized (LOCK) {
      LOCK.wait(50000);
    }
View Full Code Here

    connector.setHandler(new ClientHandler());
    connector.getFilterChain().addLast( "logger", new LoggingFilter() );
    connector.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory( Charset.forName( "UTF-8" ))));

    // Start communication.
    ConnectFuture cf = connector.connect(new InetSocketAddress("localhost", 9123));
    cf.awaitUninterruptibly();

    IoSession session = cf.getSession();

    // send a message
    session.write("Hello World!\r");

    // wait until response is received
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

                        }

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

                        ConnectFuture future = new DefaultConnectFuture();
                        SerialSessionImpl session = new SerialSessionImpl(
                                this, getListeners(), portAddress, serialPort);
                        initSession(session, future, sessionInitializer);
                        session.start();
                        return future;
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.