Package io.netty.channel

Examples of io.netty.channel.ChannelHandlerContext


        return session.connectionContext().channel().isActive() || session.inuse();
    }

    @Override
    public void onSockJSServerInitiatedClose(final SockJsSession session) {
        final ChannelHandlerContext context = session.connectionContext();
        if (context != null) { //could be null if the request is aborted, for example due to missing callback.
            if (logger.isDebugEnabled()) {
                logger.debug("Will close session connectionContext {}", session.connectionContext());
            }
            context.close();
        }
        sessions.remove(session.sessionId());
    }
View Full Code Here


        }
    }

    @Override
    public void onSockJSServerInitiatedClose(final SockJsSession session) {
        final ChannelHandlerContext context = session.connectionContext();
        if (context != null) { //could be null if the request is aborted, for example due to missing callback.
            logger.debug("Will close session connectionContext " + session.connectionContext());
            context.close();
        }
    }
View Full Code Here

    /**
     *
     * Listing 6.2 of <i>Netty in Action</i>
     */
    public static void eventsViaChannel(ChannelHandlerContext context) {
        ChannelHandlerContext ctx = context;
        Channel channel = ctx.channel();
        channel.write(Unpooled.copiedBuffer("Netty in Action",
                CharsetUtil.UTF_8));

    }
View Full Code Here

    /**
     *
     * Listing 6.3 of <i>Netty in Action</i>
     */
    public static void eventsViaChannelPipeline(ChannelHandlerContext context) {
        ChannelHandlerContext ctx = context;
        ChannelPipeline pipeline = ctx.pipeline();
        pipeline.write(Unpooled.copiedBuffer("Netty in Action",
                CharsetUtil.UTF_8));

    }
View Full Code Here

    /**
     *
     * Listing 6.4 of <i>Netty in Action</i>
     */
    public static void eventsViaChannelHandlerContext(ChannelHandlerContext context) {
        ChannelHandlerContext ctx = context;
        ctx.write(Unpooled.copiedBuffer("Netty in Action",
                CharsetUtil.UTF_8));

    }
View Full Code Here

            return buf;
          }
        });
   
    buf.retain();
    ChannelHandlerContext ctx = mockChannelHandlerContext(buf, m2);
    encoder.write(ctx, m1, null);
    Decoder decoder = new Decoder(new DSASignatureFactory());
    decoder.decode(ctx, buf, m1.recipient().createSocketTCP(), m1
        .sender().createSocketTCP());
    return decoder.message();
View Full Code Here

   * @return The mocked ChannelHandlerContext
   */
  @SuppressWarnings("unchecked")
  private ChannelHandlerContext mockChannelHandlerContext(
      final AlternativeCompositeByteBuf buf, final AtomicReference<Message> m2) {
    ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
    ByteBufAllocator alloc = mock(ByteBufAllocator.class);
    when(ctx.alloc()).thenReturn(alloc);
    when(alloc.ioBuffer()).thenReturn(buf);

    DatagramChannel dc = mock(DatagramChannel.class);
    when(ctx.channel()).thenReturn(dc);
    when(ctx.writeAndFlush(any(), any(ChannelPromise.class))).thenReturn(
        null);

    Attribute<InetSocketAddress> attr = mock(Attribute.class);
    when(ctx.attr(any(AttributeKey.class))).thenReturn(attr);

    when(ctx.fireChannelRead(any())).then(new Answer<Void>() {
      @Override
      public Void answer(final InvocationOnMock invocation)
          throws Throwable {
        Object[] args = invocation.getArguments();
        m2.set((Message) args[0]);
        return null;
      }
    });
   
    when(ctx.fireExceptionCaught(any(Throwable.class))).then(new Answer<Void>() {

      @Override
      public Void answer(InvocationOnMock invocation) throws Throwable {
        Object[] args = invocation.getArguments();
        for(Object obj:args) {
View Full Code Here

public class WebSocket08FrameDecoderTest {

    @Test
    public void channelInactive() throws Exception {
        final WebSocket08FrameDecoder decoder = new WebSocket08FrameDecoder(true, true, 65535, false);
        final ChannelHandlerContext ctx = EasyMock.createMock(ChannelHandlerContext.class);
        decoder.channelInactive(ctx);
    }
View Full Code Here

    }

    @Test
    public void testHttpUpgradeRequest() throws Exception {
        EmbeddedChannel ch = createChannel(new MockOutboundHandler());
        ChannelHandlerContext handshakerCtx = ch.pipeline().context(WebSocketServerProtocolHandshakeHandler.class);
        writeUpgradeRequest(ch);
        assertEquals(SWITCHING_PROTOCOLS, ReferenceCountUtil.releaseLater(responses.remove()).status());
        assertNotNull(WebSocketServerProtocolHandler.getHandshaker(handshakerCtx));
    }
View Full Code Here

        channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) {
                if (future.isSuccess()) {
                    ChannelPipeline p = future.channel().pipeline();
                    ChannelHandlerContext ctx = p.context(HttpRequestEncoder.class);
                    if (ctx == null) {
                        ctx = p.context(HttpClientCodec.class);
                    }
                    if (ctx == null) {
                        promise.setFailure(new IllegalStateException("ChannelPipeline does not contain " +
                                "a HttpRequestEncoder or HttpClientCodec"));
                        return;
                    }
                    p.addAfter(ctx.name(), "ws-encoder", newWebSocketEncoder());

                    promise.setSuccess();
                } else {
                    promise.setFailure(future.cause());
                }
View Full Code Here

TOP

Related Classes of io.netty.channel.ChannelHandlerContext

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.