When using Akka actors, every actor created gets registered in an ActorRegistry. The ActorRegistry is a singleton, and allows for easy lookup and management (start, stop, ...) of all actors.
In an OSGi environment however, a number of application bundles can be installed each using Akka actors internally (and Akka is installed as a bundle itself). Some of the actors of an application bundle should be available to other bundles and as such act as exported services. Others are strictly internal to the bundle. The ActorRegistry however contains all the actors of all bundles (since it's a singleton), so both the exported as well as the internal ones. This means even the actors used internally in a bundle are available to any other bundle.
But I'd like to gain more control of which actors are available outside the scope of a bundle. Ideally every bundle would have it's own ActorRegistry, and decide which of its actors get published as an OSGi service.
So what would be the best way to use Akka for a modular application in an OSGi environment, to achieve true modularity?
(Background about this on http://blog.xume.com/2011/02/actorregistry-scope-using-akka-in-osgi.html
From what I recall,
ActorRegistry
was a singleton in an earlier versions of Akka, and, from what I can see in the code now, it no longer is. NowActorRegistry
is a final class, with an instance created for Actor companion object:So you can obviously create multiple instances of the registry.
Secondly, as you know, actors register/unregister themselves in
ActorRegistry
atstart
/stop
methods, thus, in your case I would end with subclassing/mixingActor
/LocalActorRef
(overloadingstart
/stop
responsible for registration, and adding here the functionality you're looking for) and/or adding your ownActorRegistry
.