List of usage examples for io.netty.util ReferenceCountUtil release
public static boolean release(Object msg)
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecode() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, Delimiters.lineDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound();//from w w w . j av a2 s .c o m assertEquals("first", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); ch.finish(); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeNulDelimiter() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, Delimiters.nulDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("first\0second\0third", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound();/*from w w w .j a v a2 s .c om*/ assertEquals("first", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); ch.finish(); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeAndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, Delimiters.lineDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound();/*from w ww. j a v a2s. c o m*/ assertEquals("first", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); // Close channel assertTrue(ch.finish()); ByteBuf buf3 = ch.readInbound(); assertEquals("third", buf3.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); assertFalse(ch.finish()); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); buf3.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeNulDelimiterAndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, true, true, Delimiters.nulDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("first\0second\0third", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound();//from w ww . ja va 2 s. c om assertEquals("first", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); // Close channel assertTrue(ch.finish()); ByteBuf buf3 = ch.readInbound(); assertEquals("third", buf3.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); assertFalse(ch.finish()); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeWithStrip() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, true, false, false)); ch.writeInbound(copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound();//from w w w. ja v a 2 s.com assertEquals("first", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); ch.finish(); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeWithoutStrip() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, false, false, false)); ch.writeInbound(copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound();/*from ww w . j av a 2s . co m*/ assertEquals("first\r\n", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("second\n", buf2.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); ch.finish(); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeWithStripAndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, true, false, true)); ch.writeInbound(copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII)); ByteBuf buf1 = ch.readInbound();// ww w . j a va 2s . com assertEquals("first", buf1.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); // Close channel assertTrue(ch.finish()); ByteBuf buf3 = ch.readInbound(); assertEquals("third", buf3.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); assertFalse(ch.finish()); ReferenceCountUtil.release(ch.readInbound()); buf1.release(); buf2.release(); buf3.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientLineBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeWithoutStripAndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new LenientLineBasedFrameDecoder(8192, false, false, true)); ch.writeInbound(copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII)); ByteBuf buf1 = ch.readInbound();/*from ww w .j a v a 2s . c o m*/ assertEquals("first\r\n", buf1.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("second\n", buf2.toString(CharsetUtil.US_ASCII)); // Close channel assertTrue(ch.finish()); ByteBuf buf3 = ch.readInbound(); assertEquals("third", buf3.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); assertFalse(ch.finish()); ReferenceCountUtil.release(ch.readInbound()); buf1.release(); buf2.release(); buf3.release(); }
From source file:org.janusgraph.graphdb.tinkerpop.gremlin.server.handler.HttpHMACAuthenticationHandler.java
License:Apache License
private void sendError(final ChannelHandlerContext ctx, final Object msg) { ctx.writeAndFlush(new DefaultFullHttpResponse(HTTP_1_1, UNAUTHORIZED)) .addListener(ChannelFutureListener.CLOSE); ReferenceCountUtil.release(msg); }
From source file:org.janusgraph.graphdb.tinkerpop.gremlin.server.handler.HttpHMACAuthenticationHandler.java
License:Apache License
private void replyWithToken(final ChannelHandlerContext ctx, final Object msg, final String token) { final String json = "{\"token\": \"" + token + "\"}"; final byte[] jsonBytes = json.getBytes(); final FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(jsonBytes)); response.headers().set(CONTENT_TYPE, "application/json"); response.headers().set(CONTENT_LENGTH, response.content().readableBytes()); ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); ReferenceCountUtil.release(msg); }