Package org.apache.mina.common

Examples of org.apache.mina.common.ConnectFuture


        // Set connect timeout.
        ((IoConnectorConfig) connector.getDefaultConfig())
                .setConnectTimeout(15);

        // Start communication.
        ConnectFuture cf = connector.connect(new InetSocketAddress(
                args[0], Integer.parseInt(args[1])), new NetCatProtocolHandler());
       
        // Wait for the connection attempt to be finished.
        cf.join();
        cf.getSession();
    }
View Full Code Here


        // Set connect timeout.
        ((IoConnectorConfig) connector.getDefaultConfig())
                .setConnectTimeout(15);

        // Start communication.
        ConnectFuture cf = connector.connect(new InetSocketAddress(
                args[0], Integer.parseInt(args[1])), new NetCatProtocolHandler());
       
        // Wait for the connection attempt to be finished.
        cf.join();
        cf.getSession();
    }
View Full Code Here

        cfg.getFilterChain().addLast("logger", new LoggingFilter());

        IoSession session;
        for (;;) {
            try {
                ConnectFuture future = connector.connect(new InetSocketAddress(
                        HOSTNAME, PORT), new ClientSessionHandler(values), cfg);

                future.join();
                session = future.getSession();
                break;
            } catch (RuntimeIOException e) {
                System.err.println("Failed to connect.");
                e.printStackTrace();
                Thread.sleep(5000);
View Full Code Here

        // Set up server
        acceptor.bind(address, new TennisPlayer());

        // Connect to the server.
        VmPipeConnector connector = new VmPipeConnector();
        ConnectFuture future = connector.connect(address, new TennisPlayer());
        future.join();
        IoSession session = future.getSession();

        // Send the first ping message
        session.write(new TennisBall(10));

        // Wait until the match ends.
View Full Code Here

                throw e;
            }
            connListener = new ConnectorConnListner(listener);
        }
        logger.log(Level.FINE, "connecting to {0}", endpoint);
        ConnectFuture future =
      connector.connect(endpoint.getAddress(), connListener);
  synchronized (this) {
      connectFuture = future;
  }
    }
View Full Code Here

     * {@inheritDoc}
     */
    public boolean waitForConnect(long timeout)
  throws IOException, InterruptedException
    {
  ConnectFuture future;
  synchronized (this) {
      future = connectFuture;
  }
  if (future == null) {
      throw new IllegalStateException("No connect attempt in progress");
  }
        if (!future.isConnected()) {
      future.join(timeout);
  }

  boolean ready = future.isReady();
  if (ready) {
      try {
    future.getSession();
      } catch (RuntimeIOException e) {
    Throwable t = e.getCause();
    if (t instanceof IOException) {
        throw (IOException) t;
    }
View Full Code Here

            public void messageReceived(IoSession ioSession, Object object) throws Exception {
                super.messageReceived(ioSession, object);
                /** TODO */
            }
        };
        ConnectFuture future = connector.connect(address, ioHandler, endpoint.getConfig());
        future.join();
        session = future.getSession();
    }
View Full Code Here

        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

        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

            }
        });

        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

TOP

Related Classes of org.apache.mina.common.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.