Package org.jboss.netty.channel

Examples of org.jboss.netty.channel.ChannelFuture


    HashMap<String, String> footers = new HashMap<String, String>();
    footers.put("footer1", "1value");
    footers.put("footer2", "2value");
    setupServer(HttpResponseStatus.OK, chunks, headers, footers);

    ChannelFuture connectFuture = _clientBootstrap.connect(_serverAddress);
    connectFuture.awaitUninterruptibly(1, TimeUnit.SECONDS);
    assertTrue("connect succeeded", connectFuture.isSuccess());

    HttpRequest request = new DefaultHttpRequest(HTTP_1_1, HttpMethod.GET, "/test");
    Channel requestChannel = connectFuture.getChannel();
    ChannelFuture writeFuture = requestChannel.write(request);

    writeFuture.awaitUninterruptibly(1, TimeUnit.SECONDS);
    assertTrue("connect succeeded", writeFuture.isSuccess());

    HttpResponse response = _responseHandler.getResponse();
    assertEquals("response code", Integer.toString(HttpResponseStatus.OK.getCode()),
                 response.getHeader(ChunkedBodyWritableByteChannel.RESPONSE_CODE_FOOTER_NAME));
    assertEquals("Checking header1 value", "value1", response.getHeader("header1"));
View Full Code Here


    headers.put("header1", "value1");
    headers.put("header2", "value2");
    HashMap<String, String> footers = new HashMap<String, String>();
    setupServer(HttpResponseStatus.BAD_GATEWAY, chunks, headers, footers);

    ChannelFuture connectFuture = _clientBootstrap.connect(_serverAddress);
    connectFuture.awaitUninterruptibly(1, TimeUnit.SECONDS);
    assertTrue("connect succeeded", connectFuture.isSuccess());

    HttpRequest request = new DefaultHttpRequest(HTTP_1_1, HttpMethod.GET, "/test");
    Channel requestChannel = connectFuture.getChannel();
    ChannelFuture writeFuture = requestChannel.write(request);

    writeFuture.awaitUninterruptibly(1, TimeUnit.SECONDS);
    assertTrue("connect succeeded", writeFuture.isSuccess());

    HttpResponse response = _responseHandler.getResponse();
    assertEquals("response code", HttpResponseStatus.BAD_GATEWAY, response.getStatus());
    assertEquals("Checking header1 value", "value1", response.getHeader("header1"));
    assertEquals("Checking header2 value", "value2", response.getHeader("header2"));
View Full Code Here

        _httpRequest = null;
        return;
      }

      // Future should be done by this time
      ChannelFuture future = e.getFuture();

      boolean success = future.isSuccess();
      if (!success) {
        String msg = "Write request failed with cause :" + future.getCause();
        _log.error(msg);
        _messageState = MessageState.REQUEST_FAILURE;
        cause = new IllegalStateException(msg);
        _messageState = MessageState.CLOSED;
      } else {
View Full Code Here

  }

  public SimpleHttpResponseHandler sendRequest(SocketAddress serverAddress, HttpRequest request)
                                               throws Exception
  {
    ChannelFuture connectFuture = _clientBootstrap.connect(serverAddress);
    if (_timeoutPolicy == TimeoutPolicy.CONNECT_TIMEOUT ||
        _timeoutPolicy == TimeoutPolicy.ALL_TIMEOUTS)
    {
      connectFuture.awaitUninterruptibly(1000, TimeUnit.SECONDS);
    }
    else
    {
      connectFuture.awaitUninterruptibly();
    }
    assertTrue("connect succeeded", connectFuture.isSuccess());

    Channel requestChannel = connectFuture.getChannel();
    ChannelFuture writeFuture = requestChannel.write(request);

    if (_timeoutPolicy == TimeoutPolicy.SEND_TIMEOUT ||
        _timeoutPolicy == TimeoutPolicy.ALL_TIMEOUTS)
    {
      writeFuture.awaitUninterruptibly(1000, TimeUnit.SECONDS);
    }
    else
    {
      writeFuture.awaitUninterruptibly();
    }
    assertTrue("send succeeded", writeFuture.isSuccess());

    return _responseHandler;
  }
View Full Code Here

      _trailer.removeHeader(name);
    }
  }
  private void writeToChannel(Object o, int flushSize) throws IOException
  {
    ChannelFuture channelFuture = _channel.write(o);
    if (flushSize > 0 && !_channel.isWritable())
    {
      ChannelConfig channelConfig = _channel.getConfig();
      if (channelConfig instanceof NioSocketChannelConfig)
      {
        NioSocketChannelConfig nioSocketConfig = (NioSocketChannelConfig)channelConfig;
        nioSocketConfig.setWriteBufferLowWaterMark(flushSize);
        nioSocketConfig.setWriteBufferHighWaterMark(flushSize);
      }
    }
    awaitChannelFuture(channelFuture);
    if (! channelFuture.isSuccess())
    {
      throw new IOException(channelFuture.getCause());
    }
  }
View Full Code Here

        }
        if(path.equals("/")) {
          path = "index.html";
        }
       
        ChannelFuture writeFuture =  null;
        if(inJar) {
          writeFuture = writeResponseFromResource(ctx, e, request, path);
        } else {
          writeFuture = writeResponseFromFile(ctx, e, request, path);
        }

        // Decide whether to close the connection or not.
        if (writeFuture!=null && !isKeepAlive(request)) {
            // Close the connection when the whole content is written out.
            writeFuture.addListener(ChannelFutureListener.CLOSE);
        }
    }
View Full Code Here

        // Write the initial line and the header.
        ch.write(response);

        // Write the content.
        ChannelFuture writeFuture;
        if (ch.getPipeline().get(SslHandler.class) != null) {
            // Cannot use zero-copy with HTTPS.
            writeFuture = ch.write(new ChunkedFile(raf, 0, fileLength, 8192));
        } else {
            // No encryption - use zero-copy.
            final FileRegion region =
                new DefaultFileRegion(raf.getChannel(), 0, fileLength);
            writeFuture = ch.write(region);
            final String finalPath = path;
            writeFuture.addListener(new ChannelFutureProgressListener() {
                public void operationComplete(ChannelFuture future) {
                    region.releaseExternalResources();
                }

                public void operationProgressed(
View Full Code Here

        }

        Channel channel = getFactory().newChannel(bossPipeline);

        // Wait until the future is available.
        ChannelFuture future = null;
        boolean interrupted = false;
        do {
            try {
                future = futureQueue.poll(Integer.MAX_VALUE, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                interrupted = true;
            }
        } while (future == null);

        if (interrupted) {
            Thread.currentThread().interrupt();
        }

        // Wait for the future.
        future.awaitUninterruptibly();
        if (!future.isSuccess()) {
            future.getChannel().close().awaitUninterruptibly();
            throw new ChannelException("Failed to bind to: " + localAddress, future.getCause());
        }

        return channel;
    }
View Full Code Here

    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    response.setHeader(CONTENT_LENGTH, cb.readableBytes());
    response.setHeader(CONTENT_TYPE, "application/json");
    response.setHeader(CACHE_CONTROL, "no-cache");
    response.setContent(cb);
    ChannelFuture cf = Channels.future(channel);
    ctx.sendDownstream(new DownstreamMessageEvent(channel, cf, response, channel.getRemoteAddress()));
   
  }
View Full Code Here

        HttpRequest request = (HttpRequest)message;
        int metricCount = processMetric(request);
        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
        response.setContent(ChannelBuffers.copiedBuffer("\n" + metricCount + "\n", CharsetUtil.UTF_8));
        response.setHeader(CONTENT_TYPE, "text/plain");
        ChannelFuture future = Channels.future(channel);
        ctx.sendDownstream(new DownstreamMessageEvent(channel, future, response, channel.getRemoteAddress()));
        future.addListener(ChannelFutureListener.CLOSE);       
      }
    }
    ctx.sendUpstream(e);
  }
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.