Examples of ConnectFuture


Examples of org.apache.mina.common.ConnectFuture

        expectedConfig.getFilterChain().addLast("mock", mockFilter);
        acceptor.bind(new InetSocketAddress(port), mockHandler, expectedConfig);

        try {
            ConnectFuture future = connector.connect(new InetSocketAddress(
                    "localhost", port), new IoHandlerAdapter());
            future.join();

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

            future.getSession().close();

            for (int i = 0; i < 30; i++) {
                if (result.length() == 2) {
                    break;
                }
View Full Code Here

Examples of org.apache.mina.common.ConnectFuture

            }
        });

        final StringBuffer actual = new StringBuffer();

        ConnectFuture future = connector.connect(new VmPipeAddress(1),
                new IoHandlerAdapter() {

                    public void messageReceived(IoSession session,
                            Object message) throws Exception {
                        actual.append(message);
                    }

                    public void sessionClosed(IoSession session)
                            throws Exception {
                        actual.append("C");
                    }

                    public void sessionOpened(IoSession session)
                            throws Exception {
                        actual.append("A");
                    }

                });

        future.join();
        future.getSession().getCloseFuture().join();
        acceptor.unbindAll();

        // sessionClosed() might not be invoked yet
        // even if the connection is closed.
        while (actual.indexOf("C") < 0) {
View Full Code Here

Examples of org.apache.mina.common.ConnectFuture

                actual.append("A");
            }

        });

        ConnectFuture future = connector.connect(new VmPipeAddress(1),
                new IoHandlerAdapter() {
                    public void sessionOpened(IoSession session)
                            throws Exception {
                        session.write("B");
                    }

                    public void messageSent(IoSession session, Object message)
                            throws Exception {
                        session.close();
                    }
                });

        future.join();
        future.getSession().getCloseFuture().join();
        acceptor.unbindAll();

        // sessionClosed() might not be invoked yet
        // even if the connection is closed.
        while (actual.indexOf("C") < 0) {
View Full Code Here

Examples of org.apache.mina.common.ConnectFuture

        SocketAddress addr = createSocketAddress(port);

        IoConnector connector = new SocketConnector();
        IoSession[] sessions = new IoSession[5];
        for (int i = 0; i < sessions.length; i++) {
            ConnectFuture future = connector.connect(new InetSocketAddress(
                    "localhost", port), new IoHandlerAdapter());
            future.join();
            sessions[i] = future.getSession();
            Assert.assertTrue(sessions[i].isConnected());
        }

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

Examples of org.apache.mina.common.ConnectFuture

        if (LOG.isDebugEnabled()) {
            LOG.debug("Creating connector to address: " + address + " using connector: " + connector + " timeout: " + timeout + " millis.");
        }
        IoHandler ioHandler = new ResponseHandler(endpoint);
        // connect and wait until the connection is established
        ConnectFuture future = connector.connect(address, ioHandler, endpoint.getConnectorConfig());
        future.join();
        session = future.getSession();
    }
View Full Code Here

Examples of org.apache.mina.common.ConnectFuture

    }

    public void fireExceptionCaught(IoSession session, Throwable cause) {
        // Notify the related ConnectFuture
        // if the session is created from SocketConnector.
        ConnectFuture future = (ConnectFuture) session
                .removeAttribute(CONNECT_FUTURE);
        if (future == null) {
            Entry head = this.head;
            callNextExceptionCaught(head, session, cause);
        } else {
            // Please note that this place is not the only place that
            // calls ConnectFuture.setException().
            future.setException(cause);
        }
    }
View Full Code Here

Examples of org.apache.mina.common.ConnectFuture

            try {
                session.getHandler().sessionOpened(session);
            } finally {
                // Notify the related ConnectFuture
                // if the session is created from SocketConnector.
                ConnectFuture future = (ConnectFuture) session
                        .removeAttribute(CONNECT_FUTURE);
                if (future != null) {
                    future.setSession(session);
                }
            }
        }
View Full Code Here

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

            connector.getFilterChain().addLast(
                                               "codec",
                                               new ProtocolCodecFilter(
                                                       new ObjectSerializationCodecFactory()));

            ConnectFuture future1 = connector.connect( address );
            future1.join();
            if (!future1.isConnected()) {
                return false;
            }
            session = future1.getSession();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
View Full Code Here

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

   * @see net.solosky.maplefetion.net.TransferFactory#createTransfer(net.solosky.maplefetion.net.Port)
   */
  @Override
  public Transfer createTransfer(Port port) throws TransferException
  {
     ConnectFuture cf = connector.connect(new InetSocketAddress(port.getAddress(), port.getPort()));
    
     //等待连接结果
       try {
      cf.await();
    } catch (InterruptedException e) {
      throw new TransferException(e);
    }
   
    //判断是否连接成功,如果不成功抛出异常
    if(!cf.isConnected())
      throw new TransferException("Connecting to "+port+" failed..");
   
    Transfer transfer = new MinaTransfer(cf.getSession());
    cf.getSession().setAttribute(MinaTransfer.class, transfer);
   
       return transfer;
  }
View Full Code Here

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

     
     
      log.debug("About to connect to the server... HOST: "+ClientConnectionBean.host);
      log.debug("About to connect to the server... PORT: "+ClientConnectionBean.host);
     
      ConnectFuture connFuture = connector.connect(new InetSocketAddress(
                          ClientConnectionBean.host, port));
      log.debug("About to wait.");
      connFuture.awaitUninterruptibly();
      log.debug("Adding a future listener.");
      connFuture.addListener(new IoFutureListener<ConnectFuture>() {
        public void operationComplete(ConnectFuture future) {
          if (future.isConnected()) {
            log.debug("...connected");
            session = future.getSession();
            ClientShowStatusMessage.showStatusMessage("Connected ... Ready for Action");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.