Java Code Examples for akka.actor.ActorRef#equals()

The following examples show how to use akka.actor.ActorRef#equals() . 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: SupervisorActor.java    From flink with Apache License 2.0 6 votes vote down vote up
private void akkaRpcActorFailed(ActorRef actorRef, Throwable cause) {
	LOG.warn("AkkaRpcActor {} has failed. Shutting it down now.", actorRef.path(), cause);

	for (Map.Entry<ActorRef, AkkaRpcActorRegistration> registeredAkkaRpcActor : registeredAkkaRpcActors.entrySet()) {
		final ActorRef otherActorRef = registeredAkkaRpcActor.getKey();
		if (otherActorRef.equals(actorRef)) {
			final AkkaRpcException error = new AkkaRpcException(String.format("Stopping actor %s because it failed.", actorRef.path()), cause);
			registeredAkkaRpcActor.getValue().markFailed(error);
		} else {
			final AkkaRpcException siblingException = new AkkaRpcException(String.format("Stopping actor %s because its sibling %s has failed.", otherActorRef.path(), actorRef.path()));
			registeredAkkaRpcActor.getValue().markFailed(siblingException);
		}
	}

	getContext().getSystem().terminate();
}
 
Example 2
Source File: ProcessReaper.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public ProcessReaper(ActorRef watchTarget, Logger log, int exitCode) {
	if (watchTarget == null || watchTarget.equals(ActorRef.noSender())) {
		throw new IllegalArgumentException("Target may not be null or 'noSender'");
	}
	this.log = log;
	this.exitCode = exitCode;

	getContext().watch(watchTarget);
}
 
Example 3
Source File: ProcessReaper.java    From flink with Apache License 2.0 5 votes vote down vote up
public ProcessReaper(ActorRef watchTarget, Logger log, int exitCode) {
	if (watchTarget == null || watchTarget.equals(ActorRef.noSender())) {
		throw new IllegalArgumentException("Target may not be null or 'noSender'");
	}
	this.log = log;
	this.exitCode = exitCode;

	getContext().watch(watchTarget);
}
 
Example 4
Source File: RequestActor.java    From servicecomb-saga-actuator with Apache License 2.0 4 votes vote down vote up
private boolean isNotSender(ActorRef actor) {
  return !actor.equals(sender());
}
 
Example 5
Source File: WebSocketService.java    From htwplus with MIT License 4 votes vote down vote up
/**
 * WebSocket method when sending chat.
 *
 * @param wsMessage WebSocket message as JsonNode object
 * @param senderActor Sending actor
 * @param sender Sending account
 * @return WebSocket response
 */
private JsonNode wsSendChat(JsonNode wsMessage, ActorRef senderActor, Account sender) {
    // validate given parameters
    if (!wsMessage.has("recipient") || !wsMessage.has("text")) {
        return this.errorResponse("Could not send chat message, either no \"recipient\" or \"text\" information.");
    }

    Long recipientAccountId = wsMessage.get("recipient").asLong();
    String text = wsMessage.get("text").asText();
    Account recipient = this.getAccountById(recipientAccountId);

    // check, if recipient exists
    if (recipient == null) {
        return this.errorResponse("User not found");
    }


    ActorRef recipientActor = this.getActorForAccount(recipient);
    // check, if the recipient is online
    if (recipientActor == null) {
        return this.errorResponse("Recipient not online");
    }

    // sender should not be recipient
    if (recipientActor.equals(senderActor)) {
        return this.errorResponse("Cannot send chat to yourself");
    }
    // check, if sender and recipient are friends
    if (sender == null || !this.isFriendshipEstablished(sender, recipient)) {
        return this.errorResponse("You must be a friend of the recipient");
    }


    ObjectNode node = this.successResponseTemplate(WebSocketService.WS_METHOD_RECEIVE_CHAT);
    node.put("sender", Json.toJson(sender.getAsJson()));
    node.put("text", text);

    recipientActor.tell(Json.toJson(node), senderActor);

    return Json.toJson("OK");
}