How to achieve true modularity of the application using Akka in OSGi packages?

When using Akki Accs, each created actor is registered with ActorRegistry. ActorRegistry is a singleton and allows you to easily find and manage (start, stop, ...) all participants.

However, in the OSGi environment, a number of application packages can be installed, each of which uses Akka (and Akka is installed as the kit itself). Some of the participants in the application package must be available for other packages and as such act as exported services. Others are strictly internal to the kit. However, ActorRegistry contains all the participants in all packages (since it is singleton), therefore both exported and internal. This means that even the actors used inside the package are available for any other package.

But I would like to get more control over which actors are available outside the package. Ideally, each package should have its own ActorRegistry and decide which of its participants will be published as an OSGi service.

So, what would be the best way to use Akka for a modular application in the OSGi environment to achieve true modularity?

(Assume this at http://blog.xume.com/2011/02/actorregistry-scope-using-akka-in-osgi.html

+3
source share
1 answer

From what I remember, it ActorRegistrywas singleton in earlier versions of Akka, and from what I see in the code now, it is no longer . Now ActorRegistrythis is the last class, with an instance created for the Actor companion object:

object Actor extends Logging {
   ...
   val registry = new ActorRegistry
   ...
}

class LocalActorRef { 
  ...
  def initializeActorInstance = {
     ...
     Actor.registry.register(this)
     ...
  }
  ...
  def stop = {
     ...
     Actor.remote.unregister(this)
     ...
  }
  ...
}

This way you can create multiple registry instances.

-, , / ActorRegistry start/stop, , / Actor/LocalActorRef ( start/stop, , , ) / ActorRegistry.

+1

Source: https://habr.com/ru/post/1790641/


All Articles