Java Code Examples for org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#writeBoolean()

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#writeBoolean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NettyMessage.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
ByteBuf write(ByteBufAllocator allocator) throws IOException {
	// receiver ID (16), sequence number (4), backlog (4), isBuffer (1), buffer size (4)
	final int messageHeaderLength = 16 + 4 + 4 + 1 + 4;

	ByteBuf headerBuf = null;
	try {
		if (buffer instanceof Buffer) {
			// in order to forward the buffer to netty, it needs an allocator set
			((Buffer) buffer).setAllocator(allocator);
		}

		// only allocate header buffer - we will combine it with the data buffer below
		headerBuf = allocateBuffer(allocator, ID, messageHeaderLength, buffer.readableBytes(), false);

		receiverId.writeTo(headerBuf);
		headerBuf.writeInt(sequenceNumber);
		headerBuf.writeInt(backlog);
		headerBuf.writeBoolean(isBuffer);
		headerBuf.writeInt(buffer.readableBytes());

		CompositeByteBuf composityBuf = allocator.compositeDirectBuffer();
		composityBuf.addComponent(headerBuf);
		composityBuf.addComponent(buffer);
		// update writer index since we have data written to the components:
		composityBuf.writerIndex(headerBuf.writerIndex() + buffer.writerIndex());
		return composityBuf;
	}
	catch (Throwable t) {
		if (headerBuf != null) {
			headerBuf.release();
		}
		buffer.release();

		ExceptionUtils.rethrowIOException(t);
		return null; // silence the compiler
	}
}
 
Example 2
Source File: NettyMessage.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
ByteBuf write(ByteBufAllocator allocator) throws IOException {
	final ByteBuf result = allocateBuffer(allocator, ID);

	try (ObjectOutputStream oos = new ObjectOutputStream(new ByteBufOutputStream(result))) {
		oos.writeObject(cause);

		if (receiverId != null) {
			result.writeBoolean(true);
			receiverId.writeTo(result);
		} else {
			result.writeBoolean(false);
		}

		// Update frame length...
		result.setInt(0, result.readableBytes());
		return result;
	}
	catch (Throwable t) {
		result.release();

		if (t instanceof IOException) {
			throw (IOException) t;
		} else {
			throw new IOException(t);
		}
	}
}
 
Example 3
Source File: NettyMessage.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
ByteBuf write(ByteBufAllocator allocator) throws IOException {
	// receiver ID (16), sequence number (4), backlog (4), isBuffer (1), buffer size (4)
	final int messageHeaderLength = 16 + 4 + 4 + 1 + 4;

	ByteBuf headerBuf = null;
	try {
		if (buffer instanceof Buffer) {
			// in order to forward the buffer to netty, it needs an allocator set
			((Buffer) buffer).setAllocator(allocator);
		}

		// only allocate header buffer - we will combine it with the data buffer below
		headerBuf = allocateBuffer(allocator, ID, messageHeaderLength, buffer.readableBytes(), false);

		receiverId.writeTo(headerBuf);
		headerBuf.writeInt(sequenceNumber);
		headerBuf.writeInt(backlog);
		headerBuf.writeBoolean(isBuffer);
		headerBuf.writeInt(buffer.readableBytes());

		CompositeByteBuf composityBuf = allocator.compositeDirectBuffer();
		composityBuf.addComponent(headerBuf);
		composityBuf.addComponent(buffer);
		// update writer index since we have data written to the components:
		composityBuf.writerIndex(headerBuf.writerIndex() + buffer.writerIndex());
		return composityBuf;
	}
	catch (Throwable t) {
		if (headerBuf != null) {
			headerBuf.release();
		}
		buffer.release();

		ExceptionUtils.rethrowIOException(t);
		return null; // silence the compiler
	}
}
 
Example 4
Source File: NettyMessage.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
ByteBuf write(ByteBufAllocator allocator) throws IOException {
	final ByteBuf result = allocateBuffer(allocator, ID);

	try (ObjectOutputStream oos = new ObjectOutputStream(new ByteBufOutputStream(result))) {
		oos.writeObject(cause);

		if (receiverId != null) {
			result.writeBoolean(true);
			receiverId.writeTo(result);
		} else {
			result.writeBoolean(false);
		}

		// Update frame length...
		result.setInt(0, result.readableBytes());
		return result;
	}
	catch (Throwable t) {
		result.release();

		if (t instanceof IOException) {
			throw (IOException) t;
		} else {
			throw new IOException(t);
		}
	}
}
 
Example 5
Source File: NettyMessage.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
ByteBuf write(ByteBufAllocator allocator) throws IOException {
	ByteBuf headerBuf = null;
	try {
		// in order to forward the buffer to netty, it needs an allocator set
		buffer.setAllocator(allocator);

		// only allocate header buffer - we will combine it with the data buffer below
		headerBuf = allocateBuffer(allocator, ID, MESSAGE_HEADER_LENGTH, bufferSize, false);

		receiverId.writeTo(headerBuf);
		headerBuf.writeInt(sequenceNumber);
		headerBuf.writeInt(backlog);
		headerBuf.writeByte(dataType.ordinal());
		headerBuf.writeBoolean(isCompressed);
		headerBuf.writeInt(buffer.readableBytes());

		CompositeByteBuf composityBuf = allocator.compositeDirectBuffer();
		composityBuf.addComponent(headerBuf);
		composityBuf.addComponent(buffer.asByteBuf());
		// update writer index since we have data written to the components:
		composityBuf.writerIndex(headerBuf.writerIndex() + buffer.asByteBuf().writerIndex());
		return composityBuf;
	}
	catch (Throwable t) {
		if (headerBuf != null) {
			headerBuf.release();
		}
		buffer.recycleBuffer();

		ExceptionUtils.rethrowIOException(t);
		return null; // silence the compiler
	}
}
 
Example 6
Source File: NettyMessage.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
ByteBuf write(ByteBufAllocator allocator) throws IOException {
	final ByteBuf result = allocateBuffer(allocator, ID);

	try (ObjectOutputStream oos = new ObjectOutputStream(new ByteBufOutputStream(result))) {
		oos.writeObject(cause);

		if (receiverId != null) {
			result.writeBoolean(true);
			receiverId.writeTo(result);
		} else {
			result.writeBoolean(false);
		}

		// Update frame length...
		result.setInt(0, result.readableBytes());
		return result;
	}
	catch (Throwable t) {
		result.release();

		if (t instanceof IOException) {
			throw (IOException) t;
		} else {
			throw new IOException(t);
		}
	}
}