introducing: MainBus feat. LoggingBus

most tests passing, everything compiling, but docs not updated and nasty
thread-leak preventing me from running the whole test-suite (which is
the reason for this commit: I want to chase down that one first).

- the app.mainbus is classified by Class[_] (currently lookup, will
  possibly change to sub-class-aware) and accepts AnyRef messages
- LoggingBus handles akka.event-handlers from config specially:
  + start them as system services, supervised by SystemGuardian
  + keep their subscriptions in sync when logLevel_= is called
  + send them InitializeLogger(bus) message before subscribing them (so
    they can register for extras like Mute/UnMute)
- two-phased start-up: first phase with actor-less stdout logging, then
  subscription of config loggers, then remove stdout logger (logLevels
  configurable separately)
- MainBusReaper watches registered receivers and unsubscribes them upon
  death (started in phase 2)
- logger factory on Logging object, needs app/bus and log source;
  default instance in app.log
This commit is contained in:
Roland 2011-10-27 12:23:01 +02:00
parent c8b17b9e92
commit f46c6dc533
63 changed files with 749 additions and 643 deletions

View file

@ -6,7 +6,7 @@ package akka.remote
import akka.AkkaApplication
import akka.actor._
import akka.event.EventHandler
import akka.event.Logging
import akka.dispatch.{ Dispatchers, Future, PinnedDispatcher }
import akka.actor.Status._
import akka.util._
@ -29,6 +29,8 @@ import com.eaio.uuid.UUID
*/
class Remote(val app: AkkaApplication) extends RemoteService {
val log = Logging(app, this)
import app._
import app.config
import app.AkkaConfig._
@ -75,8 +77,8 @@ class Remote(val app: AkkaApplication) extends RemoteService {
val remote = new akka.remote.netty.NettyRemoteSupport(app)
remote.start(hostname, port)
remote.register(remoteDaemonServiceName, remoteDaemon)
app.eventHandler.addListener(eventStream.channel)
app.eventHandler.addListener(remoteClientLifeCycleHandler)
app.mainbus.subscribe(eventStream.channel, classOf[RemoteLifeCycleEvent])
app.mainbus.subscribe(remoteClientLifeCycleHandler, classOf[RemoteLifeCycleEvent])
// TODO actually register this provider in app in remote mode
//provider.register(ActorRefProvider.RemoteProvider, new RemoteActorRefProvider)
remote
@ -86,7 +88,7 @@ class Remote(val app: AkkaApplication) extends RemoteService {
def start() {
val triggerLazyServerVal = address.toString
eventHandler.info(this, "Starting remote server on [%s]".format(triggerLazyServerVal))
log.info("Starting remote server on [{}]", triggerLazyServerVal)
}
def uuidProtocolToUuid(uuid: UuidProtocol): UUID = new UUID(uuid.getHigh, uuid.getLow)
@ -108,16 +110,14 @@ class Remote(val app: AkkaApplication) extends RemoteService {
class RemoteSystemDaemon(remote: Remote) extends Actor {
import remote._
import remote.app._
override def preRestart(reason: Throwable, msg: Option[Any]) {
eventHandler.debug(this, "RemoteSystemDaemon failed due to [%s] - restarting...".format(reason))
log.debug("RemoteSystemDaemon failed due to [{}] - restarting...", reason)
}
def receive: Actor.Receive = {
case message: RemoteSystemDaemonMessageProtocol
eventHandler.debug(this,
"Received command [\n%s] to RemoteSystemDaemon on [%s]".format(message, nodename))
log.debug("Received command [\n{}] to RemoteSystemDaemon on [{}]", message, app.nodename)
message.getMessageType match {
case USE handleUse(message)
@ -135,7 +135,7 @@ class RemoteSystemDaemon(remote: Remote) extends Actor {
//TODO: should we not deal with unrecognized message types?
}
case unknown eventHandler.warning(this, "Unknown message to RemoteSystemDaemon [%s]".format(unknown))
case unknown log.warning("Unknown message to RemoteSystemDaemon [{}]", unknown)
}
def handleUse(message: RemoteSystemDaemonMessageProtocol) {
@ -147,7 +147,7 @@ class RemoteSystemDaemon(remote: Remote) extends Actor {
else message.getPayload.toByteArray
val actorFactory =
serialization.deserialize(actorFactoryBytes, classOf[() Actor], None) match {
app.serialization.deserialize(actorFactoryBytes, classOf[() Actor], None) match {
case Left(error) throw error
case Right(instance) instance.asInstanceOf[() Actor]
}
@ -158,7 +158,7 @@ class RemoteSystemDaemon(remote: Remote) extends Actor {
server.register(actorAddress, newActorRef)
} else {
eventHandler.error(this, "Actor 'address' for actor to instantiate is not defined, ignoring remote system daemon command [%s]".format(message))
log.error("Actor 'address' for actor to instantiate is not defined, ignoring remote system daemon command [{}]", message)
}
channel ! Success(address.toString)
@ -232,7 +232,7 @@ class RemoteSystemDaemon(remote: Remote) extends Actor {
}
private def payloadFor[T](message: RemoteSystemDaemonMessageProtocol, clazz: Class[T]): T = {
serialization.deserialize(message.getPayload.toByteArray, clazz, None) match {
app.serialization.deserialize(message.getPayload.toByteArray, clazz, None) match {
case Left(error) throw error
case Right(instance) instance.asInstanceOf[T]
}