concept message in category scala

This is an excerpt from Manning's book Reactive Design Patterns.
CompletionStage<Response> future = ask(actorRef, request, timeout) #1 .thenApply(Response.class::cast); #2 future.thenAccept(response -> <process it>); #3 #1 - Sends a message to the actor reference, using a CompletionStage as the destination for the response #2 - Maps the response to its expected type, failing upon mismatch #3 - Registers further processing to be done once a response is received and mapped
Each of these blocking calls interacts with the network equipment, generating messages and reacting to messages under the hood, but this fact is completely hidden in order to construct a synchronous façade on top of the underlying message-driven system. The thread executing these commands will suspend its execution if not enough space is available in the output buffer (for the first line) or if the response is not immediately available (on the second line). Consequently, this thread cannot do any other work in the meantime: every activity of this type that is ongoing in parallel needs its own thread, even if many of those are doing nothing but waiting for events to occur.
The fundamental notion on which message passing is built is that of an event: the fact that a certain condition has occurred (the event) is bundled together with contextual information—like who did what when and where—and is signaled by the producer as a message. Interested parties are informed by the producer using a common transport mechanism and consume the message.
Messages naturally represent events, and message passing naturally represents event-driven interactions. An event propagating through a system can also be seen as a message being forwarded along a chain of processing units. Representing events as messages enables the trade-off between latency and throughput to be adjusted on a case-by-case basis or even dynamically. This is useful in cases where response times usually need to be short, but the system also needs to degrade gracefully when the input load increases.

This is an excerpt from Manning's book Play for Scala: Covers Play 2.
conf/messages— Default messages for all languages, for messages not localized for a particular language
Messages aren’t just simple strings; they’re patterns formatted using java.text.MessageFormat. This means that you can use parameters in your messages:
validation.required={0} is requiredYou can substitute these by specifying more parameters to the call to Messages:

This is an excerpt from Manning's book Scala in Action.
All operations are performed by sending messages to objects.
GreetingsActor accepts name and sends the message to a child actor to generate a greeting message. In this case we are using the ask method (you can use ? as well) of the ActorRef to send and receive a response. Since messages are processed asynchronously the ask method returns a Future. The mapTo message allows us to transform the message from Future[Any] to Future[String]. The challenge is we don’t know when the message will be ready so that we can send the reply to the sender. The pipeTo pattern solves that problem by hooking up with the Future so that when the future completes it can take the response inside the future and send it to the sender. To see the complete working example please look at the chapter codebase.
If a given message doesn’t match any pattern inside the receive method then the unhandled method is called with the akka.actor.UnhandledMessage message. The default behavior of this method is to publish the message to an actor system’s event stream. You can configure the event stream to log these unhandled messages in the log file.
val self: ActorRefThis field holds the actor reference of this actor. You can use self to send a message to itself.
final def sender: ActorRefThis is the ActorRef of the actor that sent the last received message. It is very useful when you want to reply to the sender of the message.
Figure 9.5. WordCountMaster and WordCountWorker actors are communicating by sending messages. The main program in the figure starts the word count process.
![]()
Let’s start with the WordCountWorker actor because it’s the easiest one. This actor processes only FileToCount type messages, and the action associated with the message is to open the file and count all the words in it. Counting words in a file is exactly the same as the threading example you saw previously:
def countWords(fileName:String) = { val dataFile = new File(fileName) Source.fromFile(dataFile).getLines.foldRight(0)(_.split(" ").size + _) }You’re using scala.io.Source to open the file and count all the words in it—pretty straightforward. Now comes the most interesting part: the receive method. You already know the message you need to handle, but one new thing you have to worry about is sending the reply to the WordCountMaster actor when you’re done counting words for a given file.

This is an excerpt from Manning's book Lift in Action: The Simply Functional Web Framework for Scala.
Using the Msgs snippet couldn’t be easier—any notices that are posted from Mapper will be displayed in your markup with the messages you specified in your model.
If you’ve been reading this book from the beginning, you’ll be familiar with the S.notice, S.warning, and S.error methods. You can implement these methods in your snippet and pass them a String that represents a message you wish to pass back to the user.
In order to allow the designer to position and style these messages, Lift provides the <lift:msgs /> and <lift:msg /> helpers. These have a variety of options to allow you style the message and interface precisely.