Package io.netty.channel

Examples of io.netty.channel.ChannelFuture


            throws Exception {

        long timeoutMillis = getTimeoutMillis(e);
        if (timeoutMillis > 0) {
            // Set timeout only when getTimeoutMillis() returns a positive value.
            ChannelFuture future = e.getFuture();
            final Timeout timeout = timer.newTimeout(
                    new WriteTimeoutTask(ctx, future),
                    timeoutMillis, TimeUnit.MILLISECONDS);

            future.addListener(new TimeoutCanceller(timeout));
        }

        super.writeRequested(ctx, e);
    }
View Full Code Here


                    if (evt.getValue() != null) {
                        // CONNECTED
                        InetSocketAddress inetSocketAddress = (InetSocketAddress) e.getChannel().getRemoteAddress();
                        if (!accept(ctx, e, inetSocketAddress)) {
                            ctx.setAttachment(Boolean.TRUE);
                            ChannelFuture future = handleRefusedChannel(ctx, e, inetSocketAddress);
                            if (future != null) {
                                future.addListener(ChannelFutureListener.CLOSE);
                            } else {
                                Channels.close(e.getChannel());
                            }
                            if (isBlocked(ctx) && !continues(ctx, evt)) {
                                // don't pass to next level since channel was blocked early
View Full Code Here

                @Override
                public void initChannel(SocketChannel channel) throws Exception {
                    channel.pipeline().addLast(new TestServerHandler());
                };
            });
            ChannelFuture bindFuture = bootstrap.bind();
            //bindFuture.sync();
            //Channel channel = bindFuture.channel();
            //ChannelFuture closeFuture = channel.closeFuture();
            //closeFuture.sync();
        } finally {
View Full Code Here

    try {
      Preconditions.checkNotNull(protobufBody);
      ChannelListenerWithCoordinationId futureListener = queue.get(listener, clazz, connection);
      OutboundRpcMessage m = new OutboundRpcMessage(RpcMode.REQUEST, rpcType, futureListener.getCoordinationId(), protobufBody, dataBodies);
      connection.acquirePermit();
      ChannelFuture channelFuture = connection.getChannel().writeAndFlush(m);
      channelFuture.addListener(futureListener);
      completed = true;
    } catch (InterruptedException e) {
      completed = true;
      listener.failed(new RpcException("Interrupted while attempting to acquire outbound queue.", e));
    } finally {
View Full Code Here

        WebSocketServerHandshakerFactory factory =
                new WebSocketServerHandshakerFactory(getWebSocketLocation(req), null, false, configuration.getMaxFramePayloadLength());
        WebSocketServerHandshaker handshaker = factory.newHandshaker(req);
        if (handshaker != null) {
            ChannelFuture f = handshaker.handshake(channel, req);
            f.addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    if (!future.isSuccess()) {
                        log.error("Can't handshake " + sessionId, future.cause());
                        return;
View Full Code Here

             p.addLast(group, commandHandler);
           }
         });

        // Start the server.
        ChannelFuture f = b.bind().sync();

        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
      group.shutdownGracefully();
    }
  }
View Full Code Here

        WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory(
                getWebSocketLocation(req), null, false);
        WebSocketServerHandshaker handshaker = factory.newHandshaker(req);
        if (handshaker != null) {
            ChannelFuture f = handshaker.handshake(channel, req);
            f.addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    connectClient(channel, sessionId);
                }
            });
View Full Code Here

    }

    private void scheduleDisconnect(Channel channel, final UUID sessionId) {
        final SchedulerKey key = new SchedulerKey(Type.CLOSE_TIMEOUT, sessionId);
        scheduler.cancel(key);
        ChannelFuture future = channel.closeFuture();
        future.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                scheduler.schedule(key, new Runnable() {
                    @Override
                    public void run() {
View Full Code Here

            this.messages = messages;
        }

        @Override
        protected void channelRead0(final ChannelHandlerContext ctx, final FullHttpRequest fullHttpRequest) throws Exception {
            final ChannelFuture future;
            if (HttpMethod.POST.equals(fullHttpRequest.getMethod())) {
                String message = fullHttpRequest.content().toString(Charset.defaultCharset());
                synchronized (messages) {
                    messages.add(message);
                }
                final HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
                future = ctx.writeAndFlush(response);
            } else {
                LOGGER.warning("Received " + fullHttpRequest.getMethod());
                future = ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR));
            }

            future.addListener(ChannelFutureListener.CLOSE);
        }
View Full Code Here

            return output.toByteArray();
        }

        @Override
        protected void channelRead0(final ChannelHandlerContext ctx, final FullHttpRequest fullHttpRequest) throws Exception {
            final ChannelFuture future;
            if (HttpMethod.POST.equals(fullHttpRequest.getMethod())) {
                final InputStream is =
                    new ByteArrayInputStream(gzipCompression(fullHttpRequest.content().toString(Charset.defaultCharset()).getBytes()));

                final DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                final PrintWriter writer = new PrintWriter(baos);

                collector.doPost(HttpServletRequest.class.cast(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[]{HttpServletRequest.class}, new InvocationHandler() {
                    @Override
                    public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                        if (Object.class.equals(method.getDeclaringClass())) {
                            return method.invoke(this, args);
                        }

                        if ("getInputStream".equals(method.getName())) {
                            return new ServletInputStream() {
                                @Override
                                public int read() throws IOException {
                                    return is.read();
                                }
                            };
                        }

                        if ("getHeader".equals( method.getName()) && args[0].equals( "Content-Encoding" )) {
                            return "gzip";
                        }

                        if ("getHeader".equals( method.getName()) && args[0].equals( "Content-Type" )) {
                            return "foo";
                        }

                        throw new UnsupportedOperationException("not implemented: " + method.getName() + " for args: " + Arrays.asList(args));
                    }
                })),
                HttpServletResponse.class.cast(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { HttpServletResponse.class}, new InvocationHandler() {
                    @Override
                    public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                        if (Object.class.equals(method.getDeclaringClass())) {
                            return method.invoke(this, args);
                        }

                        final String name = method.getName();
                        if ("setStatus".equals(name)) {
                            response.setStatus(HttpResponseStatus.valueOf(Integer.class.cast(args[0])));
                            return null;
                        } else if ("getWriter".equals(name)) {
                            return writer;
                        }

                        throw new UnsupportedOperationException("not implemented");
                    }
                })));

                response.content().writeBytes(baos.toByteArray());
                future = ctx.writeAndFlush(response);
            } else {
                LOGGER.warning("Received " + fullHttpRequest.getMethod());
                future = ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR));
            }
            future.addListener(ChannelFutureListener.CLOSE);
        }
View Full Code Here

TOP

Related Classes of io.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.