akka.cluster.Member Java Examples
The following examples show how to use
akka.cluster.Member.
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: ClusterStatusObserverActor.java From java-11-examples with Apache License 2.0 | 5 votes |
@Override public void onReceive(Object message) throws Throwable { if (message instanceof ClusterEvent.MemberEvent) { Member member = ((ClusterEvent.MemberEvent) message).member(); LOG.info("memberEvent: " + member.address().toString()); clusterStatusObserver.updateMember(member); } else if (message instanceof ClusterEvent.LeaderChanged) { ClusterEvent.LeaderChanged leaderChangedEvent = (ClusterEvent.LeaderChanged)message; clusterStatusObserver.onLeaderChanged(leaderChangedEvent); LOG.info("leaderChanged: " + leaderChangedEvent.getLeader().toString()); } else { LOG.info("onReceive: " + message.getClass().getName()); } }
Example #2
Source File: Worker.java From akka-tutorial with Apache License 2.0 | 5 votes |
private void register(Member member) { if ((this.masterSystem == null) && member.hasRole(MasterSystem.MASTER_ROLE)) { this.masterSystem = member; this.getContext() .actorSelection(member.address() + "/user/" + Master.DEFAULT_NAME) .tell(new Master.RegistrationMessage(), this.self()); } }
Example #3
Source File: Worker.java From akka-tutorial with Apache License 2.0 | 5 votes |
private void register(Member member) { if ((this.masterSystem == null) && member.hasRole(MasterSystem.MASTER_ROLE)) { this.masterSystem = member; this.registrationTime = System.currentTimeMillis(); this.getContext() .actorSelection(member.address() + "/user/" + Master.DEFAULT_NAME) .tell(new Master.RegistrationMessage(), this.self()); } }
Example #4
Source File: ClusterStatusObserver.java From java-11-examples with Apache License 2.0 | 4 votes |
public void updateMember(Member member) { membersList.put(member.address().toString(), member); LOG.info("CSO: [" + membersList.size() + "]"); }
Example #5
Source File: Worker.java From akka-tutorial with Apache License 2.0 | 4 votes |
private void register(Member member) { if (member.hasRole(OctopusMaster.MASTER_ROLE)) this.getContext() .actorSelection(member.address() + "/user/" + Profiler.DEFAULT_NAME) .tell(new RegistrationMessage(), this.self()); }
Example #6
Source File: ClusterStatusSupplier.java From ditto with Eclipse Public License 2.0 | 4 votes |
@Override public ClusterStatus get() { final Function<Member, String> mapMemberToString = member -> member.address().toString(); final Set<String> allRoles = cluster.state().getAllRoles() .stream() .filter(role -> !clusterConfig.getClusterStatusRolesBlacklist().contains(role)) .collect(Collectors.toSet()); final Set<Member> unreachable = cluster.state().getUnreachable(); final Set<Member> all = StreamSupport.stream(cluster.state().getMembers().spliterator(), false).collect(Collectors.toSet()); final Set<Member> reachable = all.stream().filter(m -> !unreachable.contains(m)).collect(Collectors.toSet()); final Set<ClusterRoleStatus> roles = new HashSet<>(allRoles.size()); allRoles.forEach(role -> { final Predicate<Member> filterRole = member -> member.getRoles().contains(role); // only add role if member has reachable or unreachable entries if (all.stream().anyMatch(filterRole)) { roles.add(ClusterRoleStatus.of( role, reachable.stream() .filter(filterRole) .map(mapMemberToString) .collect(Collectors.toSet()), unreachable.stream() .filter(filterRole) .map(mapMemberToString) .collect(Collectors.toSet()), Optional.ofNullable(cluster.state().getRoleLeader(role)) .map(Address::toString) .orElse(null) )); } }); return ClusterStatus.of( reachable.stream().map(mapMemberToString).collect(Collectors.toSet()), unreachable.stream().map(mapMemberToString).collect(Collectors.toSet()), cluster.state().getSeenBy().stream().map(Address::toString).collect(Collectors.toSet()), Optional.ofNullable(cluster.state().getLeader()).map(Address::toString).orElse(null), cluster.getSelfRoles(), roles ); }
Example #7
Source File: ClientActor.java From usergrid with Apache License 2.0 | 4 votes |
/** * Process messages about nodes up, down, reachable and unreachable. */ private void processAsClusterEvent(Object message) { if (message instanceof ClusterEvent.CurrentClusterState) { ClusterEvent.CurrentClusterState state = (ClusterEvent.CurrentClusterState) message; nodes.clear(); for (Member member : state.getMembers()) { if (member.hasRole("io") && member.status().equals( MemberStatus.up())) { nodes.add(member.address()); logger.debug("RequestActor {} received cluster-state member-up for {}", name, member.address()); } } } else if (message instanceof ClusterEvent.MemberUp) { ClusterEvent.MemberUp mUp = (ClusterEvent.MemberUp) message; if (mUp.member().hasRole("io")) { nodes.add( mUp.member().address() ); } logger.debug("{} received member-up for {}", name, mUp.member().address()); } else if (message instanceof ClusterEvent.MemberEvent) { ClusterEvent.MemberEvent other = (ClusterEvent.MemberEvent) message; nodes.remove(other.member().address()); } else if (message instanceof ClusterEvent.UnreachableMember) { ClusterEvent.UnreachableMember unreachable = (ClusterEvent.UnreachableMember) message; nodes.remove(unreachable.member().address()); logger.debug("{} received un-reachable for {}", name, unreachable.member().address()); } else if (message instanceof ClusterEvent.ReachableMember) { ClusterEvent.ReachableMember reachable = (ClusterEvent.ReachableMember) message; if (reachable.member().hasRole("io")) { nodes.add( reachable.member().address() ); } logger.debug("{} received reachable for {}", name, reachable.member().address()); } else { logger.error("{}: unhandled message: {}", name, message.toString()); unhandled(message); } }