List of usage examples for io.netty.buffer ByteBufAllocator DEFAULT
ByteBufAllocator DEFAULT
To view the source code for io.netty.buffer ByteBufAllocator DEFAULT.
Click Source Link
From source file:io.pravega.shared.protocol.netty.AppendEncodeDecodeTest.java
License:Open Source License
@Test public void testVerySmallBlockSize() throws Exception { @Cleanup("release") ByteBuf fakeNetwork = ByteBufAllocator.DEFAULT.buffer(); byte[] content = new byte[100]; Arrays.fill(content, (byte) 1); ByteBuf buffer = Unpooled.wrappedBuffer(content); Append msg = new Append("segment", connectionId, 1, buffer, null); CommandEncoder commandEncoder = new CommandEncoder(new FixedBatchSizeTracker(3)); SetupAppend setupAppend = new SetupAppend(1, connectionId, "segment"); commandEncoder.encode(null, setupAppend, fakeNetwork); appendDecoder.processCommand(setupAppend); ArrayList<Object> received = new ArrayList<>(); commandEncoder.encode(null, msg, fakeNetwork); read(fakeNetwork, received);//from w w w. j a v a 2 s.com assertEquals(2, received.size()); Append readAppend = (Append) received.get(1); assertEquals(msg.data.readableBytes() + TYPE_PLUS_LENGTH_SIZE, readAppend.data.readableBytes()); }
From source file:io.pravega.shared.protocol.netty.AppendEncodeDecodeTest.java
License:Open Source License
private void sendAndVerifyEvents(String segment, UUID connectionId, int numEvents, int eventSize, int expectedMessages) throws Exception { @Cleanup("release") ByteBuf fakeNetwork = ByteBufAllocator.DEFAULT.buffer(); ArrayList<Object> received = setupAppend(segment, connectionId, fakeNetwork); for (int i = 0; i < numEvents; i++) { append(segment, connectionId, eventSize * (i + 1L), i, eventSize, fakeNetwork); read(fakeNetwork, received);//from w w w .ja v a 2 s.c o m } KeepAlive keepAlive = new KeepAlive(); encoder.encode(null, keepAlive, fakeNetwork); read(fakeNetwork, received); assertEquals(expectedMessages + 1, received.size()); assertEquals(received.get(received.size() - 1), keepAlive); received.remove(received.size() - 1); verify(received, numEvents, eventSize); }
From source file:io.pravega.shared.protocol.netty.AppendEncodeDecodeTest.java
License:Open Source License
private void testFlush(int size) throws Exception { @Cleanup("release") ByteBuf fakeNetwork = ByteBufAllocator.DEFAULT.buffer(); ArrayList<Object> received = setupAppend(streamName, connectionId, fakeNetwork); append(streamName, connectionId, size, 0, size, fakeNetwork); read(fakeNetwork, received);/*w w w . jav a 2s . c o m*/ KeepAlive keepAlive = new KeepAlive(); encoder.encode(null, keepAlive, fakeNetwork); read(fakeNetwork, received); assertEquals(2, received.size()); Append one = (Append) received.get(0); assertEquals(size + TYPE_PLUS_LENGTH_SIZE, one.getData().readableBytes()); KeepAlive two = (KeepAlive) received.get(1); assertEquals(keepAlive, two); }
From source file:io.pravega.shared.protocol.netty.AppendEncodeDecodeTest.java
License:Open Source License
@Test public void testAppendAtBlockBound() throws Exception { int size = appendBlockSize; @Cleanup("release") ByteBuf fakeNetwork = ByteBufAllocator.DEFAULT.buffer(); ArrayList<Object> received = setupAppend(streamName, connectionId, fakeNetwork); append(streamName, connectionId, size, 1, size, fakeNetwork); read(fakeNetwork, received);/*from ww w . jav a 2 s.c om*/ assertEquals(1, received.size()); append(streamName, connectionId, size + size / 2, 2, size / 2, fakeNetwork); read(fakeNetwork, received); assertEquals(1, received.size()); KeepAlive keepAlive = new KeepAlive(); encoder.encode(null, keepAlive, fakeNetwork); read(fakeNetwork, received); assertEquals(3, received.size()); Append one = (Append) received.get(0); Append two = (Append) received.get(1); assertEquals(size + TYPE_PLUS_LENGTH_SIZE, one.getData().readableBytes()); assertEquals(size / 2 + TYPE_PLUS_LENGTH_SIZE, two.getData().readableBytes()); KeepAlive three = (KeepAlive) received.get(2); assertEquals(keepAlive, three); }
From source file:io.servicecomb.foundation.vertx.tcp.TcpConnection.java
License:Apache License
protected void writeInContext() { CompositeByteBuf cbb = ByteBufAllocator.DEFAULT.compositeBuffer(); for (;;) {//from w ww . j a va 2s. c om ByteBuf buf = writeQueue.poll(); if (buf == null) { break; } writeQueueSize.decrementAndGet(); cbb.addComponent(true, buf); if (cbb.numComponents() == cbb.maxNumComponents()) { netSocket.write(Buffer.buffer(cbb)); cbb = ByteBufAllocator.DEFAULT.compositeBuffer(); } } if (cbb.isReadable()) { netSocket.write(Buffer.buffer(cbb)); } }
From source file:io.vertx.core.net.impl.SSLHelper.java
License:Open Source License
public SslHandler createSslHandler(VertxInternal vertx, String host, int port) { SSLEngine engine = getContext(vertx).newEngine(ByteBufAllocator.DEFAULT, host, port); return createHandler(engine, client); }
From source file:io.vertx.core.net.impl.SSLHelper.java
License:Open Source License
public SslHandler createSslHandler(VertxInternal vertx) { SSLEngine engine = getContext(vertx).newEngine(ByteBufAllocator.DEFAULT); return createHandler(engine, client); }
From source file:me.melchor9000.net.Socket.java
License:Open Source License
/** * Sends some data stored in the {@link ByteBuf} {@code data}, starting from its * current position with a size of {@code bytes}. Depending on the implementation * and its options, is possible that the data could not be sent in the moment, or * only a portion of it is sent./*from ww w . j av a 2 s . c o m*/ * @param data buffer with the data to be sent * @param bytes number of bytes to send * @return bytes sent * @throws InterruptedException If there's an interruption while sending the data */ public long send(@NotNull ByteBuf data, int bytes) throws InterruptedException { checkSocketCreated("send"); ByteBuf buff = ByteBufAllocator.DEFAULT.buffer(bytes).retain(); buff.writeBytes(data, 0, bytes); channel.writeAndFlush(buff).sync(); buff.release(); bytesWrote += bytes; return bytes; }
From source file:me.melchor9000.net.Socket.java
License:Open Source License
/** * Sends some data stored in the {@link ByteBuf} {@code data}, starting from its * current position with a size of {@code bytes}. Depending on the implementation * and its options, is possible that the data could not be sent in the moment, or * only a portion of it is sent. This is an asynchronous operation, so returns a * {@link Future} representing the task. * @param data buffer with the data to be sent * @param bytes number of bytes to send//from w w w. j a v a2 s .c o m * @return a {@link Future} representing this task */ public @NotNull Future<Void> sendAsync(ByteBuf data, final int bytes) { checkSocketCreated("sendAsync"); final ByteBuf buff = ByteBufAllocator.DEFAULT.directBuffer(bytes).retain(); buff.writeBytes(data, 0, bytes); return createFuture(channel.writeAndFlush(buff).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { bytesWrote += bytes; buff.release(); } })); }
From source file:me.melchor9000.net.TCPSocket.java
License:Open Source License
/** * Creates a new TCP Socket//from w w w . j a va 2s . c o m * @param service {@link IOService} to attach this socket */ public TCPSocket(IOService service) { super(service); bootstrap.channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast("readManager", readManager); } }); readBuffer = ByteBufAllocator.DEFAULT.directBuffer(1460, 1460 * 100).retain(); readOperations = new ConcurrentLinkedQueue<>(); readManager = new ReadManager(); }