concept actor in category java

This is an excerpt from Manning's book Functional Programming in Java: How functional techniques improve your Java programs.
As part of message processing, actors can send messages to other actors. Messages are sent asynchronously, which means there’s no answer to wait for. As soon as a message is sent, the sender can continue its job, which mostly consists of processing, one at a time, a queue of messages it receives. Of course, handling the message queue means that there are some concurrent accesses to the queue to manage. But this management is abstracted in the actor framework, so you, the programmer, don’t need to worry about this.
Of course, answers to messages might be needed. Suppose an actor is responsible for a long computation. The client can take advantage of asynchronicity by continuing its own job while the computation is handled for it. But once the computation is done, there must be a way for the client to receive the result. This is simply done by having the actor responsible for the computation call back its client and send it the result, once again in an asynchronous way. Note that the client may be the original sender, though that need not always be the case.

This is an excerpt from Manning's book The Well-Grounded Java Developer.
Actors are Scala’s alternative take on concurrent programming. They provide an asynchronous model of concurrency, which is based on passing messages between executing units of code. This is a different high-level concurrency model that many developers find easier to use than the lock-based, shared-by-default model that Java provides (although Scala is, of course, built on the same low-level model—the JMM).
You have three separate cases that the monitoring actor can respond to (via receive). The first is a heartbeat message, which tells you only that all is well. Because this case class takes no parameters, it’s technically a singleton, so it’s referred to as a case object. The actor doesn’t need to take any action when it receives a heartbeat.
If you receive a TemperatureAlarm message, the actor will save the temperature at which the alarm was tripped. You can imagine that the veterinarian will have another piece of code that periodically checks the TemperatureMonitor actor to see if it’s been tripped.
Finally, there’s a default case. This is a catch-all just in case any unexpected messages leak into the actor’s environment. Without this catch-all, the actor would throw an exception if an unexpected message type was seen. We’ll come back to actors at the end of this chapter and look at a little more of the detail, but Scala concurrency is a huge subject, and we give you more than a taste in this book.
An actor is an object that extends scala.actors.Actor and implements the act() method. This should hopefully echo the definition of a thread in Java in your mind. The most important difference is that Scala actors don’t communicate using explicit shared data under most circumstances.
Note that the shared data part is something the programmer must do as part of best practices. There is nothing in Scala stopping you from sharing state between actors if you want to. It’s just considered bad style to do so. Instead, actors have a communication channel called a mailbox, which is used to send a message (a work item) into an actor from another context. Figure 9.5 shows how.
To implement an actor, you could simply extend the Actor class:
import scala.actors._ class MyActor extends Actor { def act() { ... } }This looks a lot like the way that Java code would declare a subclass of Thread. Just as with threads, you need to tell the actor to start and put itself into a state where it can start to receive methods. This is done with the start() method.
As you might expect by now, Scala also provides a handy factory method, actor, to help with creating new actors (the equivalent Java concept might be a static factory method that produces anonymous implementations of Runnable). That allows concise Scala code like this:
val myactor = actor { ... }The contents of the block being passed to actor are turned into the contents of the act() method. In addition, actors that are created this way don’t need to be started with a separate start() call—they automatically start.
Sending a message into an actor from another object is very simple—you just call the ! method on the actor object.