use of org.apache.flink.runtime.rpc.messages.RemoteHandshakeMessage in project flink by apache.
the class AkkaRpcService method connectInternal.
private <C extends RpcGateway> CompletableFuture<C> connectInternal(final String address, final Class<C> clazz, Function<ActorRef, InvocationHandler> invocationHandlerFactory) {
checkState(!stopped, "RpcService is stopped");
LOG.debug("Try to connect to remote RPC endpoint with address {}. Returning a {} gateway.", address, clazz.getName());
final CompletableFuture<ActorRef> actorRefFuture = resolveActorAddress(address);
final CompletableFuture<HandshakeSuccessMessage> handshakeFuture = actorRefFuture.thenCompose((ActorRef actorRef) -> AkkaFutureUtils.toJava(Patterns.ask(actorRef, new RemoteHandshakeMessage(clazz, getVersion()), configuration.getTimeout().toMilliseconds()).<HandshakeSuccessMessage>mapTo(ClassTag$.MODULE$.<HandshakeSuccessMessage>apply(HandshakeSuccessMessage.class))));
final CompletableFuture<C> gatewayFuture = actorRefFuture.thenCombineAsync(handshakeFuture, (ActorRef actorRef, HandshakeSuccessMessage ignored) -> {
InvocationHandler invocationHandler = invocationHandlerFactory.apply(actorRef);
// Rather than using the System ClassLoader directly, we derive the
// ClassLoader from this class.
// That works better in cases where Flink runs embedded and
// all Flink code is loaded dynamically
// (for example from an OSGI bundle) through a custom ClassLoader
ClassLoader classLoader = getClass().getClassLoader();
@SuppressWarnings("unchecked") C proxy = (C) Proxy.newProxyInstance(classLoader, new Class<?>[] { clazz }, invocationHandler);
return proxy;
}, actorSystem.dispatcher());
return guardCompletionWithContextClassLoader(gatewayFuture, flinkClassLoader);
}
Aggregations