org.apache.flink.runtime.rpc.messages.RpcInvocation Java Examples

The following examples show how to use org.apache.flink.runtime.rpc.messages.RpcInvocation. 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
protected void handleRpcMessage(Object message) {
	if (message instanceof RunAsync) {
		handleRunAsync((RunAsync) message);
	} else if (message instanceof CallAsync) {
		handleCallAsync((CallAsync) message);
	} else if (message instanceof RpcInvocation) {
		handleRpcInvocation((RpcInvocation) message);
	} else {
		log.warn(
			"Received message of unknown type {} with value {}. Dropping this message!",
			message.getClass().getName(),
			message);

		sendErrorIfSender(new AkkaUnknownMessageException("Received unknown message " + message +
			" of type " + message.getClass().getSimpleName() + '.'));
	}
}
 
Example #2
Source File: AkkaRpcActor.java    From flink with Apache License 2.0 6 votes vote down vote up
protected void handleRpcMessage(Object message) {
	if (message instanceof RunAsync) {
		handleRunAsync((RunAsync) message);
	} else if (message instanceof CallAsync) {
		handleCallAsync((CallAsync) message);
	} else if (message instanceof RpcInvocation) {
		handleRpcInvocation((RpcInvocation) message);
	} else {
		log.warn(
			"Received message of unknown type {} with value {}. Dropping this message!",
			message.getClass().getName(),
			message);

		sendErrorIfSender(new AkkaUnknownMessageException("Received unknown message " + message +
			" of type " + message.getClass().getSimpleName() + '.'));
	}
}
 
Example #3
Source File: AkkaRpcActor.java    From flink with Apache License 2.0 6 votes vote down vote up
protected void handleRpcMessage(Object message) {
	if (message instanceof RunAsync) {
		handleRunAsync((RunAsync) message);
	} else if (message instanceof CallAsync) {
		handleCallAsync((CallAsync) message);
	} else if (message instanceof RpcInvocation) {
		handleRpcInvocation((RpcInvocation) message);
	} else {
		log.warn(
			"Received message of unknown type {} with value {}. Dropping this message!",
			message.getClass().getName(),
			message);

		sendErrorIfSender(new AkkaUnknownMessageException("Received unknown message " + message +
			" of type " + message.getClass().getSimpleName() + '.'));
	}
}
 
Example #4
Source File: AkkaInvocationHandler.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Invokes a RPC method by sending the RPC invocation details to the rpc endpoint.
 *
 * @param method to call
 * @param args of the method call
 * @return result of the RPC
 * @throws Exception if the RPC invocation fails
 */
private Object invokeRpc(Method method, Object[] args) throws Exception {
	String methodName = method.getName();
	Class<?>[] parameterTypes = method.getParameterTypes();
	Annotation[][] parameterAnnotations = method.getParameterAnnotations();
	Time futureTimeout = extractRpcTimeout(parameterAnnotations, args, timeout);

	final RpcInvocation rpcInvocation = createRpcInvocationMessage(methodName, parameterTypes, args);

	Class<?> returnType = method.getReturnType();

	final Object result;

	if (Objects.equals(returnType, Void.TYPE)) {
		tell(rpcInvocation);

		result = null;
	} else {
		// execute an asynchronous call
		CompletableFuture<?> resultFuture = ask(rpcInvocation, futureTimeout);

		CompletableFuture<?> completableFuture = resultFuture.thenApply((Object o) -> {
			if (o instanceof SerializedValue) {
				try {
					return  ((SerializedValue<?>) o).deserializeValue(getClass().getClassLoader());
				} catch (IOException | ClassNotFoundException e) {
					throw new CompletionException(
						new RpcException("Could not deserialize the serialized payload of RPC method : "
							+ methodName, e));
				}
			} else {
				return o;
			}
		});

		if (Objects.equals(returnType, CompletableFuture.class)) {
			result = completableFuture;
		} else {
			try {
				result = completableFuture.get(futureTimeout.getSize(), futureTimeout.getUnit());
			} catch (ExecutionException ee) {
				throw new RpcException("Failure while obtaining synchronous RPC result.", ExceptionUtils.stripExecutionException(ee));
			}
		}
	}

	return result;
}
 
Example #5
Source File: AkkaInvocationHandler.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Invokes a RPC method by sending the RPC invocation details to the rpc endpoint.
 *
 * @param method to call
 * @param args of the method call
 * @return result of the RPC
 * @throws Exception if the RPC invocation fails
 */
private Object invokeRpc(Method method, Object[] args) throws Exception {
	String methodName = method.getName();
	Class<?>[] parameterTypes = method.getParameterTypes();
	Annotation[][] parameterAnnotations = method.getParameterAnnotations();
	Time futureTimeout = extractRpcTimeout(parameterAnnotations, args, timeout);

	final RpcInvocation rpcInvocation = createRpcInvocationMessage(methodName, parameterTypes, args);

	Class<?> returnType = method.getReturnType();

	final Object result;

	if (Objects.equals(returnType, Void.TYPE)) {
		tell(rpcInvocation);

		result = null;
	} else {
		// execute an asynchronous call
		CompletableFuture<?> resultFuture = ask(rpcInvocation, futureTimeout);

		CompletableFuture<?> completableFuture = resultFuture.thenApply((Object o) -> {
			if (o instanceof SerializedValue) {
				try {
					return  ((SerializedValue<?>) o).deserializeValue(getClass().getClassLoader());
				} catch (IOException | ClassNotFoundException e) {
					throw new CompletionException(
						new RpcException("Could not deserialize the serialized payload of RPC method : "
							+ methodName, e));
				}
			} else {
				return o;
			}
		});

		if (Objects.equals(returnType, CompletableFuture.class)) {
			result = completableFuture;
		} else {
			try {
				result = completableFuture.get(futureTimeout.getSize(), futureTimeout.getUnit());
			} catch (ExecutionException ee) {
				throw new RpcException("Failure while obtaining synchronous RPC result.", ExceptionUtils.stripExecutionException(ee));
			}
		}
	}

	return result;
}
 
Example #6
Source File: AkkaInvocationHandler.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Invokes a RPC method by sending the RPC invocation details to the rpc endpoint.
 *
 * @param method to call
 * @param args of the method call
 * @return result of the RPC
 * @throws Exception if the RPC invocation fails
 */
private Object invokeRpc(Method method, Object[] args) throws Exception {
	String methodName = method.getName();
	Class<?>[] parameterTypes = method.getParameterTypes();
	Annotation[][] parameterAnnotations = method.getParameterAnnotations();
	Time futureTimeout = extractRpcTimeout(parameterAnnotations, args, timeout);

	final RpcInvocation rpcInvocation = createRpcInvocationMessage(methodName, parameterTypes, args);

	Class<?> returnType = method.getReturnType();

	final Object result;

	if (Objects.equals(returnType, Void.TYPE)) {
		tell(rpcInvocation);

		result = null;
	} else {
		// Capture the call stack. It is significantly faster to do that via an exception than
		// via Thread.getStackTrace(), because exceptions lazily initialize the stack trace, initially only
		// capture a lightweight native pointer, and convert that into the stack trace lazily when needed.
		final Throwable callStackCapture = captureAskCallStack ? new Throwable() : null;

		// execute an asynchronous call
		final CompletableFuture<?> resultFuture = ask(rpcInvocation, futureTimeout);

		final CompletableFuture<Object> completableFuture = new CompletableFuture<>();
		resultFuture.whenComplete((resultValue, failure) -> {
			if (failure != null) {
				completableFuture.completeExceptionally(resolveTimeoutException(failure, callStackCapture, method));
			} else {
				completableFuture.complete(deserializeValueIfNeeded(resultValue, method));
			}
		});

		if (Objects.equals(returnType, CompletableFuture.class)) {
			result = completableFuture;
		} else {
			try {
				result = completableFuture.get(futureTimeout.getSize(), futureTimeout.getUnit());
			} catch (ExecutionException ee) {
				throw new RpcException("Failure while obtaining synchronous RPC result.", ExceptionUtils.stripExecutionException(ee));
			}
		}
	}

	return result;
}