Package org.jboss.netty.channel

Examples of org.jboss.netty.channel.ChannelFuture


        ClassNotFoundException {
      throw new UnsupportedOperationException();
    }

    public Future<?> write(Object msg) {
      final ChannelFuture future = channel.write(msg);
      future.addListener(completionListener);
      return new Future<Void>() {

        @Override
        public boolean cancel(boolean arg0) {
          return future.cancel();
        }

        @Override
        public Void get() throws InterruptedException,
            ExecutionException {
          future.await();
          if (!future.isSuccess()) {
            throw new ExecutionException(future.getCause());
          }
          return null;
        }

        @Override
        public Void get(long arg0, TimeUnit arg1)
            throws InterruptedException, ExecutionException,
            TimeoutException {
          if (future.await(arg0, arg1)) {
            if (!future.isSuccess()) {
              throw new ExecutionException(future.getCause());
            }
            return null;
          }
          throw new TimeoutException();
        }

        @Override
        public boolean isCancelled() {
          return future.isCancelled();
        }

        @Override
        public boolean isDone() {
          return future.isDone();
        }
      };
    }
View Full Code Here


    }

    private void flushResponse() {
        // Send the response and close the connection.
        try {
            ChannelFuture future = write(responseBuffer);
            future.addListener(ChannelFutureListener.CLOSE);
        } catch (Exception e) {
            ioExceptionHandler.uncaughtException(Thread.currentThread(), e);
        }
    }
View Full Code Here

                response.addHeader(SET_COOKIE, cookieEncoder.encode());
            }
        }

        // Write the response.
        ChannelFuture future = e.getChannel().write(response);

        // Close the non-keep-alive connection after the write operation is done.
        if (!keepAlive) {
            future.addListener(ChannelFutureListener.CLOSE);
        }
    }
View Full Code Here

        // Set up the event pipeline factory.
        bootstrap.setPipelineFactory(new FactorialClientPipelineFactory(count));

        // Make a new connection.
        ChannelFuture connectFuture =
            bootstrap.connect(new InetSocketAddress(host, port));

        // Wait until the connection is made successfully.
        Channel channel = connectFuture.awaitUninterruptibly().getChannel();

        // Get the handler instance to retrieve the answer.
        FactorialClientHandler handler =
            (FactorialClientHandler) channel.getPipeline().getLast();
View Full Code Here

        // Set up the event pipeline factory.
        bootstrap.setPipelineFactory(new HttpClientPipelineFactory(ssl));

        // Start the connection attempt.
        ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));

        // Wait until the connection attempt succeeds or fails.
        Channel channel = future.awaitUninterruptibly().getChannel();
        if (!future.isSuccess()) {
            future.getCause().printStackTrace();
            bootstrap.releaseExternalResources();
            return;
        }

        // Prepare the HTTP request.
View Full Code Here

        inboundChannel.setReadable(false);

        // Start the connection attempt.
        ClientBootstrap cb = new ClientBootstrap(cf);
        cb.getPipeline().addLast("handler", new OutboundHandler(e.getChannel()));
        ChannelFuture f = cb.connect(new InetSocketAddress(remoteHost, remotePort));

        outboundChannel = f.getChannel();
        f.addListener(new ChannelFutureListener() {
            public void operationComplete(ChannelFuture future) throws Exception {
                if (future.isSuccess()) {
                    // Connection attempt succeeded:
                    // Begin to accept incoming traffic.
                    inboundChannel.setReadable(true);
View Full Code Here

    });
  }
});
   
     // Start the connection attempt.
    ChannelFuture future = bootstrap.connect(new InetSocketAddress("localhost", 8080));
    // Wait until the connection attempt succeeds or fails.
    Channel channel = future.awaitUninterruptibly().getChannel();
    if (future.isSuccess())
      System.out.println("connected");
   
    // get a proxy

    }
View Full Code Here

              ctx.sendUpstream(e);
              System.out.println("channel closed wait to reconnect ...");
                  timer.schedule(new TimerTask() {
                      public void run() {
                        System.out.println("reconnecting...");
                         ChannelFuture f = _bootstrap.connect();
                         try
              {
                           System.out.println("future wait");
                f.awaitUninterruptibly();
                         System.out.println("future wait terminated");
              }
              catch (Exception e)
              {
                // TODO Auto-generated catch block
                e.printStackTrace();
                 }
                       if (f.isSuccess())
                       System.out.println("connected");
                       else
                       {
                         System.out.println("not connected");
                        // f.getChannel().close();
View Full Code Here

      ctx.sendUpstream(e);
      Constants.ahessianLogger.warn("channel closed wait to reconnect ...");
          timer.schedule(new TimerTask() {
              public void run() {
                Constants.ahessianLogger.warn("reconnecting...");
                  ChannelFuture f = _bootstrap.getBootstrap().connect();
                  try
        {
          f.awaitUninterruptibly();
        }
        catch (Exception e)
        {
          // TODO Auto-generated catch block
          Constants.ahessianLogger.warn("", e);
            }
                if (f.isSuccess())
                  Constants.ahessianLogger.warn("connected");
                else
                {
                  Constants.ahessianLogger.warn("not connected");
                }
View Full Code Here

        }
      }
      if (_channel != null && _channel.isOpen())
        try
        {
          ChannelFuture cf = _channel.close();
          getLog().info("controller close session");
          cf.await(1000);
        }
        catch (InterruptedException e)
        {
          e.printStackTrace();
          getLog().info("session close wait interrupted in JVMController");
View Full Code Here

TOP

Related Classes of org.jboss.netty.channel.ChannelFuture

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.