Examples of ChannelFuture


Examples of org.jboss.netty.channel.ChannelFuture

        }
        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

Examples of org.jboss.netty.channel.ChannelFuture

        // 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

Examples of org.jboss.netty.channel.ChannelFuture

        }

        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

Examples of org.jboss.netty.channel.ChannelFuture

    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

Examples of org.jboss.netty.channel.ChannelFuture

        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

Examples of org.jboss.netty.channel.ChannelFuture

            res.setContent(ChannelBuffers.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8));
            setContentLength(res, res.getContent().readableBytes());
        }

        // Send the response and close the connection if necessary.
        ChannelFuture f = ctx.getChannel().write(res);
        if (!isKeepAlive(req) || res.getStatus().getCode() != 200) {
            f.addListener(ChannelFutureListener.CLOSE);
        }
    }
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.