Java Code Examples for org.apache.flink.util.SerializedValue#getByteArray()

The following examples show how to use org.apache.flink.util.SerializedValue#getByteArray() . 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: AkkaRpcActor.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private Either<SerializedValue<?>, AkkaRpcException> serializeRemoteResultAndVerifySize(Object result, String methodName) {
	try {
		SerializedValue<?> serializedResult = new SerializedValue<>(result);

		long resultSize = serializedResult.getByteArray().length;
		if (resultSize > maximumFramesize) {
			return Either.Right(new AkkaRpcException(
				"The method " + methodName + "'s result size " + resultSize
					+ " exceeds the maximum size " + maximumFramesize + " ."));
		} else {
			return Either.Left(serializedResult);
		}
	} catch (IOException e) {
		return Either.Right(new AkkaRpcException(
			"Failed to serialize the result for RPC call : " + methodName + '.', e));
	}
}
 
Example 2
Source File: BlobWriter.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Serializes the given value and offloads it to the BlobServer if its size exceeds the minimum
 * offloading size of the BlobServer.
 *
 * @param value to serialize
 * @param jobId to which the value belongs.
 * @param blobWriter to use to offload the serialized value
 * @param <T> type of the value to serialize
 * @return Either the serialized value or the stored blob key
 * @throws IOException if the data cannot be serialized
 */
static <T> Either<SerializedValue<T>, PermanentBlobKey> serializeAndTryOffload(
		T value,
		JobID jobId,
		BlobWriter blobWriter) throws IOException {
	Preconditions.checkNotNull(value);
	Preconditions.checkNotNull(jobId);
	Preconditions.checkNotNull(blobWriter);

	final SerializedValue<T> serializedValue = new SerializedValue<>(value);

	if (serializedValue.getByteArray().length < blobWriter.getMinOffloadingSize()) {
		return Either.Left(new SerializedValue<>(value));
	} else {
		try {
			final PermanentBlobKey permanentBlobKey = blobWriter.putPermanent(jobId, serializedValue.getByteArray());

			return Either.Right(permanentBlobKey);
		} catch (IOException e) {
			LOG.warn("Failed to offload value {} for job {} to BLOB store.", value, jobId, e);

			return Either.Left(serializedValue);
		}
	}
}
 
Example 3
Source File: AkkaRpcActor.java    From flink with Apache License 2.0 6 votes vote down vote up
private Either<SerializedValue<?>, AkkaRpcException> serializeRemoteResultAndVerifySize(Object result, String methodName) {
	try {
		SerializedValue<?> serializedResult = new SerializedValue<>(result);

		long resultSize = serializedResult.getByteArray().length;
		if (resultSize > maximumFramesize) {
			return Either.Right(new AkkaRpcException(
				"The method " + methodName + "'s result size " + resultSize
					+ " exceeds the maximum size " + maximumFramesize + " ."));
		} else {
			return Either.Left(serializedResult);
		}
	} catch (IOException e) {
		return Either.Right(new AkkaRpcException(
			"Failed to serialize the result for RPC call : " + methodName + '.', e));
	}
}
 
Example 4
Source File: BlobWriter.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Serializes the given value and offloads it to the BlobServer if its size exceeds the minimum
 * offloading size of the BlobServer.
 *
 * @param value to serialize
 * @param jobId to which the value belongs.
 * @param blobWriter to use to offload the serialized value
 * @param <T> type of the value to serialize
 * @return Either the serialized value or the stored blob key
 * @throws IOException if the data cannot be serialized
 */
static <T> Either<SerializedValue<T>, PermanentBlobKey> serializeAndTryOffload(
		T value,
		JobID jobId,
		BlobWriter blobWriter) throws IOException {
	Preconditions.checkNotNull(value);
	Preconditions.checkNotNull(jobId);
	Preconditions.checkNotNull(blobWriter);

	final SerializedValue<T> serializedValue = new SerializedValue<>(value);

	if (serializedValue.getByteArray().length < blobWriter.getMinOffloadingSize()) {
		return Either.Left(new SerializedValue<>(value));
	} else {
		try {
			final PermanentBlobKey permanentBlobKey = blobWriter.putPermanent(jobId, serializedValue.getByteArray());

			return Either.Right(permanentBlobKey);
		} catch (IOException e) {
			LOG.warn("Failed to offload value {} for job {} to BLOB store.", value, jobId, e);

			return Either.Left(serializedValue);
		}
	}
}
 
Example 5
Source File: AkkaRpcActor.java    From flink with Apache License 2.0 6 votes vote down vote up
private Either<SerializedValue<?>, AkkaRpcException> serializeRemoteResultAndVerifySize(Object result, String methodName) {
	try {
		SerializedValue<?> serializedResult = new SerializedValue<>(result);

		long resultSize = serializedResult.getByteArray().length;
		if (resultSize > maximumFramesize) {
			return Either.Right(new AkkaRpcException(
				"The method " + methodName + "'s result size " + resultSize
					+ " exceeds the maximum size " + maximumFramesize + " ."));
		} else {
			return Either.Left(serializedResult);
		}
	} catch (IOException e) {
		return Either.Right(new AkkaRpcException(
			"Failed to serialize the result for RPC call : " + methodName + '.', e));
	}
}
 
Example 6
Source File: BlobWriter.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Serializes the given value and offloads it to the BlobServer if its size exceeds the minimum
 * offloading size of the BlobServer.
 *
 * @param value to serialize
 * @param jobId to which the value belongs.
 * @param blobWriter to use to offload the serialized value
 * @param <T> type of the value to serialize
 * @return Either the serialized value or the stored blob key
 * @throws IOException if the data cannot be serialized
 */
static <T> Either<SerializedValue<T>, PermanentBlobKey> serializeAndTryOffload(
		T value,
		JobID jobId,
		BlobWriter blobWriter) throws IOException {
	Preconditions.checkNotNull(value);
	Preconditions.checkNotNull(jobId);
	Preconditions.checkNotNull(blobWriter);

	final SerializedValue<T> serializedValue = new SerializedValue<>(value);

	if (serializedValue.getByteArray().length < blobWriter.getMinOffloadingSize()) {
		return Either.Left(new SerializedValue<>(value));
	} else {
		try {
			final PermanentBlobKey permanentBlobKey = blobWriter.putPermanent(jobId, serializedValue.getByteArray());

			return Either.Right(permanentBlobKey);
		} catch (IOException e) {
			LOG.warn("Failed to offload value {} for job {} to BLOB store.", value, jobId, e);

			return Either.Left(serializedValue);
		}
	}
}