use of org.apache.flink.runtime.messages.JobManagerMessages.ResponseWebMonitorPort in project flink by apache.
the class JobManagerRetriever method notifyLeaderAddress.
@Override
public void notifyLeaderAddress(final String leaderAddress, final UUID leaderSessionID) {
if (leaderAddress != null && !leaderAddress.equals("")) {
try {
final Promise<Tuple2<ActorGateway, Integer>> leaderGatewayPortPromise = new scala.concurrent.impl.Promise.DefaultPromise<>();
synchronized (waitLock) {
leaderGatewayPortFuture = leaderGatewayPortPromise.future();
waitLock.notifyAll();
}
LOG.info("New leader reachable under {}:{}.", leaderAddress, leaderSessionID);
AkkaUtils.getActorRefFuture(leaderAddress, actorSystem, lookupTimeout).flatMap(new Mapper<ActorRef, Future<Tuple2<ActorGateway, Object>>>() {
@Override
public Future<Tuple2<ActorGateway, Object>> apply(ActorRef jobManagerRef) {
ActorGateway leaderGateway = new AkkaActorGateway(jobManagerRef, leaderSessionID);
Future<Object> webMonitorPort = leaderGateway.ask(JobManagerMessages.getRequestWebMonitorPort(), timeout);
return Futures.successful(leaderGateway).zip(webMonitorPort);
}
}, actorSystem.dispatcher()).onComplete(new OnComplete<Tuple2<ActorGateway, Object>>() {
@Override
public void onComplete(Throwable failure, Tuple2<ActorGateway, Object> success) throws Throwable {
if (failure == null) {
if (success._2() instanceof ResponseWebMonitorPort) {
int webMonitorPort = ((ResponseWebMonitorPort) success._2()).port();
leaderGatewayPortPromise.success(new Tuple2<>(success._1(), webMonitorPort));
} else {
leaderGatewayPortPromise.failure(new Exception("Received the message " + success._2() + " as response to " + JobManagerMessages.getRequestWebMonitorPort() + ". But a message of type " + ResponseWebMonitorPort.class + " was expected."));
}
} else {
LOG.warn("Failed to retrieve leader gateway and port.", failure);
leaderGatewayPortPromise.failure(failure);
}
}
}, actorSystem.dispatcher());
} catch (Exception e) {
handleError(e);
}
}
}
Aggregations