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

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#writeLong() . 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: AbstractByteBufTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void comparableInterfaceNotViolated() {
    assumeFalse(buffer.isReadOnly());
    buffer.writerIndex(buffer.readerIndex());
    assumeTrue(buffer.writableBytes() >= 4);

    buffer.writeLong(0);
    ByteBuf buffer2 = newBuffer(CAPACITY);
    assumeFalse(buffer2.isReadOnly());
    buffer2.writerIndex(buffer2.readerIndex());
    // Write an unsigned integer that will cause buffer.getUnsignedInt() - buffer2.getUnsignedInt() to underflow the
    // int type and wrap around on the negative side.
    buffer2.writeLong(0xF0000000L);
    assertTrue(buffer.compareTo(buffer2) < 0);
    assertTrue(buffer2.compareTo(buffer) > 0);
    buffer2.release();
}
 
Example 2
Source File: MessageSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for serializing the messages.
 *
 * @param alloc			The {@link ByteBufAllocator} used to allocate the buffer to serialize the message into.
 * @param requestId		The id of the request to which the message refers to.
 * @param messageType	The {@link MessageType type of the message}.
 * @param payload		The serialized version of the message.
 * @return A {@link ByteBuf} containing the serialized message.
 */
private static ByteBuf writePayload(
		final ByteBufAllocator alloc,
		final long requestId,
		final MessageType messageType,
		final byte[] payload) {

	final int frameLength = HEADER_LENGTH + REQUEST_ID_SIZE + payload.length;
	final ByteBuf buf = alloc.ioBuffer(frameLength + Integer.BYTES);

	buf.writeInt(frameLength);
	writeHeader(buf, messageType);
	buf.writeLong(requestId);
	buf.writeBytes(payload);
	return buf;
}
 
Example 3
Source File: MessageSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Serializes the exception containing the failure message sent to the
 * {@link org.apache.flink.queryablestate.network.Client} in case of
 * protocol related errors.
 *
 * @param alloc			The {@link ByteBufAllocator} used to allocate the buffer to serialize the message into.
 * @param requestId		The id of the request to which the message refers to.
 * @param cause			The exception thrown at the server.
 * @return A {@link ByteBuf} containing the serialized message.
 */
public static ByteBuf serializeRequestFailure(
		final ByteBufAllocator alloc,
		final long requestId,
		final Throwable cause) throws IOException {

	final ByteBuf buf = alloc.ioBuffer();

	// Frame length is set at the end
	buf.writeInt(0);
	writeHeader(buf, MessageType.REQUEST_FAILURE);
	buf.writeLong(requestId);

	try (ByteBufOutputStream bbos = new ByteBufOutputStream(buf);
			ObjectOutput out = new ObjectOutputStream(bbos)) {
		out.writeObject(cause);
	}

	// Set frame length
	int frameLength = buf.readableBytes() - Integer.BYTES;
	buf.setInt(0, frameLength);
	return buf;
}
 
Example 4
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void comparableInterfaceNotViolated() {
    assumeFalse(buffer.isReadOnly());
    buffer.writerIndex(buffer.readerIndex());
    assumeTrue(buffer.writableBytes() >= 4);

    buffer.writeLong(0);
    ByteBuf buffer2 = newBuffer(CAPACITY);
    assumeFalse(buffer2.isReadOnly());
    buffer2.writerIndex(buffer2.readerIndex());
    // Write an unsigned integer that will cause buffer.getUnsignedInt() - buffer2.getUnsignedInt() to underflow the
    // int type and wrap around on the negative side.
    buffer2.writeLong(0xF0000000L);
    assertTrue(buffer.compareTo(buffer2) < 0);
    assertTrue(buffer2.compareTo(buffer) > 0);
    buffer2.release();
}
 
Example 5
Source File: MessageSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for serializing the messages.
 *
 * @param alloc			The {@link ByteBufAllocator} used to allocate the buffer to serialize the message into.
 * @param requestId		The id of the request to which the message refers to.
 * @param messageType	The {@link MessageType type of the message}.
 * @param payload		The serialized version of the message.
 * @return A {@link ByteBuf} containing the serialized message.
 */
private static ByteBuf writePayload(
		final ByteBufAllocator alloc,
		final long requestId,
		final MessageType messageType,
		final byte[] payload) {

	final int frameLength = HEADER_LENGTH + REQUEST_ID_SIZE + payload.length;
	final ByteBuf buf = alloc.ioBuffer(frameLength + Integer.BYTES);

	buf.writeInt(frameLength);
	writeHeader(buf, messageType);
	buf.writeLong(requestId);
	buf.writeBytes(payload);
	return buf;
}
 
Example 6
Source File: MessageSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Serializes the exception containing the failure message sent to the
 * {@link org.apache.flink.queryablestate.network.Client} in case of
 * protocol related errors.
 *
 * @param alloc			The {@link ByteBufAllocator} used to allocate the buffer to serialize the message into.
 * @param requestId		The id of the request to which the message refers to.
 * @param cause			The exception thrown at the server.
 * @return A {@link ByteBuf} containing the serialized message.
 */
public static ByteBuf serializeRequestFailure(
		final ByteBufAllocator alloc,
		final long requestId,
		final Throwable cause) throws IOException {

	final ByteBuf buf = alloc.ioBuffer();

	// Frame length is set at the end
	buf.writeInt(0);
	writeHeader(buf, MessageType.REQUEST_FAILURE);
	buf.writeLong(requestId);

	try (ByteBufOutputStream bbos = new ByteBufOutputStream(buf);
			ObjectOutput out = new ObjectOutputStream(bbos)) {
		out.writeObject(cause);
	}

	// Set frame length
	int frameLength = buf.readableBytes() - Integer.BYTES;
	buf.setInt(0, frameLength);
	return buf;
}
 
Example 7
Source File: MessageSerializer.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for serializing the messages.
 *
 * @param alloc			The {@link ByteBufAllocator} used to allocate the buffer to serialize the message into.
 * @param requestId		The id of the request to which the message refers to.
 * @param messageType	The {@link MessageType type of the message}.
 * @param payload		The serialized version of the message.
 * @return A {@link ByteBuf} containing the serialized message.
 */
private static ByteBuf writePayload(
		final ByteBufAllocator alloc,
		final long requestId,
		final MessageType messageType,
		final byte[] payload) {

	final int frameLength = HEADER_LENGTH + REQUEST_ID_SIZE + payload.length;
	final ByteBuf buf = alloc.ioBuffer(frameLength + Integer.BYTES);

	buf.writeInt(frameLength);
	writeHeader(buf, messageType);
	buf.writeLong(requestId);
	buf.writeBytes(payload);
	return buf;
}
 
Example 8
Source File: MessageSerializer.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Serializes the exception containing the failure message sent to the
 * {@link org.apache.flink.queryablestate.network.Client} in case of
 * protocol related errors.
 *
 * @param alloc			The {@link ByteBufAllocator} used to allocate the buffer to serialize the message into.
 * @param requestId		The id of the request to which the message refers to.
 * @param cause			The exception thrown at the server.
 * @return A {@link ByteBuf} containing the serialized message.
 */
public static ByteBuf serializeRequestFailure(
		final ByteBufAllocator alloc,
		final long requestId,
		final Throwable cause) throws IOException {

	final ByteBuf buf = alloc.ioBuffer();

	// Frame length is set at the end
	buf.writeInt(0);
	writeHeader(buf, MessageType.REQUEST_FAILURE);
	buf.writeLong(requestId);

	try (ByteBufOutputStream bbos = new ByteBufOutputStream(buf);
			ObjectOutput out = new ObjectOutputStream(bbos)) {
		out.writeObject(cause);
	}

	// Set frame length
	int frameLength = buf.readableBytes() - Integer.BYTES;
	buf.setInt(0, frameLength);
	return buf;
}
 
Example 9
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void comparableInterfaceNotViolated() {
    assumeFalse(buffer.isReadOnly());
    buffer.writerIndex(buffer.readerIndex());
    assumeTrue(buffer.writableBytes() >= 4);

    buffer.writeLong(0);
    ByteBuf buffer2 = newBuffer(CAPACITY);
    assumeFalse(buffer2.isReadOnly());
    buffer2.writerIndex(buffer2.readerIndex());
    // Write an unsigned integer that will cause buffer.getUnsignedInt() - buffer2.getUnsignedInt() to underflow the
    // int type and wrap around on the negative side.
    buffer2.writeLong(0xF0000000L);
    assertTrue(buffer.compareTo(buffer2) < 0);
    assertTrue(buffer2.compareTo(buffer) > 0);
    buffer2.release();
}
 
Example 10
Source File: IntermediateResultPartitionID.java    From flink with Apache License 2.0 4 votes vote down vote up
public void writeTo(ByteBuf buf) {
	buf.writeLong(this.lowerPart);
	buf.writeLong(this.upperPart);
}
 
Example 11
Source File: ExecutionAttemptID.java    From flink with Apache License 2.0 4 votes vote down vote up
public void writeTo(ByteBuf buf) {
	buf.writeLong(this.lowerPart);
	buf.writeLong(this.upperPart);
}
 
Example 12
Source File: InputChannelID.java    From flink with Apache License 2.0 4 votes vote down vote up
public void writeTo(ByteBuf buf) {
	buf.writeLong(this.lowerPart);
	buf.writeLong(this.upperPart);
}
 
Example 13
Source File: IntermediateResultPartitionID.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public void writeTo(ByteBuf buf) {
	buf.writeLong(this.lowerPart);
	buf.writeLong(this.upperPart);
}
 
Example 14
Source File: IntermediateDataSetID.java    From flink with Apache License 2.0 4 votes vote down vote up
public void writeTo(ByteBuf buf) {
	buf.writeLong(lowerPart);
	buf.writeLong(upperPart);
}
 
Example 15
Source File: ExecutionAttemptID.java    From flink with Apache License 2.0 4 votes vote down vote up
public void writeTo(ByteBuf buf) {
	buf.writeLong(this.lowerPart);
	buf.writeLong(this.upperPart);
}
 
Example 16
Source File: InputChannelID.java    From flink with Apache License 2.0 4 votes vote down vote up
public void writeTo(ByteBuf buf) {
	buf.writeLong(this.lowerPart);
	buf.writeLong(this.upperPart);
}
 
Example 17
Source File: InputChannelID.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public void writeTo(ByteBuf buf) {
	buf.writeLong(this.lowerPart);
	buf.writeLong(this.upperPart);
}
 
Example 18
Source File: ExecutionAttemptID.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public void writeTo(ByteBuf buf) {
	buf.writeLong(this.lowerPart);
	buf.writeLong(this.upperPart);
}