use of org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException in project flink by apache.
the class AkkaRpcActor method serializeRemoteResultAndVerifySize.
private Either<AkkaRpcSerializedValue, AkkaRpcException> serializeRemoteResultAndVerifySize(Object result, String methodName) {
try {
AkkaRpcSerializedValue serializedResult = AkkaRpcSerializedValue.valueOf(result);
long resultSize = serializedResult.getSerializedDataLength();
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));
}
}
use of org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException in project flink by apache.
the class AkkaRpcActor method handleMessage.
private void handleMessage(final Object message) {
if (state.isRunning()) {
mainThreadValidator.enterMainThread();
try {
handleRpcMessage(message);
} finally {
mainThreadValidator.exitMainThread();
}
} else {
log.info("The rpc endpoint {} has not been started yet. Discarding message {} until processing is started.", rpcEndpoint.getClass().getName(), message);
sendErrorIfSender(new AkkaRpcException(String.format("Discard message %s, because the rpc endpoint %s has not been started yet.", message, rpcEndpoint.getAddress())));
}
}
use of org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException in project flink by apache.
the class AkkaRpcActor method sendAsyncResponse.
private void sendAsyncResponse(CompletableFuture<?> asyncResponse, String methodName) {
final ActorRef sender = getSender();
Promise.DefaultPromise<Object> promise = new Promise.DefaultPromise<>();
FutureUtils.assertNoException(asyncResponse.handle((value, throwable) -> {
if (throwable != null) {
promise.failure(throwable);
} else {
if (isRemoteSender(sender)) {
Either<AkkaRpcSerializedValue, AkkaRpcException> serializedResult = serializeRemoteResultAndVerifySize(value, methodName);
if (serializedResult.isLeft()) {
promise.success(serializedResult.left());
} else {
promise.failure(serializedResult.right());
}
} else {
promise.success(new Status.Success(value));
}
}
// consume the provided throwable
return null;
}));
Patterns.pipe(promise.future(), getContext().dispatcher()).to(sender);
}
use of org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException in project flink by apache.
the class AkkaRpcActorTest method testMessageDiscarding.
/**
* Tests that the {@link AkkaRpcActor} discards messages until the corresponding {@link
* RpcEndpoint} has been started.
*/
@Test
public void testMessageDiscarding() throws Exception {
int expectedValue = 1337;
DummyRpcEndpoint rpcEndpoint = new DummyRpcEndpoint(akkaRpcService);
DummyRpcGateway rpcGateway = rpcEndpoint.getSelfGateway(DummyRpcGateway.class);
// this message should be discarded and completed with an AkkaRpcException
CompletableFuture<Integer> result = rpcGateway.foobar();
try {
result.get(timeout.getSize(), timeout.getUnit());
fail("Expected an AkkaRpcException.");
} catch (ExecutionException ee) {
// expected this exception, because the endpoint has not been started
assertTrue(ee.getCause() instanceof AkkaRpcException);
}
// set a new value which we expect to be returned
rpcEndpoint.setFoobar(expectedValue);
// start the endpoint so that it can process messages
rpcEndpoint.start();
try {
// send the rpc again
result = rpcGateway.foobar();
// now we should receive a result :-)
Integer actualValue = result.get(timeout.getSize(), timeout.getUnit());
assertThat("The new foobar value should have been returned.", actualValue, Is.is(expectedValue));
} finally {
RpcUtils.terminateRpcEndpoint(rpcEndpoint, timeout);
}
}
use of org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException in project flink by apache.
the class SupervisorActor method akkaRpcActorFailed.
private void akkaRpcActorFailed(ActorRef actorRef, Throwable cause) {
LOG.warn("AkkaRpcActor {} has failed. Shutting it down now.", actorRef.path(), cause);
for (Map.Entry<ActorRef, AkkaRpcActorRegistration> registeredAkkaRpcActor : registeredAkkaRpcActors.entrySet()) {
final ActorRef otherActorRef = registeredAkkaRpcActor.getKey();
if (otherActorRef.equals(actorRef)) {
final AkkaRpcException error = new AkkaRpcException(String.format("Stopping actor %s because it failed.", actorRef.path()), cause);
registeredAkkaRpcActor.getValue().markFailed(error);
} else {
final AkkaRpcException siblingException = new AkkaRpcException(String.format("Stopping actor %s because its sibling %s has failed.", otherActorRef.path(), actorRef.path()));
registeredAkkaRpcActor.getValue().markFailed(siblingException);
}
}
getContext().getSystem().terminate();
}
Aggregations