+ Optional<Cluster> cluster = context.getCluster();
+ if (!cluster.isPresent()) {
+ return false;
+ }
+
+ ActorSelection leaderActor = context.getPeerActorSelection(leaderId);
+ if (leaderActor == null) {
+ return false;
+ }
+
+ Address leaderAddress = leaderActor.anchorPath().address();
+
+ CurrentClusterState state = cluster.get().state();
+ Set<Member> unreachable = state.getUnreachable();
+
+ log.debug("{}: Checking for leader {} in the cluster unreachable set {}", logName(), leaderAddress,
+ unreachable);
+
+ for (Member m: unreachable) {
+ if (leaderAddress.equals(m.address())) {
+ log.info("{}: Leader {} is unreachable", logName(), leaderAddress);
+ return false;
+ }
+ }
+
+ for (Member m: state.getMembers()) {
+ if (leaderAddress.equals(m.address())) {
+ if (m.status() == MemberStatus.up() || m.status() == MemberStatus.weaklyUp()) {
+ log.debug("{}: Leader {} cluster status is {} - leader is available", logName(),
+ leaderAddress, m.status());
+ return true;
+ } else {
+ log.debug("{}: Leader {} cluster status is {} - leader is unavailable", logName(),
+ leaderAddress, m.status());
+ return false;
+ }
+ }
+ }
+
+ log.debug("{}: Leader {} not found in the cluster member set", logName(), leaderAddress);
+
+ return false;