/// <summary> /// Spawns a worker helper which communicates with the message store to add a dislike /// to a user message given in the message passed as parameter. /// </summary> /// <param name="m">non-null message of type Dislike</param> protected void processDislike(Message m) { Dislike like = (Dislike)m; if (!ongoingCommunications.ContainsKey(like.CommunicationId)) { throw new UnknownClientException("Unknown communication ID"); } SimulatedActor client = ongoingCommunications[like.CommunicationId]; MessageStoreMessage message = new AddDislike(like.ClientName, like.MessageId, like.CommunicationId); WorkerHelper helper = new WorkerHelper(messageStore, client, message, system); system.Spawn(helper); }
/// <summary> /// Spawns a worker helper which communicates with the message store to retrieve /// messages of the author given in the message passed as parameter. /// </summary> /// <param name="m">non-null message of type RetrieveMessages</param> protected void processRetrieveMessages(Message m) { RetrieveMessages retrMessages = (RetrieveMessages)m; if (!ongoingCommunications.ContainsKey(retrMessages.CommunicationId)) { throw new UnknownClientException("Unknown communication ID"); } SimulatedActor client = ongoingCommunications[retrMessages.CommunicationId]; MessageStoreMessage message = new RetrieveFromStore(retrMessages.Author, retrMessages.CommunicationId); WorkerHelper helper = new WorkerHelper(messageStore, client, message, system); system.Spawn(helper); }
/// <summary> /// Performs checks on a user message, which should be published. If the /// checks are passed, a worker helper is spawned, which communicates with /// the message store to store the new user message. /// New messages must have zero likes, must not have a message ID assigned /// and must not be (strictly) longer than 10 characters. /// Only 10 characters are allowed to to alleviate exercise 4. /// </summary> /// <param name="m">non-null message of type Publish</param> protected void processPublish(Message m) { Publish publish = (Publish)m; if (!ongoingCommunications.ContainsKey(publish.CommunicationId)) { throw new UnknownClientException("Unknown communication ID"); } SimulatedActor client = ongoingCommunications[publish.CommunicationId]; UserMessage userMessage = publish.Message; if (userMessage.Likes.Count > 0 || userMessage.Dislikes.Count > 0 || userMessage.MessageId != UserMessage.NEW || userMessage.Message.Length > 10) { client.Tell(new OperationFailed(publish.CommunicationId)); } else { MessageStoreMessage message = new UpdateMessageStore(userMessage, publish.CommunicationId); WorkerHelper helper = new WorkerHelper(messageStore, client, message, system); system.Spawn(helper); } }