I rewrote the PureMCV framework in Scala language, but I have some questions/problems.
Previously I was using the multicore java version, which worked well with scala,
but because of it inherent one thereadedness I quicly hit a bottleneck (I'm wirting a server application)
In scala I also tried Actors but the only way you can send a message to an actor is by having a reference to the instance,so that is clearly not a modular architecture (and I do not want to pollute my code with singletons either..)
So I thought I will rewrite the PureMVC framework with Scala Actors (every actor is a real or virtual (pooled) thread) My plan was to run all mediators, commands and proxies in their own thread. But this of course posed a lot of questions.
Firstly: you cannot touch the proxies from the commands or the mediators because that is not thread safe, so you cannot do this:
var med = facade.retrieveMediator(TestMediator.NAME).asInstanceOf[TestMediator]
Basically you cannot call directly from any class instance to any other instance (by instance I mean commands, mediators and proxies)
For these purposes I created the bangWait function, which works very similary to the above, though not by locking but by sending scala !? message
Secondly: actors must have been told what notifications will they recat on (just like in the handleNotification function in Mediators)
but this will not work for proxies since they do not listen to notifications.
Thirdly: actors have ! and !? (and !!) operations, so I had to implement more functions like sendNotification to represent these
My solution to these problems:
-I ported the multicore AS3 version (it's much closer to scala sintax than java)
-All test cases were ported too and are running ok
-I completely removed proxies for the time being I use Mediators instead of them(see above in second point)
-All other stuff remained the same, I tried to keep as much of the original structure as possible.
-in the Notifier class besides the 'sendNotification' method a new 'bang' and a new 'bangWait' method was included
as it is in the Notifier it can be used from Commands and Mediators too. The bang method gets converted in the Observer class to scala ! and (it's just like sendNotification but with actors). The bangWait method (scala !?) is the equvivalent of a sychronous function call (see the scala Actors documentation for more info on this)
-In the mediator if you do not handle actor generated notifications with handleNotification function but by overriding the scala act method, you can send a reply with the scala reply method.
-As command listen to only one notification in any case the execute method will be called (so command remain 100% untouched)
-I wrote some extra testcases to test Actor based testcases.
I'm willing to commit the code if anyone interested, but I do not know what to do about all these changes. As of now ,except for proxies I left everything untouched, all I added -besides porting - are extra functionality , but if a newcomer wants to use it I would remove many standard
stuff from puremvc because those are not thread safe operations anymore.. remember all puremvc classes are running in thir own thread!
So I'm not sure if all these changes will qualify as PureMVC for Cliff Hall ...
It's more like a tiny but enormouly scalable messaging framework ... ParalelPureMVC or something.
I guess none of the above makes too much sense if you do not know Scala, but anyway , any comments? ideas?
I attached some testcases