Minor refactoring to ActorRegistry
This commit is contained in:
parent
236eecebcf
commit
b51a4fec64
1 changed files with 12 additions and 10 deletions
|
|
@ -79,7 +79,7 @@ object ActorRegistry extends ListenerManagement {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds all actors that are subtypes of the class passed in as the Manifest argument and supproting passed message.
|
* Finds all actors that are subtypes of the class passed in as the Manifest argument and supporting passed message.
|
||||||
*/
|
*/
|
||||||
def actorsFor[T <: Actor](message: Any)(implicit manifest: Manifest[T] ): Array[ActorRef] =
|
def actorsFor[T <: Actor](message: Any)(implicit manifest: Manifest[T] ): Array[ActorRef] =
|
||||||
filter(a => manifest.erasure.isAssignableFrom(a.actor.getClass) && a.isDefinedAt(message))
|
filter(a => manifest.erasure.isAssignableFrom(a.actor.getClass) && a.isDefinedAt(message))
|
||||||
|
|
@ -104,7 +104,7 @@ object ActorRegistry extends ListenerManagement {
|
||||||
actorsFor[T](manifest.erasure.asInstanceOf[Class[T]])
|
actorsFor[T](manifest.erasure.asInstanceOf[Class[T]])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds any actor that matches T.
|
* Finds any actor that matches T. Very expensive, traverses ALL alive actors.
|
||||||
*/
|
*/
|
||||||
def actorFor[T <: Actor](implicit manifest: Manifest[T]): Option[ActorRef] =
|
def actorFor[T <: Actor](implicit manifest: Manifest[T]): Option[ActorRef] =
|
||||||
find({ case a: ActorRef if manifest.erasure.isAssignableFrom(a.actor.getClass) => a })
|
find({ case a: ActorRef if manifest.erasure.isAssignableFrom(a.actor.getClass) => a })
|
||||||
|
|
@ -328,12 +328,12 @@ object ActorRegistry extends ListenerManagement {
|
||||||
/**
|
/**
|
||||||
* Registers an actor in the ActorRegistry.
|
* Registers an actor in the ActorRegistry.
|
||||||
*/
|
*/
|
||||||
private[akka] def register(actor: ActorRef) = {
|
private[akka] def register(actor: ActorRef) {
|
||||||
// ID
|
val id = actor.id
|
||||||
actorsById.put(actor.id, actor)
|
val uuid = actor.uuid
|
||||||
|
|
||||||
// UUID
|
actorsById.put(id, actor)
|
||||||
actorsByUUID.put(actor.uuid, actor)
|
actorsByUUID.put(uuid, actor)
|
||||||
|
|
||||||
// notify listeners
|
// notify listeners
|
||||||
notifyListeners(ActorRegistered(actor))
|
notifyListeners(ActorRegistered(actor))
|
||||||
|
|
@ -342,10 +342,12 @@ object ActorRegistry extends ListenerManagement {
|
||||||
/**
|
/**
|
||||||
* Unregisters an actor in the ActorRegistry.
|
* Unregisters an actor in the ActorRegistry.
|
||||||
*/
|
*/
|
||||||
private[akka] def unregister(actor: ActorRef) = {
|
private[akka] def unregister(actor: ActorRef) {
|
||||||
actorsByUUID remove actor.uuid
|
val id = actor.id
|
||||||
|
val uuid = actor.uuid
|
||||||
|
|
||||||
actorsById.remove(actor.id,actor)
|
actorsByUUID remove uuid
|
||||||
|
actorsById.remove(id,actor)
|
||||||
|
|
||||||
// notify listeners
|
// notify listeners
|
||||||
notifyListeners(ActorUnregistered(actor))
|
notifyListeners(ActorUnregistered(actor))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue