List of usage examples for io.netty.buffer ByteBuf readableBytes
public abstract int readableBytes();
From source file:com.ebay.jetstream.http.netty.server.HttpRequestHandler.java
License:MIT License
private void processHttpRequest(HttpRequest message, ChannelHandlerContext ctx) throws Exception { if (LOGGER.isDebugEnabled()) { debugHeadersAndCookies(message); }/*from w w w .j a va 2 s . c om*/ // Expect: 100-continue should be handled by HttpObjectAggregator. ByteBuf buf = ((FullHttpMessage) message).content(); m_totalContentLength.addAndGet(buf.readableBytes()); m_server.processHttpRequest(message, ctx.channel()); }
From source file:com.ebay.jetstream.messaging.transport.netty.autoflush.handler.AutoFlushWriterChannelQueue.java
License:MIT License
/** * return true if time to flush else return false * @param e// www.jav a 2 s . c om * @return */ public void add(MessageEvent e) { m_queue.add(e); ByteBuf buf = (ByteBuf) e.getMsg(); m_bufferSize.addAndGet(buf.readableBytes()); }
From source file:com.ebay.jetstream.messaging.transport.netty.compression.MessageCompressionHandler.java
License:MIT License
/** * Invoked when {@link Channel#write(Object)} is called. *//*from w ww . j a va 2 s . c o m*/ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { try { Attribute<Boolean> attr = ctx.channel().attr(EventProducer.m_eckey); Boolean enableCompression = attr.get(); if ((enableCompression != null) && (enableCompression == true)) { ByteBuf chbuf = (ByteBuf) msg; int msglen = chbuf.readableBytes(); ExtendedChannelPromise epromise = (ExtendedChannelPromise) promise; epromise.setRawBytes(msglen); byte[] compressed = Snappy.rawCompress(chbuf.readBytes(msglen).array(), msglen); epromise.setCompressedBytes(compressed.length + 4); chbuf.release(); // need to release the original buffer - do I need to check if this this a ref counted buffer ByteBuf sendbuf = ctx.alloc().buffer(); sendbuf.writeInt(compressed.length); sendbuf.writeBytes(compressed); ctx.write(sendbuf, promise); m_totalMessagesCompressed.increment(); } else { ctx.write(msg, promise); } } catch (Throwable t) { m_totalMessagesDropped.increment(); LOGGER.debug("Failed to compress message - " + t.getLocalizedMessage()); } }
From source file:com.ebay.jetstream.messaging.transport.netty.compression.MessageDecompressionHandler.java
License:MIT License
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; }//from w w w .j a va 2 s. c om byte[] uncompressedbuf; if (m_allocBuf) uncompressedbuf = new byte[m_tmpBufSz]; else uncompressedbuf = m_tmpBuf; int framelen = frame.readableBytes(); int len = 0; try { len = Snappy.rawUncompress(frame.readBytes(framelen).array(), 0, framelen, uncompressedbuf, 0); } catch (Throwable t) { LOGGER.debug("Failed to uncompress - " + t.getLocalizedMessage()); frame.release(); return null; } frame.release(); ByteBuf buf = ctx.alloc().directBuffer(len); return buf.writeBytes(uncompressedbuf, 0, len); }
From source file:com.eightkdata.mongowp.bson.netty.DefaultNettyBsonLowLevelReader.java
License:Open Source License
@Override BsonArray readArray(@Loose @ModifiesIndexes ByteBuf byteBuf) throws NettyBsonReaderException { int length = byteBuf.readInt(); int significantLenght = length - 4 - 1; ByteBuf significantSlice = byteBuf.readSlice(significantLenght); byte b = byteBuf.readByte(); assert b == 0x00; ArrayList<BsonValue<?>> list = new ArrayList<>(); while (significantSlice.readableBytes() > 0) { list.add(readArrayEntry(significantSlice)); }//from w w w . j a v a2 s .c om return new ListBsonArray(list); }
From source file:com.eightkdata.mongowp.bson.netty.DefaultNettyBsonLowLevelReader.java
License:Open Source License
@Override BsonDocument readDocument(@Loose @ModifiesIndexes ByteBuf byteBuf) throws NettyBsonReaderException { int length = byteBuf.readInt(); int significantLenght = length - 4 - 1; ByteBuf significantSlice = byteBuf.readSlice(significantLenght); byte b = byteBuf.readByte(); assert b == 0x00; LinkedHashMap<String, BsonValue<?>> values = new LinkedHashMap<>(); while (significantSlice.readableBytes() > 0) { Entry<?> entry = readDocumentEntry(significantSlice); values.put(entry.getKey(), entry.getValue()); }/*from w ww .jav a 2 s .c o m*/ return new MapBasedBsonDocument(values); }
From source file:com.eightkdata.mongowp.bson.netty.NettyBsonBsonBinary.java
License:Open Source License
public NettyBsonBsonBinary(byte numericSubtype, BinarySubtype subtype, @Tight @ModifiesIndexes ByteBuf data) { this.numericSubtype = numericSubtype; this.subtype = subtype; length = data.readableBytes(); byteSource = new NonIoByteSource(new ByteBufByteSource(data)); }
From source file:com.eightkdata.mongowp.bson.netty.NettyBsonString.java
License:Open Source License
private int getStringLenght(@Tight ByteBuf byteBuf) { return byteBuf.readableBytes(); }
From source file:com.eightkdata.mongowp.bson.netty.OffHeapValuesNettyBsonLowLevelReader.java
License:Open Source License
@Override BsonDocument readDocument(@Loose @ModifiesIndexes ByteBuf byteBuf) throws NettyBsonReaderException { int length = byteBuf.readInt(); int significantLenght = length - 4 - 1; ByteBuf significantSlice = byteBuf.readSlice(significantLenght); byte b = byteBuf.readByte(); assert b == 0x00; ArrayList<BsonDocument.Entry<?>> list = new ArrayList<>(); while (significantSlice.readableBytes() > 0) { Entry<?> entry = readDocumentEntry(significantSlice); list.add(entry);//from w w w . ja v a 2 s. com } return new ListBasedBsonDocument(list); }
From source file:com.eightkdata.mongowp.bson.netty.pool.ShortStringPoolPolicy.java
License:Open Source License
protected final boolean isShort(ByteBuf input) { return input.readableBytes() < sizeLimit; }