Java Code Examples for akka.cluster.Member#hasRole()

The following examples show how to use akka.cluster.Member#hasRole() . 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: Worker.java    From akka-tutorial with Apache License 2.0 5 votes vote down vote up
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 2
Source File: Worker.java    From akka-tutorial with Apache License 2.0 5 votes vote down vote up
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 3
Source File: Worker.java    From akka-tutorial with Apache License 2.0 4 votes vote down vote up
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 4
Source File: ClientActor.java    From usergrid with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }
}