Java Code Examples for org.apache.flink.runtime.io.network.partition.consumer.InputChannelID#fromByteBuf()

The following examples show how to use org.apache.flink.runtime.io.network.partition.consumer.InputChannelID#fromByteBuf() . 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 6 votes vote down vote up
static ErrorResponse readFrom(ByteBuf buffer) throws Exception {
	try (ObjectInputStream ois = new ObjectInputStream(new ByteBufInputStream(buffer))) {
		Object obj = ois.readObject();

		if (!(obj instanceof Throwable)) {
			throw new ClassCastException("Read object expected to be of type Throwable, " +
					"actual type is " + obj.getClass() + ".");
		} else {
			if (buffer.readBoolean()) {
				InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
				return new ErrorResponse((Throwable) obj, receiverId);
			} else {
				return new ErrorResponse((Throwable) obj);
			}
		}
	}
}
 
Example 2
Source File: NettyMessage.java    From flink with Apache License 2.0 6 votes vote down vote up
static TaskEventRequest readFrom(ByteBuf buffer, ClassLoader classLoader) throws IOException {
	// directly deserialize fromNetty's buffer
	int length = buffer.readInt();
	ByteBuffer serializedEvent = buffer.nioBuffer(buffer.readerIndex(), length);
	// assume this event's content is read from the ByteBuf (positions are not shared!)
	buffer.readerIndex(buffer.readerIndex() + length);

	TaskEvent event =
		(TaskEvent) EventSerializer.fromSerializedEvent(serializedEvent, classLoader);

	ResultPartitionID partitionId =
		new ResultPartitionID(
			IntermediateResultPartitionID.fromByteBuf(buffer),
			ExecutionAttemptID.fromByteBuf(buffer));

	InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);

	return new TaskEventRequest(event, partitionId, receiverId);
}
 
Example 3
Source File: NettyMessage.java    From flink with Apache License 2.0 6 votes vote down vote up
static ErrorResponse readFrom(ByteBuf buffer) throws Exception {
	try (ObjectInputStream ois = new ObjectInputStream(new ByteBufInputStream(buffer))) {
		Object obj = ois.readObject();

		if (!(obj instanceof Throwable)) {
			throw new ClassCastException("Read object expected to be of type Throwable, " +
					"actual type is " + obj.getClass() + ".");
		} else {
			if (buffer.readBoolean()) {
				InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
				return new ErrorResponse((Throwable) obj, receiverId);
			} else {
				return new ErrorResponse((Throwable) obj);
			}
		}
	}
}
 
Example 4
Source File: NettyMessage.java    From flink with Apache License 2.0 6 votes vote down vote up
static TaskEventRequest readFrom(ByteBuf buffer, ClassLoader classLoader) throws IOException {
	// directly deserialize fromNetty's buffer
	int length = buffer.readInt();
	ByteBuffer serializedEvent = buffer.nioBuffer(buffer.readerIndex(), length);
	// assume this event's content is read from the ByteBuf (positions are not shared!)
	buffer.readerIndex(buffer.readerIndex() + length);

	TaskEvent event =
		(TaskEvent) EventSerializer.fromSerializedEvent(serializedEvent, classLoader);

	ResultPartitionID partitionId =
		new ResultPartitionID(
			IntermediateResultPartitionID.fromByteBuf(buffer),
			ExecutionAttemptID.fromByteBuf(buffer));

	InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);

	return new TaskEventRequest(event, partitionId, receiverId);
}
 
Example 5
Source File: NettyMessage.java    From flink with Apache License 2.0 6 votes vote down vote up
static ErrorResponse readFrom(ByteBuf buffer) throws Exception {
	try (ObjectInputStream ois = new ObjectInputStream(new ByteBufInputStream(buffer))) {
		Object obj = ois.readObject();

		if (!(obj instanceof Throwable)) {
			throw new ClassCastException("Read object expected to be of type Throwable, " +
					"actual type is " + obj.getClass() + ".");
		} else {
			if (buffer.readBoolean()) {
				InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
				return new ErrorResponse((Throwable) obj, receiverId);
			} else {
				return new ErrorResponse((Throwable) obj);
			}
		}
	}
}
 
Example 6
Source File: NettyMessage.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
static TaskEventRequest readFrom(ByteBuf buffer, ClassLoader classLoader) throws IOException {
	// directly deserialize fromNetty's buffer
	int length = buffer.readInt();
	ByteBuffer serializedEvent = buffer.nioBuffer(buffer.readerIndex(), length);
	// assume this event's content is read from the ByteBuf (positions are not shared!)
	buffer.readerIndex(buffer.readerIndex() + length);

	TaskEvent event =
		(TaskEvent) EventSerializer.fromSerializedEvent(serializedEvent, classLoader);

	ResultPartitionID partitionId =
		new ResultPartitionID(
			IntermediateResultPartitionID.fromByteBuf(buffer),
			ExecutionAttemptID.fromByteBuf(buffer));

	InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);

	return new TaskEventRequest(event, partitionId, receiverId);
}
 
Example 7
Source File: NettyMessage.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
static AddCredit readFrom(ByteBuf buffer) {
	ResultPartitionID partitionId =
		new ResultPartitionID(
			IntermediateResultPartitionID.fromByteBuf(buffer),
			ExecutionAttemptID.fromByteBuf(buffer));
	int credit = buffer.readInt();
	InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);

	return new AddCredit(partitionId, credit, receiverId);
}
 
Example 8
Source File: NettyMessage.java    From flink with Apache License 2.0 5 votes vote down vote up
static BufferResponse readFrom(ByteBuf buffer) {
	InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
	int sequenceNumber = buffer.readInt();
	int backlog = buffer.readInt();
	boolean isBuffer = buffer.readBoolean();
	int size = buffer.readInt();

	ByteBuf retainedSlice = buffer.readSlice(size).retain();
	return new BufferResponse(retainedSlice, isBuffer, sequenceNumber, receiverId, backlog);
}
 
Example 9
Source File: NettyMessage.java    From flink with Apache License 2.0 5 votes vote down vote up
static PartitionRequest readFrom(ByteBuf buffer) {
	ResultPartitionID partitionId =
		new ResultPartitionID(
			IntermediateResultPartitionID.fromByteBuf(buffer),
			ExecutionAttemptID.fromByteBuf(buffer));
	int queueIndex = buffer.readInt();
	InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
	int credit = buffer.readInt();

	return new PartitionRequest(partitionId, queueIndex, receiverId, credit);
}
 
Example 10
Source File: NettyMessage.java    From flink with Apache License 2.0 5 votes vote down vote up
static AddCredit readFrom(ByteBuf buffer) {
	ResultPartitionID partitionId =
		new ResultPartitionID(
			IntermediateResultPartitionID.fromByteBuf(buffer),
			ExecutionAttemptID.fromByteBuf(buffer));
	int credit = buffer.readInt();
	InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);

	return new AddCredit(partitionId, credit, receiverId);
}
 
Example 11
Source File: NettyMessage.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the message header part and composes a new BufferResponse with an empty data buffer. The
 * data buffer will be filled in later.
 *
 * @param messageHeader the serialized message header.
 * @param bufferAllocator the allocator for network buffer.
 * @return a BufferResponse object with the header parsed and the data buffer to fill in later. The
 *			data buffer will be null if the target channel has been released or the buffer size is 0.
 */
static BufferResponse readFrom(ByteBuf messageHeader, NetworkBufferAllocator bufferAllocator) {
	InputChannelID receiverId = InputChannelID.fromByteBuf(messageHeader);
	int sequenceNumber = messageHeader.readInt();
	int backlog = messageHeader.readInt();
	Buffer.DataType dataType = Buffer.DataType.values()[messageHeader.readByte()];
	boolean isCompressed = messageHeader.readBoolean();
	int size = messageHeader.readInt();

	Buffer dataBuffer = null;

	if (size != 0) {
		if (dataType.isBuffer()) {
			dataBuffer = bufferAllocator.allocatePooledNetworkBuffer(receiverId);
		} else {
			dataBuffer = bufferAllocator.allocateUnPooledNetworkBuffer(size, dataType);
		}
	}

	if (dataBuffer != null) {
		dataBuffer.setCompressed(isCompressed);
	}

	return new BufferResponse(
		dataBuffer,
		dataType,
		isCompressed,
		sequenceNumber,
		receiverId,
		backlog,
		size);
}
 
Example 12
Source File: NettyMessage.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
static PartitionRequest readFrom(ByteBuf buffer) {
	ResultPartitionID partitionId =
		new ResultPartitionID(
			IntermediateResultPartitionID.fromByteBuf(buffer),
			ExecutionAttemptID.fromByteBuf(buffer));
	int queueIndex = buffer.readInt();
	InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
	int credit = buffer.readInt();

	return new PartitionRequest(partitionId, queueIndex, receiverId, credit);
}
 
Example 13
Source File: NettyMessage.java    From flink with Apache License 2.0 5 votes vote down vote up
static PartitionRequest readFrom(ByteBuf buffer) {
	ResultPartitionID partitionId =
		new ResultPartitionID(
			IntermediateResultPartitionID.fromByteBuf(buffer),
			ExecutionAttemptID.fromByteBuf(buffer));
	int queueIndex = buffer.readInt();
	InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
	int credit = buffer.readInt();

	return new PartitionRequest(partitionId, queueIndex, receiverId, credit);
}
 
Example 14
Source File: NettyMessage.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
static BufferResponse readFrom(ByteBuf buffer) {
	InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);
	int sequenceNumber = buffer.readInt();
	int backlog = buffer.readInt();
	boolean isBuffer = buffer.readBoolean();
	int size = buffer.readInt();

	ByteBuf retainedSlice = buffer.readSlice(size).retain();
	return new BufferResponse(retainedSlice, isBuffer, sequenceNumber, receiverId, backlog);
}
 
Example 15
Source File: NettyMessage.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
static CancelPartitionRequest readFrom(ByteBuf buffer) throws Exception {
	return new CancelPartitionRequest(InputChannelID.fromByteBuf(buffer));
}
 
Example 16
Source File: NettyMessage.java    From flink with Apache License 2.0 4 votes vote down vote up
static CancelPartitionRequest readFrom(ByteBuf buffer) throws Exception {
	return new CancelPartitionRequest(InputChannelID.fromByteBuf(buffer));
}
 
Example 17
Source File: NettyMessage.java    From flink with Apache License 2.0 4 votes vote down vote up
static CancelPartitionRequest readFrom(ByteBuf buffer) throws Exception {
	return new CancelPartitionRequest(InputChannelID.fromByteBuf(buffer));
}
 
Example 18
Source File: NettyMessage.java    From flink with Apache License 2.0 4 votes vote down vote up
static AddCredit readFrom(ByteBuf buffer) {
	int credit = buffer.readInt();
	InputChannelID receiverId = InputChannelID.fromByteBuf(buffer);

	return new AddCredit(credit, receiverId);
}
 
Example 19
Source File: NettyMessage.java    From flink with Apache License 2.0 4 votes vote down vote up
static ResumeConsumption readFrom(ByteBuf buffer) {
	return new ResumeConsumption(InputChannelID.fromByteBuf(buffer));
}