@Override protected void encode(ChannelHandlerContext channelHandlerContext, ClusterMetrics clusterStatus, List<Object> objects) { objects.add(new DatagramPacket(Unpooled.wrappedBuffer( ClusterMetricsBuilder.toClusterStatus(clusterStatus).toByteArray()), isa)); } }
NettyRpcConnection(NettyRpcClient rpcClient, ConnectionId remoteId) throws IOException { super(rpcClient.conf, AbstractRpcClient.WHEEL_TIMER, remoteId, rpcClient.clusterId, rpcClient.userProvider.isHBaseSecurityEnabled(), rpcClient.codec, rpcClient.compressor); this.rpcClient = rpcClient; byte[] connectionHeaderPreamble = getConnectionHeaderPreamble(); this.connectionHeaderPreamble = Unpooled.directBuffer(connectionHeaderPreamble.length).writeBytes(connectionHeaderPreamble); ConnectionHeader header = getConnectionHeader(); this.connectionHeaderWithLength = Unpooled.directBuffer(4 + header.getSerializedSize()); this.connectionHeaderWithLength.writeInt(header.getSerializedSize()); header.writeTo(new ByteBufOutputStream(this.connectionHeaderWithLength)); }
return EMPTY_BUFFER; } else { return copiedBuffer(arrays[0]); return wrappedBuffer(mergedArray);
stringToSimpleStrings = new HashMap<String, SimpleStringRedisMessage>(DEFAULT_SIMPLE_STRINGS.length, 1.0f); for (String message : DEFAULT_SIMPLE_STRINGS) { ByteBuf key = Unpooled.unmodifiableBuffer( Unpooled.unreleasableBuffer(Unpooled.wrappedBuffer(message.getBytes(CharsetUtil.UTF_8)))); SimpleStringRedisMessage cached = new SimpleStringRedisMessage(message); byteBufToSimpleStrings.put(key, cached); stringToErrors = new HashMap<String, ErrorRedisMessage>(DEFAULT_ERRORS.length, 1.0f); for (String message : DEFAULT_ERRORS) { ByteBuf key = Unpooled.unmodifiableBuffer( Unpooled.unreleasableBuffer(Unpooled.wrappedBuffer(message.getBytes(CharsetUtil.UTF_8)))); ErrorRedisMessage cached = new ErrorRedisMessage(message); byteBufToErrors.put(key, cached); for (long value = MIN_CACHED_INTEGER_NUMBER; value < MAX_CACHED_INTEGER_NUMBER; value++) { byte[] keyBytes = RedisCodecUtil.longToAsciiBytes(value); ByteBuf keyByteBuf = Unpooled.unmodifiableBuffer(Unpooled.unreleasableBuffer( Unpooled.wrappedBuffer(keyBytes))); IntegerRedisMessage cached = new IntegerRedisMessage(value); byteBufToIntegers.put(keyByteBuf, cached);
/** * Creates a new empty text frame. */ public TextWebSocketFrame() { super(Unpooled.buffer(0)); }
/** * Creates a new big-endian buffer whose content is the specified * {@code array} encoded in the specified {@code charset}. * The new buffer's {@code readerIndex} and {@code writerIndex} are * {@code 0} and the length of the encoded string respectively. */ public static ByteBuf copiedBuffer(char[] array, Charset charset) { if (array == null) { throw new NullPointerException("array"); } return copiedBuffer(array, 0, array.length, charset); }
@SuppressWarnings("deprecation") @Override public ByteBuf asReadOnly() { return Unpooled.unmodifiableBuffer(this); }
/** * Returns a new big-endian composite buffer with no components. */ public static CompositeByteBuf compositeBuffer() { return compositeBuffer(AbstractByteBufAllocator.DEFAULT_MAX_COMPONENTS); }
return EMPTY_BUFFER; case 1: return copiedBuffer(buffers[0]); return wrappedBuffer(mergedArray).order(order);
/** * Creates a new empty close frame. */ public CloseWebSocketFrame() { super(Unpooled.buffer(0)); }
private static ByteBuf fromText(String text) { if (text == null || text.isEmpty()) { return Unpooled.EMPTY_BUFFER; } else { return Unpooled.copiedBuffer(text, CharsetUtil.UTF_8); } }
@Override public ByteBuf asReadOnly() { return Unpooled.unmodifiableBuffer(this); }
public ByteBuf toByteBuf() { return Unpooled.compositeBuffer().addComponents(value).writerIndex(size()).readerIndex(0); }
@Override protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { byte[] bytes = new byte[msg.readableBytes()]; msg.readBytes(bytes); ctx.fireChannelRead(Unpooled.wrappedBuffer(saslClient.unwrap(bytes, 0, bytes.length))); } }
return EMPTY_BUFFER; case 1: return copiedBuffer(buffers[0]); return wrappedBuffer(mergedArray).order(order);
NettyRpcConnection(NettyRpcClient rpcClient, ConnectionId remoteId) throws IOException { super(rpcClient.conf, AbstractRpcClient.WHEEL_TIMER, remoteId, rpcClient.clusterId, rpcClient.userProvider.isHBaseSecurityEnabled(), rpcClient.codec, rpcClient.compressor); this.rpcClient = rpcClient; byte[] connectionHeaderPreamble = getConnectionHeaderPreamble(); this.connectionHeaderPreamble = Unpooled.directBuffer(connectionHeaderPreamble.length).writeBytes(connectionHeaderPreamble); ConnectionHeader header = getConnectionHeader(); this.connectionHeaderWithLength = Unpooled.directBuffer(4 + header.getSerializedSize()); this.connectionHeaderWithLength.writeInt(header.getSerializedSize()); header.writeTo(new ByteBufOutputStream(this.connectionHeaderWithLength)); }
/** * Create a new {@link DefaultFullBinaryMemcacheResponse} with the header, key and extras. * * @param key the key to use. * @param extras the extras to use. */ public DefaultFullBinaryMemcacheResponse(ByteBuf key, ByteBuf extras) { this(key, extras, Unpooled.buffer(0)); }
/** * Sets the string for this frame * * @param text * text to store */ private static ByteBuf fromText(String text) { if (text == null || text.isEmpty()) { return Unpooled.EMPTY_BUFFER; } else { return Unpooled.copiedBuffer(text, CharsetUtil.UTF_8); } }
@Override public ByteBuf asReadOnly() { return Unpooled.unmodifiableBuffer(this); }
@Override public void addContent(ByteBuf buffer, boolean last) throws IOException { if (buffer != null) { long localsize = buffer.readableBytes(); checkSize(size + localsize); if (definedSize > 0 && definedSize < size + localsize) { throw new IOException("Out of size: " + (size + localsize) + " > " + definedSize); } size += localsize; if (byteBuf == null) { byteBuf = buffer; } else if (byteBuf instanceof CompositeByteBuf) { CompositeByteBuf cbb = (CompositeByteBuf) byteBuf; cbb.addComponent(true, buffer); } else { CompositeByteBuf cbb = compositeBuffer(Integer.MAX_VALUE); cbb.addComponents(true, byteBuf, buffer); byteBuf = cbb; } } if (last) { setCompleted(); } else { if (buffer == null) { throw new NullPointerException("buffer"); } } }