I've now written a few applications using scala actors and I'm interested in how people have approached or dealt with some of the problems I've encountered.
A plethora of Message classes or !?
I have an actor which reacts to a user operation and must cause something to happen. Let's say it reacts to a message UserRequestsX(id). A continuing problem I have is that, because I want to modularize my programs, a single actor on its own is unable to complete the action without involving other actors. For example, suppose I need to use the id parameter to retrieve a bunch of values and then these need to be deleted via some other actor. If I were writing a normal Java program, I might do something like:
public void reportTrades(Date date) {
    Set<Trade> trades = persistence.lookup(date);
    reportService.report(trades);
}
Which is simple enough. However, using actors this becomes a bit of a pain because I want to avoid using  !?. One actor reacts to the ReportTrades(date) message but it must ask a PersistenceActor for the trades and then a ReportActor to report them. The only way I've found of doing this is to do:
react {
    case ReportTrades(date) =>
       persistenceActor ! GetTradesAndReport(date)
}
So that in my PersistenceActor I have a react block:
react {
    case GetTradesAndReport(date) =>
       val ts = trades.get(date) //from persietent store
       reportActor ! ReportTrades(ts)
}
But now I have 2 problems:
- I have to create extra message classes to represent the same request (i.e. "report trades"). In fact I have three in this scenario but I may have many more - it becomes a problem keeping track of these
- What should I call the first and third message ReportTrades? It's confusing to call them bothReportTrades(or if I do, I must put them in separate packages). Essentially there is no such thing asoverloadinga class byvaltype.
Is there something I'm missing? Can I avoid this? Should I just give up and use !? Do people use some organizational structure to clarify what is going on?
 
     
    