Package org.apache.mina.core.future

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


        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


                        }

                        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

        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

        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();
            assertTrue(sessions[i].isConnected());
            assertTrue(sessions[i].write(IoBuffer.allocate(1)).awaitUninterruptibly().isWritten());
        }

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

        bind(true);
        IoConnector connector = newConnector();
        IoSession session = null;
        connector.setHandler(new IoHandlerAdapter());
       
        ConnectFuture future = connector.connect(createSocketAddress(port));
        future.awaitUninterruptibly();
        session = future.getSession();
        assertTrue(session.isConnected());
        assertTrue(session.write(IoBuffer.allocate(1)).awaitUninterruptibly().isWritten());

        // Wait for the server side session to be created.
        Thread.sleep(500);

        Collection<IoSession> managedSession = acceptor.getManagedSessions().values();
        assertEquals(1, managedSession.size());

        acceptor.unbind();

        // Wait for the client side sessions to close.
        Thread.sleep(500);

        assertEquals(0, managedSession.size());
        for (IoSession element : managedSession) {
            assertFalse(element.isConnected());
        }
       
        // Rebind
        bind(true);
       
        // Check again the connection
        future = connector.connect(createSocketAddress(port));
        future.awaitUninterruptibly();
        session = future.getSession();
        assertTrue(session.isConnected());
        assertTrue(session.write(IoBuffer.allocate(1)).awaitUninterruptibly().isWritten());

        // Wait for the server side session to be created.
        Thread.sleep(500);
View Full Code Here

            @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

                @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

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

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

        // Build the connection address
        SocketAddress address = new InetSocketAddress( config.getLdapHost(), config.getLdapPort() );

        // And create the connection future
        ConnectFuture connectionFuture = connector.connect( address );

        // Wait until it's established
        connectionFuture.awaitUninterruptibly();

        if ( !connectionFuture.isConnected() )
        {
            // disposing connector if not connected
            try
            {
                close();
            }
            catch ( IOException ioe )
            {
                // Nothing to do
            }

            return false;
        }

        // Get the close future for this session
        CloseFuture closeFuture = connectionFuture.getSession().getCloseFuture();

        // Add a listener to close the session in the session.
        closeFuture.addListener( new IoFutureListener<IoFuture>()
        {
            public void operationComplete( IoFuture future )
            {
                // Process all the waiting operations and cancel them
                LOG.debug( "received a NoD, closing everything" );

                for ( int messageId : futureMap.keySet() )
                {
                    ResponseFuture<?> responseFuture = futureMap.get( messageId );
                    LOG.debug( "closing {}", responseFuture );

                    responseFuture.cancel();

                    try
                    {
                        if ( responseFuture instanceof AddFuture )
                        {
                            ( ( AddFuture ) responseFuture ).set( AddNoDResponse.PROTOCOLERROR );
                        }
                        else if ( responseFuture instanceof BindFuture )
                        {
                            ( ( BindFuture ) responseFuture ).set( BindNoDResponse.PROTOCOLERROR );
                        }
                        else if ( responseFuture instanceof CompareFuture )
                        {
                            ( ( CompareFuture ) responseFuture ).set( CompareNoDResponse.PROTOCOLERROR );
                        }
                        else if ( responseFuture instanceof DeleteFuture )
                        {
                            ( ( DeleteFuture ) responseFuture ).set( DeleteNoDResponse.PROTOCOLERROR );
                        }
                        else if ( responseFuture instanceof ExtendedFuture )
                        {
                            ( ( ExtendedFuture ) responseFuture ).set( ExtendedNoDResponse.PROTOCOLERROR );
                        }
                        else if ( responseFuture instanceof ModifyFuture )
                        {
                            ( ( ModifyFuture ) responseFuture ).set( ModifyNoDResponse.PROTOCOLERROR );
                        }
                        else if ( responseFuture instanceof ModifyDnFuture )
                        {
                            ( ( ModifyDnFuture ) responseFuture ).set( ModifyDnNoDResponse.PROTOCOLERROR );
                        }
                        else if ( responseFuture instanceof SearchFuture )
                        {
                            ( ( SearchFuture ) responseFuture ).set( SearchNoDResponse.PROTOCOLERROR );
                        }
                    }
                    catch ( ExecutionException e )
                    {
                        LOG.error( "Error while processing the NoD for {}", responseFuture );
                    }
                    catch ( InterruptedException e )
                    {
                        LOG.error( "Error while processing the NoD for {}", responseFuture );
                    }

                    futureMap.remove( messageId );
                }

                futureMap.clear();
            }
        } );

        // Get back the session
        ldapSession = connectionFuture.getSession();
        connected.set( true );

        // Store the container into the session
        ldapSession.setAttribute( "LDAP-Container", codec.newMessageContainer() );
View Full Code Here

    NioSocketConnector connector = new NioSocketConnector();
    connector.getFilterChain().addLast("codec",
        new ProtocolCodecFilter(
            new TextLineCodecFactory(Charset.forName("US-ASCII"))));
    connector.setHandler(new TcpProtocolHandler(this));
    ConnectFuture cf = connector.connect(new InetSocketAddress(HOST, 7002));
    cf.addListener(new IoFutureListener() {
      public void operationComplete(IoFuture s) {
        try {
          if(s.getSession() != null && s.getSession().isConnected()) {
            m_packetGen.setTcpSession(s.getSession());
          } else {
            messageDialog("Connection timed out.\n"
                + "The server may be offline.\n"
                + "Contact an administrator for assistance.", getDisplay());
            HOST = "";
            m_packetGen = null;
          }
        }catch(RuntimeIoException e){
          messageDialog("Connection timed out.\n"
              + "The server may be offline.\n"
              + "Contact an administrator for assistance.", getDisplay());
          HOST = "";
          m_packetGen = null;
        }catch (Exception e) {
          e.printStackTrace();
          messageDialog("Connection timed out.\n"
              + "The server may be offline.\n"
              + "Contact an administrator for assistance.", getDisplay());
          HOST = "";
          m_packetGen = null;
        }
      }
    });
    /*
     * Connect via UDP to game server
     */
    NioDatagramConnector udp = new NioDatagramConnector();
    udp.getFilterChain().addLast("codec",
        new ProtocolCodecFilter(
            new TextLineCodecFactory(Charset.forName("US-ASCII"))));
    udp.setHandler(new UdpProtocolHandler(this));
    cf = udp.connect(new InetSocketAddress(HOST, 7005));
    cf.addListener(new IoFutureListener() {
      public void operationComplete(IoFuture s) {
        try {
          if(s.getSession().isConnected()) {
            m_packetGen.setUdpSession(s.getSession());
          } else {
            messageDialog("Connection timed out.\n"
                + "The server may be offline.\n"
                + "Contact an administrator for assistance.", getDisplay());
            HOST = "";
            m_packetGen = null;
          }
        }catch(RuntimeIoException e){
          messageDialog("Connection timed out.\n"
              + "The server may be offline.\n"
              + "Contact an administrator for assistance.", getDisplay());
          HOST = "";
          m_packetGen = null;
        } catch (Exception e) {
          e.printStackTrace();
          messageDialog("Connection timed out.\n"
              + "The server may be offline.\n"
              + "Contact an administrator for assistance.", getDisplay());
          HOST = "";
          m_packetGen = null;
        }
      }
    });
    /*
     * Connect via TCP to chat server
     */
    NioSocketConnector chat = new NioSocketConnector();
    chat.getFilterChain().addLast("codec",
        new ProtocolCodecFilter(
            new TextLineCodecFactory(Charset.forName("US-ASCII"))));
    chat.setHandler(new ChatProtocolHandler());
    ConnectFuture cf2 = connector.connect(new InetSocketAddress(CHATHOST, 7001));
    cf2.addListener(new IoFutureListener() {
      public void operationComplete(IoFuture s) {
        try {
          if(s.getSession() != null && s.getSession().isConnected()) {
            m_packetGen.setChatSession(s.getSession());
            m_chatServerIsActive = true;
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.