Removed logging

This commit is contained in:
Jonas Bonér 2011-02-28 22:54:32 +01:00
parent 359a63c2fb
commit 9354f0790c
51 changed files with 154 additions and 556 deletions

View file

@ -17,4 +17,4 @@ the License.
---------------
Licenses for dependency projects can be found here:
[http://doc.akkasource.org/licenses]
[http://doc.akka.io/licenses]

View file

@ -4,7 +4,6 @@
package akka
import akka.util.Logging
import akka.actor.newUuid
import java.io.{StringWriter, PrintWriter}
@ -34,16 +33,9 @@ import java.net.{InetAddress, UnknownHostException}
printStackTrace(pw)
sw.toString
}
private lazy val _log = {
AkkaException.log.slf4j.error(toString)
()
}
def log: Unit = _log
}
object AkkaException extends Logging {
object AkkaException {
val hostname = try {
InetAddress.getLocalHost.getHostName
} catch {

View file

@ -8,13 +8,14 @@ import akka.dispatch._
import akka.config.Config._
import akka.config.Supervision._
import akka.util.Helpers.{narrow, narrowSilently}
import akka.util.ListenerManagement
import akka.AkkaException
import java.util.concurrent.TimeUnit
import java.net.InetSocketAddress
import scala.reflect.BeanProperty
import akka.util. {ReflectiveAccess, Logging, Duration}
import akka.util. {ReflectiveAccess, Duration}
import akka.remoteinterface.RemoteSupport
import akka.japi. {Creator, Procedure}
@ -73,7 +74,31 @@ class ActorInitializationException private[akka](message: String) extends AkkaEx
class ActorTimeoutException private[akka](message: String) extends AkkaException(message)
/**
* This message is thrown by default when an Actors behavior doesn't match a message
* Error handler.
* <pre>
* val errorHandlerEventListener = new Actor {
* def receive = {
* case ErrorHandlerEvent(cause: Throwable, instance: AnyRef) =>
* }
* }
*
* ErrorHandler.addListener(errorHandlerEventListener)
* ...
* ErrorHandler.removeListener(errorHandlerEventListener)
* </pre>
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
object ErrorHandler extends ListenerManagement {
case class ErrorHandlerEvent(
@BeanProperty val cause: Throwable,
@BeanProperty val instance: AnyRef) {
@BeanProperty val thread: Thread = Thread.currentThread
}
}
/**
* This message is thrown by default when an Actors behavior doesn't match a message
*/
case class UnhandledMessageException(msg: Any, ref: ActorRef) extends Exception {
override def getMessage() = "Actor %s does not handle [%s]".format(ref,msg)
@ -85,7 +110,8 @@ case class UnhandledMessageException(msg: Any, ref: ActorRef) extends Exception
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
object Actor extends Logging {
object Actor extends ListenerManagement {
/**
* Add shutdown cleanups
*/
@ -93,11 +119,9 @@ object Actor extends Logging {
val hook = new Runnable {
override def run {
// Shutdown HawtDispatch GlobalQueue
log.slf4j.info("Shutting down Hawt Dispatch global queue")
org.fusesource.hawtdispatch.globalQueue.asInstanceOf[org.fusesource.hawtdispatch.internal.GlobalDispatchQueue].shutdown
// Clear Thread.subclassAudits
log.slf4j.info("Clearing subclass audits")
val tf = classOf[java.lang.Thread].getDeclaredField("subclassAudits")
tf.setAccessible(true)
val subclassAudits = tf.get(null).asInstanceOf[java.util.Map[_,_]]
@ -283,7 +307,7 @@ object Actor extends Logging {
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
trait Actor extends Logging {
trait Actor {
/**
* Type alias because traits cannot have companion objects.
@ -357,14 +381,14 @@ trait Actor extends Logging {
* <pre>
* def receive = {
* case Ping =&gt;
* log.slf4j.info("got a 'Ping' message")
* println("got a 'Ping' message")
* self.reply("pong")
*
* case OneWay =&gt;
* log.slf4j.info("got a 'OneWay' message")
* println("got a 'OneWay' message")
*
* case unknown =&gt;
* log.slf4j.warn("unknown message [{}], ignoring", unknown)
* println("unknown message: " + unknown)
* }
* </pre>
*/

View file

@ -22,7 +22,7 @@ import scala.reflect.BeanProperty
import scala.collection.immutable.Stack
import scala.annotation.tailrec
private[akka] object ActorRefInternals extends Logging {
private[akka] object ActorRefInternals {
/**
* LifeCycles for ActorRefs.
@ -68,9 +68,6 @@ private[akka] object ActorRefInternals extends Logging {
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
trait ActorRef extends ActorRefShared with java.lang.Comparable[ActorRef] { scalaRef: ScalaActorRef =>
//Reuse same logger
import Actor.log
// Only mutable for RemoteServer in order to maintain identity across nodes
@volatile
protected[akka] var _uuid = newUuid
@ -525,7 +522,6 @@ trait ActorRef extends ActorRefShared with java.lang.Comparable[ActorRef] { scal
protected[akka] def checkReceiveTimeout = {
cancelReceiveTimeout
if (receiveTimeout.isDefined && dispatcher.mailboxSize(this) <= 0) { //Only reschedule if desired and there are currently no more messages to be processed
log.slf4j.debug("Scheduling timeout for {}", this)
_futureTimeout = Some(Scheduler.scheduleOnce(this, ReceiveTimeout, receiveTimeout.get, TimeUnit.MILLISECONDS))
}
}
@ -534,7 +530,6 @@ trait ActorRef extends ActorRefShared with java.lang.Comparable[ActorRef] { scal
if (_futureTimeout.isDefined) {
_futureTimeout.get.cancel(true)
_futureTimeout = None
log.slf4j.debug("Timeout canceled for {}", this)
}
}
}
@ -682,7 +677,6 @@ class LocalActorRef private[akka] (
"Actor can only have one supervisor [" + actorRef + "], e.g. link(actor) fails")
linkedActors.put(actorRef.uuid, actorRef)
actorRef.supervisor = Some(this)
Actor.log.slf4j.debug("Linking actor [{}] to actor [{}]", actorRef, this)
}
/**
@ -695,7 +689,6 @@ class LocalActorRef private[akka] (
"Actor [" + actorRef + "] is not a linked actor, can't unlink")
linkedActors.remove(actorRef.uuid)
actorRef.supervisor = None
Actor.log.slf4j.debug("Unlinking actor [{}] from actor [{}]", actorRef, this)
}
/**
@ -811,11 +804,10 @@ class LocalActorRef private[akka] (
* Callback for the dispatcher. This is the single entry point to the user Actor implementation.
*/
protected[akka] def invoke(messageHandle: MessageInvocation): Unit = guard.withGuard {
if (isShutdown) Actor.log.slf4j.warn("Actor [{}] is shut down,\n\tignoring message [{}]", toString, messageHandle)
if (isShutdown) {}
else {
currentMessage = messageHandle
try {
Actor.log.slf4j.trace("Invoking actor with message: {}\n", messageHandle)
try {
cancelReceiveTimeout // FIXME: leave this here?
actor(messageHandle.message)
@ -827,8 +819,6 @@ class LocalActorRef private[akka] (
}
} catch {
case e =>
Actor.log.slf4j.error("Could not invoke actor [{}]", this)
Actor.log.slf4j.error("Problem", e)
throw e
} finally {
currentMessage = null //TODO: Don't reset this, we might want to resend the message
@ -884,42 +874,28 @@ class LocalActorRef private[akka] (
protected[akka] def restart(reason: Throwable, maxNrOfRetries: Option[Int], withinTimeRange: Option[Int]) {
def performRestart {
Actor.log.slf4j.info("Restarting actor [{}] configured as PERMANENT.", id)
val failedActor = actorInstance.get
failedActor match {
case p: Proxyable =>
//p.swapProxiedActor(freshActor) //TODO: broken
Actor.log.slf4j.debug("Invoking 'preRestart' for failed actor instance [{}].", id)
failedActor.preRestart(reason)
Actor.log.slf4j.debug("Invoking 'postRestart' for failed actor instance [{}].", id)
failedActor.postRestart(reason)
case _ =>
Actor.log.slf4j.debug("Invoking 'preRestart' for failed actor instance [{}].", id)
failedActor.preRestart(reason)
val freshActor = newActor
setActorSelfFields(failedActor,null) //Only null out the references if we could instantiate the new actor
actorInstance.set(freshActor) //Assign it here so if preStart fails, we can null out the sef-refs next call
freshActor.preStart
Actor.log.slf4j.debug("Invoking 'postRestart' for new actor instance [{}].", id)
freshActor.postRestart(reason)
}
}
def tooManyRestarts {
Actor.log.slf4j.warn(
"Maximum number of restarts [{}] within time range [{}] reached." +
"\n\tWill *not* restart actor [{}] anymore." +
"\n\tLast exception causing restart was" +
"\n\t[{}].",
Array[AnyRef](maxNrOfRetries, withinTimeRange, this, reason))
_supervisor.foreach { sup =>
// can supervisor handle the notification?
val notification = MaximumNumberOfRestartsWithinTimeRangeReached(this, maxNrOfRetries, withinTimeRange, reason)
if (sup.isDefinedAt(notification)) notifySupervisorWithMessage(notification)
else Actor.log.slf4j.warn(
"No message handler defined for system message [MaximumNumberOfRestartsWithinTimeRangeReached]" +
"\n\tCan't send the message to the supervisor [{}].", sup)
}
stop
@ -939,12 +915,9 @@ class LocalActorRef private[akka] (
performRestart
true
} catch {
case e => Actor.log.slf4j.debug("Unexpected exception during restart",e)
false //An error or exception here should trigger a retry
case e => false //An error or exception here should trigger a retry
}
Actor.log.slf4j.debug("Restart: {} for [{}].", success, id)
if (success) {
_status = ActorRefInternals.RUNNING
dispatcher.resume(this)
@ -999,15 +972,10 @@ class LocalActorRef private[akka] (
}
private def shutDownTemporaryActor(temporaryActor: ActorRef) {
Actor.log.slf4j.info("Actor [{}] configured as TEMPORARY and will not be restarted.", temporaryActor.id)
temporaryActor.stop
linkedActors.remove(temporaryActor.uuid) // remove the temporary actor
// if last temporary actor is gone, then unlink me from supervisor
if (linkedActors.isEmpty) {
Actor.log.slf4j.info(
"All linked actors have died permanently (they were all configured as TEMPORARY)" +
"\n\tshutting down and unlinking supervisor actor as well [{}].",
temporaryActor.id)
notifySupervisorWithMessage(UnlinkAndStop(this))
}
@ -1015,9 +983,6 @@ class LocalActorRef private[akka] (
}
private def handleExceptionInDispatch(reason: Throwable, message: Any) = {
Actor.log.slf4j.error("Exception when invoking \n\tactor [{}] \n\twith message [{}]", this, message)
Actor.log.slf4j.error("Problem", reason)
//Prevent any further messages to be processed until the actor has been restarted
dispatcher.suspend(this)
@ -1073,7 +1038,6 @@ class LocalActorRef private[akka] (
private def initializeActorInstance = {
actor.preStart // run actor preStart
Actor.log.slf4j.trace("[{}] has started", toString)
Actor.registry.register(this)
}
}

View file

@ -255,7 +255,6 @@ private[actor] final class ActorRegistry private[actor] () extends ListenerManag
* Shuts down and unregisters all actors in the system.
*/
def shutdownAll() {
log.slf4j.info("Shutting down all actors in the system...")
if (TypedActorModule.isEnabled) {
val elements = actorsByUUID.elements
while (elements.hasMoreElements) {
@ -270,7 +269,6 @@ private[actor] final class ActorRegistry private[actor] () extends ListenerManag
}
actorsByUUID.clear
actorsById.clear
log.slf4j.info("All actors have been shut down and unregistered from ActorRegistry")
}
}

View file

@ -8,13 +8,13 @@ import java.io.File
import java.net.{URL, URLClassLoader}
import java.util.jar.JarFile
import akka.util.{Bootable, Logging}
import akka.util.{Bootable}
import akka.config.Config._
/**
* Handles all modules in the deploy directory (load and unload)
*/
trait BootableActorLoaderService extends Bootable with Logging {
trait BootableActorLoaderService extends Bootable {
val BOOT_CLASSES = config.getList("akka.boot")
lazy val applicationLoader: Option[ClassLoader] = createApplicationClassLoader
@ -25,7 +25,6 @@ trait BootableActorLoaderService extends Bootable with Logging {
val DEPLOY = HOME.get + "/deploy"
val DEPLOY_DIR = new File(DEPLOY)
if (!DEPLOY_DIR.exists) {
log.slf4j.error("Could not find a deploy directory at [{}]", DEPLOY)
System.exit(-1)
}
val filesToDeploy = DEPLOY_DIR.listFiles.toArray.toList
@ -41,8 +40,6 @@ trait BootableActorLoaderService extends Bootable with Logging {
}
}
val toDeploy = filesToDeploy.map(_.toURI.toURL)
log.slf4j.info("Deploying applications from [{}]: [{}]", DEPLOY, toDeploy)
log.slf4j.debug("Loading dependencies [{}]", dependencyJars)
val allJars = toDeploy ::: dependencyJars
new URLClassLoader(allJars.toArray,Thread.currentThread.getContextClassLoader)
@ -50,12 +47,9 @@ trait BootableActorLoaderService extends Bootable with Logging {
})
abstract override def onLoad = {
applicationLoader.foreach(_ => log.slf4j.info("Creating /deploy class-loader"))
super.onLoad
for (loader <- applicationLoader; clazz <- BOOT_CLASSES) {
log.slf4j.info("Loading boot class [{}]", clazz)
loader.loadClass(clazz).newInstance
}
}

View file

@ -291,19 +291,16 @@ trait FSM[S, D] {
private val handleEventDefault: StateFunction = {
case Event(value, stateData) =>
log.slf4j.warn("Event {} not handled in state {}, staying at current state", value, currentState.stateName)
stay
}
private var handleEvent: StateFunction = handleEventDefault
private var terminateEvent: PartialFunction[StopEvent[S,D], Unit] = {
case StopEvent(Failure(cause), _, _) =>
log.slf4j.error("Stopping because of a failure with cause {}", cause)
case StopEvent(reason, _, _) => log.slf4j.info("Stopping because of reason: {}", reason)
case StopEvent(reason, _, _) =>
}
private var transitionEvent: TransitionHandler = (from, to) => {
log.slf4j.debug("Transitioning from state {} to {}", from, to)
}
override final protected def receive: Receive = {
@ -376,7 +373,6 @@ trait FSM[S, D] {
}
private def terminate(reason: Reason) = {
timers.foreach{ case (timer, t) => log.slf4j.info("Canceling timer {}", timer); t.cancel}
terminateEvent.apply(StopEvent(reason, currentState.stateName, currentState.stateData))
self.stop
}
@ -405,7 +401,7 @@ trait FSM[S, D] {
def replying(replyValue: Any): State = {
self.sender match {
case Some(sender) => sender ! replyValue
case None => log.slf4j.error("Unable to send reply value {}, no sender reference to reply to", replyValue)
case None =>
}
this
}

View file

@ -19,25 +19,19 @@ import scala.collection.JavaConversions
import java.util.concurrent._
import akka.util.Logging
import akka.AkkaException
object Scheduler extends Logging {
object Scheduler {
import Actor._
case class SchedulerException(msg: String, e: Throwable) extends RuntimeException(msg, e)
@volatile private var service = Executors.newSingleThreadScheduledExecutor(SchedulerThreadFactory)
log.slf4j.info("Starting up Scheduler")
/**
* Schedules to send the specified message to the receiver after initialDelay and then repeated after delay
*/
def schedule(receiver: ActorRef, message: AnyRef, initialDelay: Long, delay: Long, timeUnit: TimeUnit): ScheduledFuture[AnyRef] = {
log.slf4j.trace(
"Schedule scheduled event\n\tevent = [{}]\n\treceiver = [{}]\n\tinitialDelay = [{}]\n\tdelay = [{}]\n\ttimeUnit = [{}]",
Array[AnyRef](message, receiver, initialDelay.asInstanceOf[AnyRef], delay.asInstanceOf[AnyRef], timeUnit))
try {
service.scheduleAtFixedRate(
new Runnable { def run = receiver ! message },
@ -59,10 +53,6 @@ object Scheduler extends Logging {
* avoid blocking operations since this is executed in the schedulers thread
*/
def schedule(runnable: Runnable, initialDelay: Long, delay: Long, timeUnit: TimeUnit): ScheduledFuture[AnyRef] = {
log.slf4j.trace(
"Schedule scheduled event\n\trunnable = [{}]\n\tinitialDelay = [{}]\n\tdelay = [{}]\n\ttimeUnit = [{}]",
Array[AnyRef](runnable, initialDelay.asInstanceOf[AnyRef], delay.asInstanceOf[AnyRef], timeUnit))
try {
service.scheduleAtFixedRate(runnable,initialDelay, delay, timeUnit).asInstanceOf[ScheduledFuture[AnyRef]]
} catch {
@ -74,9 +64,6 @@ object Scheduler extends Logging {
* Schedules to send the specified message to the receiver after delay
*/
def scheduleOnce(receiver: ActorRef, message: AnyRef, delay: Long, timeUnit: TimeUnit): ScheduledFuture[AnyRef] = {
log.slf4j.trace(
"Schedule one-time event\n\tevent = [{}]\n\treceiver = [{}]\n\tdelay = [{}]\n\ttimeUnit = [{}]",
Array[AnyRef](message, receiver, delay.asInstanceOf[AnyRef], timeUnit))
try {
service.schedule(
new Runnable { def run = receiver ! message },
@ -98,9 +85,6 @@ object Scheduler extends Logging {
* avoid blocking operations since the runnable is executed in the schedulers thread
*/
def scheduleOnce(runnable: Runnable, delay: Long, timeUnit: TimeUnit): ScheduledFuture[AnyRef] = {
log.slf4j.trace(
"Schedule one-time event\n\trunnable = [{}]\n\tdelay = [{}]\n\ttimeUnit = [{}]",
Array[AnyRef](runnable, delay.asInstanceOf[AnyRef], timeUnit))
try {
service.schedule(runnable,delay, timeUnit).asInstanceOf[ScheduledFuture[AnyRef]]
} catch {
@ -109,12 +93,10 @@ object Scheduler extends Logging {
}
def shutdown: Unit = synchronized {
log.slf4j.info("Shutting down Scheduler")
service.shutdown
}
def restart: Unit = synchronized {
log.slf4j.info("Restarting Scheduler")
shutdown
service = Executors.newSingleThreadScheduledExecutor(SchedulerThreadFactory)
}

View file

@ -76,7 +76,7 @@ object Supervisor {
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
case class SupervisorFactory(val config: SupervisorConfig) extends Logging {
case class SupervisorFactory(val config: SupervisorConfig) {
def newInstance: Supervisor = newInstanceFor(config)
@ -166,11 +166,6 @@ final class SupervisorActor private[akka] (handler: FaultHandlingStrategy) exten
// FIXME add a way to respond to MaximumNumberOfRestartsWithinTimeRangeReached in declaratively configured Supervisor
case MaximumNumberOfRestartsWithinTimeRangeReached(
victim, maxNrOfRetries, withinTimeRange, lastExceptionCausingRestart) =>
Actor.log.slf4j.warn(
"Declaratively configured supervisor received a [MaximumNumberOfRestartsWithinTimeRangeReached] notification," +
"\n\tbut there is currently no way of handling it in a declaratively configured supervisor." +
"\n\tIf you want to be able to handle this error condition then you need to create the supervision tree programatically." +
"\n\tThis will be supported in the future.")
case unknown => throw new SupervisorException(
"SupervisorActor can not respond to messages.\n\tUnknown message [" + unknown + "]")
}

View file

@ -62,8 +62,6 @@ import scala.reflect.BeanProperty
*/
abstract class UntypedActor extends Actor {
def logger = log.logger //Give the Java guys a break
def getContext(): ActorRef = self
final protected def receive = {

View file

@ -5,7 +5,6 @@
package akka.config
import akka.AkkaException
import akka.util.Logging
import net.lag.configgy.{Config => CConfig, Configgy, ParseException}
import java.net.InetSocketAddress
@ -19,7 +18,7 @@ class ModuleNotAvailableException(message: String) extends AkkaException(message
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
object Config extends Logging {
object Config {
val VERSION = "1.1-SNAPSHOT"
val HOME = {
@ -57,7 +56,7 @@ object Config extends Logging {
val configFile = System.getProperty("akka.config", "")
try {
Configgy.configure(configFile)
log.slf4j.info("Config loaded from -Dakka.config={}", configFile)
println("Config loaded from -Dakka.config={}", configFile)
} catch {
case e: ParseException => throw new ConfigurationException(
"Config could not be loaded from -Dakka.config=" + configFile +
@ -67,7 +66,7 @@ object Config extends Logging {
} else if (getClass.getClassLoader.getResource(confName) ne null) {
try {
Configgy.configureFromResource(confName, getClass.getClassLoader)
log.slf4j.info("Config [{}] loaded from the application classpath.",confName)
println("Config [{}] loaded from the application classpath.",confName)
} catch {
case e: ParseException => throw new ConfigurationException(
"Can't load '" + confName + "' config file from application classpath," +
@ -78,7 +77,7 @@ object Config extends Logging {
try {
val configFile = HOME.get + "/config/" + confName
Configgy.configure(configFile)
log.slf4j.info(
println(
"AKKA_HOME is defined as [{}], config loaded from [{}].",
HOME.getOrElse(throwNoAkkaHomeException),
configFile)
@ -90,7 +89,7 @@ object Config extends Logging {
}
Configgy.config
} else {
log.slf4j.warn(
println(
"\nCan't load '" + confName + "'." +
"\nOne of the three ways of locating the '" + confName + "' file needs to be defined:" +
"\n\t1. Define the '-Dakka.config=...' system property option." +

View file

@ -7,7 +7,7 @@ package akka.dispatch
import akka.actor.{Actor, ActorRef}
import akka.actor.newUuid
import akka.config.Config._
import akka.util.{Duration, Logging}
import akka.util.{Duration}
import net.lag.configgy.ConfigMap
@ -46,7 +46,7 @@ import java.util.concurrent.TimeUnit
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
object Dispatchers extends Logging {
object Dispatchers {
val THROUGHPUT = config.getInt("akka.actor.throughput", 5)
val DEFAULT_SHUTDOWN_TIMEOUT = config.getLong("akka.actor.dispatcher-shutdown-timeout").
map(time => Duration(time, TIME_UNIT)).

View file

@ -116,12 +116,11 @@ class ExecutorBasedEventDrivenDispatcher(
}
}
private[akka] def start = log.slf4j.debug("Starting up {}\n\twith throughput [{}]", this, throughput)
private[akka] def start = {}
private[akka] def shutdown {
val old = executorService.getAndSet(config.createLazyExecutorService(threadFactory))
if (old ne null) {
log.slf4j.debug("Shutting down {}", this)
old.shutdownNow()
}
}
@ -137,17 +136,15 @@ class ExecutorBasedEventDrivenDispatcher(
throw e
}
}
} else log.slf4j.warn("{} is shut down,\n\tignoring the rest of the messages in the mailbox of\n\t{}", this, mbox)
}
override val toString = getClass.getSimpleName + "[" + name + "]"
def suspend(actorRef: ActorRef) {
log.slf4j.debug("Suspending {}",actorRef.uuid)
getMailbox(actorRef).suspended.tryLock
}
def resume(actorRef: ActorRef) {
log.slf4j.debug("Resuming {}",actorRef.uuid)
val mbox = getMailbox(actorRef)
mbox.suspended.tryUnlock
registerForExecution(mbox)

View file

@ -168,12 +168,11 @@ class ExecutorBasedEventDrivenWorkStealingDispatcher(
} else false
}
private[akka] def start = log.slf4j.debug("Starting up {}",toString)
private[akka] def start = {}
private[akka] def shutdown {
val old = executorService.getAndSet(config.createLazyExecutorService(threadFactory))
if (old ne null) {
log.slf4j.debug("Shutting down {}", toString)
old.shutdownNow()
}
}

View file

@ -7,7 +7,7 @@ package akka.dispatch
import java.util.concurrent._
import atomic. {AtomicInteger, AtomicBoolean, AtomicReference, AtomicLong}
import akka.util.{Switch, ReentrantGuard, Logging, HashCode, ReflectiveAccess}
import akka.util.{Switch, ReentrantGuard, HashCode, ReflectiveAccess}
import akka.actor._
/**
@ -36,7 +36,7 @@ object MessageDispatcher {
/**
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
trait MessageDispatcher extends Logging {
trait MessageDispatcher {
import MessageDispatcher._
protected val uuids = new ConcurrentSkipListSet[Uuid]
@ -105,8 +105,7 @@ trait MessageDispatcher extends Logging {
val uuid = i.next()
Actor.registry.actorFor(uuid) match {
case Some(actor) => actor.stop
case None =>
log.slf4j.error("stopAllLinkedActors couldn't find linked actor: " + uuid)
case None => {}
}
}
}

View file

@ -9,7 +9,7 @@ import java.util.concurrent._
import atomic.{AtomicLong, AtomicInteger}
import ThreadPoolExecutor.CallerRunsPolicy
import akka.util. {Duration, Logging}
import akka.util. {Duration}
object ThreadPoolConfig {
type Bounds = Int
@ -170,22 +170,19 @@ object MonitorableThread {
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
class MonitorableThread(runnable: Runnable, name: String)
extends Thread(runnable, name + "-" + MonitorableThread.created.incrementAndGet) with Logging {
extends Thread(runnable, name + "-" + MonitorableThread.created.incrementAndGet) {
setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
def uncaughtException(thread: Thread, cause: Throwable) =
log.slf4j.error("Thread.UncaughtException", cause)
def uncaughtException(thread: Thread, cause: Throwable) = {}
})
override def run = {
val debug = MonitorableThread.debugLifecycle
log.slf4j.debug("Created thread {}", getName)
try {
MonitorableThread.alive.incrementAndGet
super.run
} finally {
MonitorableThread.alive.decrementAndGet
log.slf4j.debug("Exiting thread {}", getName)
}
}
}
@ -212,13 +209,12 @@ class BoundedExecutorDecorator(val executor: ExecutorService, bound: Int) extend
case e: RejectedExecutionException =>
semaphore.release
case e =>
log.slf4j.error("Unexpected exception", e)
throw e
}
}
}
trait ExecutorServiceDelegate extends ExecutorService with Logging {
trait ExecutorServiceDelegate extends ExecutorService {
def executor: ExecutorService
@ -254,7 +250,6 @@ trait LazyExecutorService extends ExecutorServiceDelegate {
def createExecutor: ExecutorService
lazy val executor = {
log.slf4j.info("Lazily initializing ExecutorService for ",this)
createExecutor
}
}

View file

@ -14,7 +14,7 @@ import java.util.concurrent.ConcurrentHashMap
import akka.AkkaException
import reflect.BeanProperty
trait RemoteModule extends Logging {
trait RemoteModule {
val UUID_PREFIX = "uuid:"
def optimizeLocalScoped_?(): Boolean //Apply optimizations for remote operations in local scope

View file

@ -71,8 +71,7 @@ trait DefaultActorPool extends ActorPool
self reply_? Stats(_delegates length)
case max:MaximumNumberOfRestartsWithinTimeRangeReached =>
log.error("Pooled actor will be removed after exceeding maxium number of restart retries. ["+max.victim.toString+"]")
_delegates = _delegates filter {delegate => (delegate.uuid != max.victim.uuid)}
_delegates = _delegates filter {delegate => (delegate.uuid != max.victim.uuid)}
case msg =>
_capacity
@ -102,14 +101,11 @@ trait DefaultActorPool extends ActorPool
delegate
}
}
log.slf4j.debug("Pool capacity increased by {}", _lastCapacityChange)
}
else if (_lastCapacityChange < 0) {
val s = _delegates splitAt(_delegates.length + _lastCapacityChange)
s._2 foreach {_ stop}
_delegates = s._1
log.slf4j.debug("Pool capacity decreased by {}", -1*_lastCapacityChange)
}
}

View file

@ -9,7 +9,7 @@ import java.security.{MessageDigest, SecureRandom}
/**
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
object Crypt extends Logging {
object Crypt {
val hex = "0123456789ABCDEF"
val lineSeparator = System.getProperty("line.separator")
@ -24,7 +24,6 @@ object Crypt extends Logging {
def sha1(bytes: Array[Byte]): String = digest(bytes, MessageDigest.getInstance("SHA1"))
def generateSecureCookie: String = {
log.slf4j.info("Generating secure cookie...")
val bytes = Array.fill(32)(0.byteValue)
random.nextBytes(bytes)
sha1(bytes)

View file

@ -7,7 +7,7 @@ package akka.util
/**
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
object Helpers extends Logging {
object Helpers {
implicit def null2Option[T](t: T): Option[T] = Option(t)
@ -42,8 +42,6 @@ object Helpers extends Logging {
narrow(o)
} catch {
case e: ClassCastException =>
log.slf4j.warn("Cannot narrow {} to expected type {}!", o, implicitly[Manifest[T]].erasure.getName)
log.slf4j.trace("narrowSilently", e)
None
}

View file

@ -13,7 +13,7 @@ import akka.actor.ActorRef
*
* @author Martin Krasser
*/
trait ListenerManagement extends Logging {
trait ListenerManagement {
private val listeners = new ConcurrentSkipListSet[ActorRef]
@ -50,14 +50,13 @@ trait ListenerManagement extends Logging {
*/
def hasListener(listener: ActorRef): Boolean = listeners.contains(listener)
protected def notifyListeners(message: => Any) {
protected[akka] def notifyListeners(message: => Any) {
if (hasListeners) {
val msg = message
val iterator = listeners.iterator
while (iterator.hasNext) {
val listener = iterator.next
if (listener.isRunning) listener ! msg
else log.slf4j.warn("Can't notify [{}] since it is not running.", listener)
}
}
}
@ -65,12 +64,11 @@ trait ListenerManagement extends Logging {
/**
* Execute <code>f</code> with each listener as argument.
*/
protected def foreachListener(f: (ActorRef) => Unit) {
protected[akka] def foreachListener(f: (ActorRef) => Unit) {
val iterator = listeners.iterator
while (iterator.hasNext) {
val listener = iterator.next
if (listener.isRunning) f(listener)
else log.slf4j.warn("Can't notify [{}] since it is not running.", listener)
}
}
}

View file

@ -1,170 +0,0 @@
/**
* Copyright (C) 2009-2011 Scalable Solutions AB <http://scalablesolutions.se>
*/
package akka.util
import org.slf4j.{Logger => SLFLogger,LoggerFactory => SLFLoggerFactory}
/**
* Base trait for all classes that wants to be able use the logging infrastructure.
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
trait Logging {
@transient val log = Logger(this.getClass.getName)
}
/**
* Scala SLF4J wrapper
*
* Example:
* <pre>
* class Foo extends Logging {
* log.info("My foo is %s","alive")
* log.error(new Exception(),"My foo is %s","broken")
* }
* </pre>
*
* The logger uses String.format:
* http://download-llnw.oracle.com/javase/6/docs/api/java/lang/String.html#format(java.lang.String,%20java.lang.Object...)
*
* If you want to use underlying slf4j Logger, do:
* log.slf4j.info("My foo is {}","alive")
* log.slf4j.error("My foo is broken",new Exception())
*/
class Logger(val slf4j: SLFLogger) {
final def name = logger.getName
final def logger = slf4j
final def trace_? = logger.isTraceEnabled
final def debug_? = logger.isDebugEnabled
final def info_? = logger.isInfoEnabled
final def warning_? = logger.isWarnEnabled
final def error_? = logger.isErrorEnabled
//Trace
final def trace(t: Throwable, fmt: => String, arg: Any, argN: Any*) {
trace(t,message(fmt,arg,argN:_*))
}
final def trace(t: Throwable, msg: => String) {
if (trace_?) logger.trace(msg,t)
}
final def trace(fmt: => String, arg: Any, argN: Any*) {
trace(message(fmt,arg,argN:_*))
}
final def trace(msg: => String) {
if (trace_?) logger trace msg
}
//Debug
final def debug(t: Throwable, fmt: => String, arg: Any, argN: Any*) {
debug(t,message(fmt,arg,argN:_*))
}
final def debug(t: Throwable, msg: => String) {
if (debug_?) logger.debug(msg,t)
}
final def debug(fmt: => String, arg: Any, argN: Any*) {
debug(message(fmt,arg,argN:_*))
}
final def debug(msg: => String) {
if (debug_?) logger debug msg
}
//Info
final def info(t: Throwable, fmt: => String, arg: Any, argN: Any*) {
info(t,message(fmt,arg,argN:_*))
}
final def info(t: Throwable, msg: => String) {
if (info_?) logger.info(msg,t)
}
final def info(fmt: => String, arg: Any, argN: Any*) {
info(message(fmt,arg,argN:_*))
}
final def info(msg: => String) {
if (info_?) logger info msg
}
//Warning
final def warning(t: Throwable, fmt: => String, arg: Any, argN: Any*) {
warning(t,message(fmt,arg,argN:_*))
}
final def warn(t: Throwable, fmt: => String, arg: Any, argN: Any*) = warning(t, fmt, arg, argN)
final def warning(t: Throwable, msg: => String) {
if (warning_?) logger.warn(msg,t)
}
final def warn(t: Throwable, msg: => String) = warning(t, msg)
final def warning(fmt: => String, arg: Any, argN: Any*) {
warning(message(fmt,arg,argN:_*))
}
final def warn(fmt: => String, arg: Any, argN: Any*) = warning(fmt, arg, argN:_*)
final def warning(msg: => String) {
if (warning_?) logger warn msg
}
final def warn(msg: => String) = warning(msg)
//Error
final def error(t: Throwable, fmt: => String, arg: Any, argN: Any*) {
error(t,message(fmt,arg,argN:_*))
}
final def error(t: Throwable, msg: => String) {
if (error_?) logger.error(msg,t)
}
final def error(fmt: => String, arg: Any, argN: Any*) {
error(message(fmt,arg,argN:_*))
}
final def error(msg: => String) {
if (error_?) logger error msg
}
protected final def message(fmt: String, arg: Any, argN: Any*) : String = {
if ((argN eq null) || argN.isEmpty) fmt.format(arg)
else fmt.format((arg +: argN):_*)
}
}
/**
* Logger factory
*
* ex.
*
* val logger = Logger("my.cool.logger")
* val logger = Logger(classOf[Banana])
* val rootLogger = Logger.root
*
*/
object Logger {
/* Uncomment to be able to debug what logging configuration will be used
{
import org.slf4j.LoggerFactory
import ch.qos.logback.classic.LoggerContext
import ch.qos.logback.core.util.StatusPrinter
// print logback's internal status
StatusPrinter.print(LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext])
}*/
def apply(logger: String) : Logger = new Logger(SLFLoggerFactory getLogger logger)
def apply(clazz: Class[_]) : Logger = apply(clazz.getName)
def root : Logger = apply(SLFLogger.ROOT_LOGGER_NAME)
}

View file

@ -17,7 +17,7 @@ import akka.actor._
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
object ReflectiveAccess extends Logging {
object ReflectiveAccess {
val loader = getClass.getClassLoader
@ -125,8 +125,6 @@ object ReflectiveAccess extends Logging {
Some(ctor.newInstance(args: _*).asInstanceOf[T])
} catch {
case e =>
log.slf4j.warn("Could not instantiate class [{}]", clazz.getName)
log.slf4j.warn("createInstance",e.getCause)
None
}
@ -143,8 +141,6 @@ object ReflectiveAccess extends Logging {
Some(ctor.newInstance(args: _*).asInstanceOf[T])
} catch {
case e =>
log.slf4j.warn("Could not instantiate class [{}]", fqn)
log.slf4j.warn("createInstance",e.getCause)
None
}
@ -156,13 +152,9 @@ object ReflectiveAccess extends Logging {
Option(instance.get(null).asInstanceOf[T])
} catch {
case e: ClassNotFoundException => {
log.slf4j.debug("Could not get object [{}]", fqn)
log.slf4j.debug("getObjectFor", e)
None
}
case ei: ExceptionInInitializerError => {
log.slf4j.error("Exception in initializer for object [{}]",fqn)
log.slf4j.error("Cause was:",ei.getCause)
throw ei
}
}

View file

@ -60,11 +60,9 @@ object ActorRefSpec {
case "complex2" => replyActor ! "complexRequest2"
case "simple" => replyActor ! "simpleRequest"
case "complexReply" => {
println("got complex reply")
latch.countDown
}
case "simpleReply" => {
println("got simple reply")
latch.countDown
}
}

View file

@ -43,7 +43,6 @@ object FSMActorSpec {
goto(Open) using CodeState("", code) forMax timeout
}
case wrong => {
log.slf4j.error("Wrong code {}", wrong)
stay using CodeState("", code)
}
}
@ -61,7 +60,6 @@ object FSMActorSpec {
whenUnhandled {
case Event(_, stateData) => {
log.slf4j.info("Unhandled")
unhandledLatch.open
stay
}
@ -83,12 +81,10 @@ object FSMActorSpec {
initialize
private def doLock() {
log.slf4j.info("Locked")
lockedLatch.open
}
private def doUnlock = {
log.slf4j.info("Unlocked")
unlockedLatch.open
}
}

View file

@ -498,18 +498,16 @@ class SupervisorSpec extends JUnitSuite {
val inits = new AtomicInteger(0)
val dyingActor = actorOf(new Actor {
self.lifeCycle = Permanent
log.slf4j.debug("Creating dying actor, attempt: " + inits.incrementAndGet)
inits.incrementAndGet
if (!(inits.get % 2 != 0))
throw new IllegalStateException("Don't wanna!")
def receive = {
case Ping => self.reply_?("pong")
case Die => throw new Exception("expected")
}
})
val supervisor =
Supervisor(
SupervisorConfig(

View file

@ -2,7 +2,6 @@ package akka.actor.routing
import akka.actor.Actor
import akka.actor.Actor._
import akka.util.Logging
import org.scalatest.Suite
import org.junit.runner.RunWith
@ -15,7 +14,7 @@ import java.util.concurrent.{CountDownLatch, TimeUnit}
import akka.routing._
@RunWith(classOf[JUnitRunner])
class RoutingSpec extends junit.framework.TestCase with Suite with MustMatchers with Logging {
class RoutingSpec extends junit.framework.TestCase with Suite with MustMatchers {
import Routing._
@Test def testDispatcher = {

View file

@ -5,7 +5,7 @@
package akka.http
import akka.config.Config
import akka.util.{Logging, Bootable}
import akka.util.{Bootable}
import akka.remote.BootableRemoteActorService
import akka.actor.BootableActorLoaderService
import akka.servlet.AkkaLoader

View file

@ -9,7 +9,7 @@ import javax.servlet.ServletConfig
import java.io.File
import akka.actor.BootableActorLoaderService
import akka.util.{Bootable, Logging}
import akka.util.Bootable
import org.eclipse.jetty.xml.XmlConfiguration
import org.eclipse.jetty.server.{Handler, Server}
@ -20,7 +20,7 @@ import akka.AkkaException
/**
* Handles the Akka Comet Support (load/unload)
*/
trait EmbeddedAppServer extends Bootable with Logging {
trait EmbeddedAppServer extends Bootable {
self: BootableActorLoaderService =>
import akka.config.Config._
@ -39,7 +39,6 @@ trait EmbeddedAppServer extends Bootable with Logging {
abstract override def onLoad = {
super.onLoad
if (isRestEnabled) {
log.slf4j.info("Attempting to start Akka HTTP service")
val configuration = new XmlConfiguration(findJettyConfigXML.getOrElse(error("microkernel-server.xml not found!")))
@ -64,15 +63,11 @@ trait EmbeddedAppServer extends Bootable with Logging {
s.start()
s
}
log.slf4j.info("Akka HTTP service started")
}
}
abstract override def onUnload = {
super.onUnload
server foreach { t =>
log.slf4j.info("Shutting down REST service (Jersey)")
t.stop()
}
server foreach { _.stop() }
}
}

View file

@ -14,8 +14,7 @@ import Types._
/**
* @author Garrick Evans
*/
trait JettyContinuation extends ContinuationListener with akka.util.Logging
{
trait JettyContinuation extends ContinuationListener {
import javax.servlet.http.HttpServletResponse
import MistSettings._
@ -79,7 +78,6 @@ trait JettyContinuation extends ContinuationListener with akka.util.Logging
// unexpected continution state(s) - log and do nothing
//
case _ => {
log.slf4j.warn("Received continuation in unexpected state: "+continuation.isInitial+" "+continuation.isSuspended+" "+continuation.isExpired+" "+continuation.isResumed)
//continuation.cancel
None
}

View file

@ -4,7 +4,6 @@
package akka.http
import akka.util.Logging
import akka.actor.{ActorRegistry, ActorRef, Actor}
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
@ -63,7 +62,7 @@ import Types._
/**
*
*/
trait Mist extends Logging {
trait Mist {
import javax.servlet.{ServletContext}
import MistSettings._
@ -118,16 +117,11 @@ trait Mist extends Logging {
val server = context.getServerInfo
val (major, minor) = (context.getMajorVersion, context.getMinorVersion)
log.slf4j.info("Initializing Akka HTTP on {} with Servlet API {}.{}",Array[AnyRef](server, major: java.lang.Integer, minor: java.lang.Integer))
_factory = if (major >= 3) {
log.slf4j.info("Supporting Java asynchronous contexts.")
Some(Servlet30ContextMethodFactory)
} else if (server.toLowerCase startsWith JettyServer) {
log.slf4j.info("Supporting Jetty asynchronous continuations.")
Some(JettyContinuationMethodFactory)
} else {
log.slf4j.error("No asynchronous request handling can be supported.")
None
}
}
@ -185,7 +179,7 @@ class AkkaMistFilter extends Filter with Mist {
case "POST" => mistify(hreq, hres)(_factory.get.Post)
case "PUT" => mistify(hreq, hres)(_factory.get.Put)
case "TRACE" => mistify(hreq, hres)(_factory.get.Trace)
case unknown => log.slf4j.warn("Unknown http method: {}",unknown)
case unknown => {}
}
chain.doFilter(req,res)
case _ => chain.doFilter(req,res)
@ -270,7 +264,6 @@ trait Endpoint { this: Actor =>
*/
protected def _na(uri: String, req: RequestMethod) = {
req.NotFound("No endpoint available for [" + uri + "]")
log.slf4j.debug("No endpoint available for [{}]", uri)
}
}
@ -300,7 +293,7 @@ class RootEndpoint extends Actor with Endpoint {
def recv: Receive = {
case NoneAvailable(uri, req) => _na(uri, req)
case unknown => log.slf4j.error("Unexpected message sent to root endpoint. [{}]", unknown)
case unknown => {}
}
/**
@ -319,8 +312,7 @@ class RootEndpoint extends Actor with Endpoint {
*
* @author Garrick Evans
*/
trait RequestMethod extends Logging
{
trait RequestMethod {
import java.io.IOException
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
@ -387,7 +379,6 @@ trait RequestMethod extends Logging
case Some(pipe) => {
try {
if (!suspended) {
log.slf4j.warn("Attempt to complete an expired connection.")
false
}
else {
@ -397,13 +388,11 @@ trait RequestMethod extends Logging
}
} catch {
case io =>
log.slf4j.error("Failed to write data to connection on resume - the client probably disconnected", io)
false
}
}
case None =>
log.slf4j.error("Attempt to complete request with no context.")
false
}
@ -411,24 +400,16 @@ trait RequestMethod extends Logging
context match {
case Some(pipe) => {
try {
if (!suspended) {
log.slf4j.warn("Attempt to complete an expired connection.")
}
else {
if (suspended) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to write data to connection on resume")
pipe.complete
}
}
catch {
case io: IOException => log.slf4j.error("Request completed with internal error.", io)
}
finally {
log.slf4j.error("Request completed with internal error.", t)
} catch {
case io: IOException => {}
}
}
case None =>
log.slf4j.error("Attempt to complete request with no context", t)
case None => {}
}
}

View file

@ -11,8 +11,7 @@ import Types._
/**
* @author Garrick Evans
*/
trait Servlet30Context extends AsyncListener with akka.util.Logging
{
trait Servlet30Context extends AsyncListener {
import javax.servlet.http.HttpServletResponse
import MistSettings._
@ -36,7 +35,6 @@ trait Servlet30Context extends AsyncListener with akka.util.Logging
}
catch {
case ex: IllegalStateException =>
log.slf4j.info("Cannot update timeout - already returned to container")
false
}
}
@ -46,8 +44,8 @@ trait Servlet30Context extends AsyncListener with akka.util.Logging
//
def onComplete(e: AsyncEvent) {}
def onError(e: AsyncEvent) = e.getThrowable match {
case null => log.slf4j.warn("Error occured...")
case t => log.slf4j.warn("Error occured", t)
case null => {}
case t => {}
}
def onStartAsync(e: AsyncEvent) {}
def onTimeout(e: AsyncEvent) = {

View file

@ -25,7 +25,6 @@ package akka.security
import akka.actor.{Scheduler, Actor, ActorRef, ActorRegistry, IllegalActorStateException}
import akka.actor.Actor._
import akka.config.Config
import akka.util.Logging
import com.sun.jersey.api.model.AbstractMethod
import com.sun.jersey.spi.container.{ResourceFilterFactory, ContainerRequest, ContainerRequestFilter, ContainerResponse, ContainerResponseFilter, ResourceFilter}
@ -69,9 +68,9 @@ case class SpnegoCredentials(token: Array[Byte]) extends Credentials
/**
* Jersey Filter for invocation intercept and authorization/authentication
*/
class AkkaSecurityFilterFactory extends ResourceFilterFactory with Logging {
class AkkaSecurityFilterFactory extends ResourceFilterFactory {
class Filter(actor: ActorRef, rolesAllowed: Option[List[String]])
extends ResourceFilter with ContainerRequestFilter with Logging {
extends ResourceFilter with ContainerRequestFilter {
override def getRequestFilter: ContainerRequestFilter = this
@ -91,7 +90,6 @@ class AkkaSecurityFilterFactory extends ResourceFilterFactory with Logging {
throw new WebApplicationException(r.asInstanceOf[Response])
case None => throw new WebApplicationException(408)
case unknown => {
log.slf4j.warn("Authenticator replied with unexpected result [{}]", unknown)
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR)
}
}
@ -244,7 +242,7 @@ trait BasicAuthenticationActor extends AuthenticationActor[BasicCredentials] {
* class to create an authenticator. Don't forget to set the authenticator FQN in the
* rest-part of the akka config
*/
trait DigestAuthenticationActor extends AuthenticationActor[DigestCredentials] with Logging {
trait DigestAuthenticationActor extends AuthenticationActor[DigestCredentials] {
import LiftUtils._
private object InvalidateNonces
@ -257,8 +255,7 @@ trait DigestAuthenticationActor extends AuthenticationActor[DigestCredentials] w
case InvalidateNonces =>
val ts = System.currentTimeMillis
nonceMap.filter(tuple => (ts - tuple._2) < nonceValidityPeriod)
case unknown =>
log.slf4j.error("Don't know what to do with: ", unknown)
case unknown => {}
}
//Schedule the invalidation of nonces
@ -345,7 +342,7 @@ import org.ietf.jgss.GSSContext
import org.ietf.jgss.GSSCredential
import org.ietf.jgss.GSSManager
trait SpnegoAuthenticationActor extends AuthenticationActor[SpnegoCredentials] with Logging {
trait SpnegoAuthenticationActor extends AuthenticationActor[SpnegoCredentials] {
override def unauthorized =
Response.status(401).header("WWW-Authenticate", "Negotiate").build
@ -371,7 +368,6 @@ trait SpnegoAuthenticationActor extends AuthenticationActor[SpnegoCredentials] w
Some(UserInfo(user, null, rolesFor(user)))
} catch {
case e: PrivilegedActionException => {
log.slf4j.error("Action not allowed", e)
return None
}
}

View file

@ -6,12 +6,12 @@ package akka.servlet
import akka.config.Config
import akka.actor.Actor
import akka.util. {Switch, Logging, Bootable}
import akka.util. {Switch, Bootable}
/*
* This class is responsible for booting up a stack of bundles and then shutting them down
*/
class AkkaLoader extends Logging {
class AkkaLoader {
private val hasBooted = new Switch(false)
@volatile private var _bundles: Option[Bootable] = None
@ -23,50 +23,50 @@ class AkkaLoader extends Logging {
*/
def boot(withBanner: Boolean, b : Bootable): Unit = hasBooted switchOn {
if (withBanner) printBanner
log.slf4j.info("Starting Akka...")
println("Starting Akka...")
b.onLoad
Thread.currentThread.setContextClassLoader(getClass.getClassLoader)
_bundles = Some(b)
log.slf4j.info("Akka started successfully")
println("Akka started successfully")
}
/*
* Shutdown, well, shuts down the bundles used in boot
*/
def shutdown: Unit = hasBooted switchOff {
log.slf4j.info("Shutting down Akka...")
println("Shutting down Akka...")
_bundles.foreach(_.onUnload)
_bundles = None
Actor.shutdownHook.run
log.slf4j.info("Akka succesfully shut down")
println("Akka succesfully shut down")
}
private def printBanner = {
log.slf4j.info("==================================================")
log.slf4j.info(" t")
log.slf4j.info(" t t t")
log.slf4j.info(" t t tt t")
log.slf4j.info(" tt t t tt t")
log.slf4j.info(" t ttttttt t ttt t")
log.slf4j.info(" t tt ttt t ttt t")
log.slf4j.info(" t t ttt t ttt t t")
log.slf4j.info(" tt t ttt ttt ttt t")
log.slf4j.info(" t t ttt ttt t tt t")
log.slf4j.info(" t ttt ttt t t")
log.slf4j.info(" tt ttt ttt t")
log.slf4j.info(" ttt ttt")
log.slf4j.info(" tttttttt ttt ttt ttt ttt tttttttt")
log.slf4j.info(" ttt tt ttt ttt ttt ttt ttt ttt")
log.slf4j.info(" ttt ttt ttt ttt ttt ttt ttt ttt")
log.slf4j.info(" ttt ttt ttt ttt ttt tt ttt ttt")
log.slf4j.info(" tttt ttttttttt tttttttt tttt")
log.slf4j.info(" ttttttttt ttt ttt ttt ttt ttttttttt")
log.slf4j.info(" ttt ttt ttt ttt ttt ttt ttt ttt")
log.slf4j.info(" ttt ttt ttt ttt ttt ttt ttt ttt")
log.slf4j.info(" ttt tt ttt ttt ttt ttt ttt ttt")
log.slf4j.info(" tttttttt ttt ttt ttt ttt tttttttt")
log.slf4j.info("==================================================")
log.slf4j.info(" Running version {}", Config.VERSION)
log.slf4j.info("==================================================")
println("==================================================")
println(" t")
println(" t t t")
println(" t t tt t")
println(" tt t t tt t")
println(" t ttttttt t ttt t")
println(" t tt ttt t ttt t")
println(" t t ttt t ttt t t")
println(" tt t ttt ttt ttt t")
println(" t t ttt ttt t tt t")
println(" t ttt ttt t t")
println(" tt ttt ttt t")
println(" ttt ttt")
println(" tttttttt ttt ttt ttt ttt tttttttt")
println(" ttt tt ttt ttt ttt ttt ttt ttt")
println(" ttt ttt ttt ttt ttt ttt ttt ttt")
println(" ttt ttt ttt ttt ttt tt ttt ttt")
println(" tttt ttttttttt tttttttt tttt")
println(" ttttttttt ttt ttt ttt ttt ttttttttt")
println(" ttt ttt ttt ttt ttt ttt ttt ttt")
println(" ttt ttt ttt ttt ttt ttt ttt ttt")
println(" ttt tt ttt ttt ttt ttt ttt ttt")
println(" tttttttt ttt ttt ttt ttt tttttttt")
println("==================================================")
println(" Running version {}", Config.VERSION)
println("==================================================")
}
}

View file

@ -7,7 +7,7 @@ package akka.servlet
import akka.remote.BootableRemoteActorService
import akka.actor.BootableActorLoaderService
import akka.config.Config
import akka.util.{Logging, Bootable}
import akka.util.Bootable
import javax.servlet.{ServletContextListener, ServletContextEvent}

View file

@ -6,14 +6,14 @@ package akka.remote
import akka.config.Config.config
import akka.actor. {Actor, BootableActorLoaderService}
import akka.util. {ReflectiveAccess, Bootable, Logging}
import akka.util. {ReflectiveAccess, Bootable}
/**
* This bundle/service is responsible for booting up and shutting down the remote actors facility
* <p/>
* It is used in Kernel
*/
trait BootableRemoteActorService extends Bootable with Logging {
trait BootableRemoteActorService extends Bootable {
self: BootableActorLoaderService =>
protected lazy val remoteServerThread = new Thread(new Runnable() {
@ -24,18 +24,14 @@ trait BootableRemoteActorService extends Bootable with Logging {
abstract override def onLoad = {
if (ReflectiveAccess.isRemotingEnabled && RemoteServerSettings.isRemotingEnabled) {
log.slf4j.info("Initializing Remote Actors Service...")
startRemoteService
log.slf4j.info("Remote Actors Service initialized")
}
super.onLoad
}
abstract override def onUnload = {
log.slf4j.info("Shutting down Remote Actors Service")
Actor.remote.shutdown
if (remoteServerThread.isAlive) remoteServerThread.join(1000)
log.slf4j.info("Remote Actors Service has been shut down")
super.onUnload
}
}

View file

@ -10,7 +10,7 @@ import akka.util._
import com.google.protobuf.{Message, ByteString}
object MessageSerializer extends Logging {
object MessageSerializer {
private def SERIALIZER_JAVA: Serializer.Java = Serializer.Java
private def SERIALIZER_JAVA_JSON: Serializer.JavaJSON = Serializer.JavaJSON
private def SERIALIZER_SCALA_JSON: Serializer.ScalaJSON = Serializer.ScalaJSON

View file

@ -38,7 +38,7 @@ import scala.reflect.BeanProperty
import java.lang.reflect.InvocationTargetException
import java.util.concurrent.atomic. {AtomicReference, AtomicLong, AtomicBoolean}
trait NettyRemoteClientModule extends RemoteClientModule { self: ListenerManagement with Logging =>
trait NettyRemoteClientModule extends RemoteClientModule { self: ListenerManagement =>
private val remoteClients = new HashMap[Address, RemoteClient]
private val remoteActors = new Index[Address, Uuid]
private val lock = new ReadWriteGuard
@ -142,7 +142,7 @@ trait NettyRemoteClientModule extends RemoteClientModule { self: ListenerManagem
*/
abstract class RemoteClient private[akka] (
val module: NettyRemoteClientModule,
val remoteAddress: InetSocketAddress) extends Logging {
val remoteAddress: InetSocketAddress) {
val name = this.getClass.getSimpleName + "@" + remoteAddress.getHostName + "::" + remoteAddress.getPort
@ -194,7 +194,6 @@ abstract class RemoteClient private[akka] (
def send[T](
request: RemoteMessageProtocol,
senderFuture: Option[CompletableFuture[T]]): Option[CompletableFuture[T]] = {
log.slf4j.debug("sending message: {} has future {}", request, senderFuture)
if (isRunning) {
if (request.getOneWay) {
currentChannel.write(request).addListener(new ChannelFutureListener {
@ -272,22 +271,17 @@ class ActiveRemoteClient private[akka] (
bootstrap.setOption("tcpNoDelay", true)
bootstrap.setOption("keepAlive", true)
log.slf4j.info("Starting remote client connection to [{}]", remoteAddress)
// Wait until the connection attempt succeeds or fails.
connection = bootstrap.connect(remoteAddress)
openChannels.add(connection.awaitUninterruptibly.getChannel)
if (!connection.isSuccess) {
notifyListeners(RemoteClientError(connection.getCause, module, remoteAddress))
log.slf4j.error("Remote client connection to [{}] has failed", remoteAddress)
log.slf4j.debug("Remote client connection failed", connection.getCause)
false
} else {
timer.newTimeout(new TimerTask() {
def run(timeout: Timeout) = {
if(isRunning) {
log.slf4j.debug("Reaping expired futures awaiting completion from [{}]", remoteAddress)
val i = futures.entrySet.iterator
while(i.hasNext) {
val e = i.next
@ -304,15 +298,12 @@ class ActiveRemoteClient private[akka] (
case true => true
case false if reconnectIfAlreadyConnected =>
isAuthenticated.set(false)
log.slf4j.debug("Remote client reconnecting to [{}]", remoteAddress)
openChannels.remove(connection.getChannel)
connection.getChannel.close
connection = bootstrap.connect(remoteAddress)
openChannels.add(connection.awaitUninterruptibly.getChannel) // Wait until the connection attempt succeeds or fails.
if (!connection.isSuccess) {
notifyListeners(RemoteClientError(connection.getCause, module, remoteAddress))
log.slf4j.error("Reconnection to [{}] has failed", remoteAddress)
log.slf4j.debug("Reconnection failed", connection.getCause)
false
} else true
case false => false
@ -320,7 +311,6 @@ class ActiveRemoteClient private[akka] (
}
def shutdown = runSwitch switchOff {
log.slf4j.info("Shutting down {}", name)
notifyListeners(RemoteClientShutdown(module, remoteAddress))
timer.stop
timer = null
@ -329,7 +319,6 @@ class ActiveRemoteClient private[akka] (
bootstrap.releaseExternalResources
bootstrap = null
connection = null
log.slf4j.info("{} has been shut down", name)
}
private[akka] def isWithinReconnectionTimeWindow: Boolean = {
@ -339,7 +328,6 @@ class ActiveRemoteClient private[akka] (
} else {
val timeLeft = RECONNECTION_TIME_WINDOW - (System.currentTimeMillis - reconnectionTimeWindowStart)
if (timeLeft > 0) {
log.slf4j.info("Will try to reconnect to remote server for another [{}] milliseconds", timeLeft)
true
} else false
}
@ -399,12 +387,11 @@ class ActiveRemoteClientHandler(
val remoteAddress: SocketAddress,
val timer: HashedWheelTimer,
val client: ActiveRemoteClient)
extends SimpleChannelUpstreamHandler with Logging {
extends SimpleChannelUpstreamHandler {
override def handleUpstream(ctx: ChannelHandlerContext, event: ChannelEvent) = {
if (event.isInstanceOf[ChannelStateEvent] &&
event.asInstanceOf[ChannelStateEvent].getState != ChannelState.INTEREST_OPS) {
log.slf4j.debug(event.toString)
}
super.handleUpstream(ctx, event)
}
@ -414,8 +401,6 @@ class ActiveRemoteClientHandler(
event.getMessage match {
case reply: RemoteMessageProtocol =>
val replyUuid = uuidFrom(reply.getActorInfo.getUuid.getHigh, reply.getActorInfo.getUuid.getLow)
log.slf4j.debug("Remote client received RemoteMessageProtocol[\n{}]",reply)
log.slf4j.debug("Trying to map back to future: {}",replyUuid)
val future = futures.remove(replyUuid).asInstanceOf[CompletableFuture[Any]]
if (reply.hasMessage) {
@ -444,7 +429,6 @@ class ActiveRemoteClientHandler(
} catch {
case e: Exception =>
client.notifyListeners(RemoteClientError(e, client.module, client.remoteAddress))
log.slf4j.error("Unexpected exception in remote client handler", e)
throw e
}
}
@ -465,7 +449,6 @@ class ActiveRemoteClientHandler(
override def channelConnected(ctx: ChannelHandlerContext, event: ChannelStateEvent) = {
def connect = {
client.notifyListeners(RemoteClientConnected(client.module, client.remoteAddress))
log.slf4j.debug("Remote client connected to [{}]", ctx.getChannel.getRemoteAddress)
client.resetReconnectionTimeWindow
}
@ -482,16 +465,11 @@ class ActiveRemoteClientHandler(
override def channelDisconnected(ctx: ChannelHandlerContext, event: ChannelStateEvent) = {
client.notifyListeners(RemoteClientDisconnected(client.module, client.remoteAddress))
log.slf4j.debug("Remote client disconnected from [{}]", ctx.getChannel.getRemoteAddress)
}
override def exceptionCaught(ctx: ChannelHandlerContext, event: ExceptionEvent) = {
client.notifyListeners(RemoteClientError(event.getCause, client.module, client.remoteAddress))
if (event.getCause ne null)
log.slf4j.error("Unexpected exception from downstream in remote client", event.getCause)
else
log.slf4j.error("Unexpected exception from downstream in remote client: {}", event)
if (event.getCause ne null) event.getCause.printStackTrace
event.getChannel.close
}
@ -506,8 +484,6 @@ class ActiveRemoteClientHandler(
.newInstance(exception.getMessage).asInstanceOf[Throwable]
} catch {
case problem =>
log.debug("Couldn't parse exception returned from RemoteServer",problem)
log.warn("Couldn't create instance of {} with message {}, returning UnparsableException",classname, exception.getMessage)
UnparsableException(classname, exception.getMessage)
}
}
@ -579,7 +555,7 @@ class NettyRemoteServer(serverModule: NettyRemoteServerModule, val host: String,
serverModule.notifyListeners(RemoteServerShutdown(serverModule))
} catch {
case e: java.nio.channels.ClosedChannelException => {}
case e => serverModule.log.slf4j.warn("Could not close remote server channel in a graceful way")
case e => {}
}
}
}
@ -607,12 +583,10 @@ trait NettyRemoteServerModule extends RemoteServerModule { self: RemoteModule =>
def start(_hostname: String, _port: Int, loader: Option[ClassLoader] = None): RemoteServerModule = guard withGuard {
try {
_isRunning switchOn {
log.slf4j.debug("Starting up remote server on {}:{}",_hostname, _port)
currentServer.set(Some(new NettyRemoteServer(this, _hostname, _port, loader)))
}
} catch {
case e =>
log.slf4j.error("Could not start up remote server", e)
notifyListeners(RemoteServerError(e, this))
}
this
@ -622,7 +596,6 @@ trait NettyRemoteServerModule extends RemoteServerModule { self: RemoteModule =>
_isRunning switchOff {
currentServer.getAndSet(None) foreach {
instance =>
log.slf4j.debug("Shutting down remote server on {}:{}",instance.host, instance.port)
instance.shutdown
}
}
@ -634,7 +607,6 @@ trait NettyRemoteServerModule extends RemoteServerModule { self: RemoteModule =>
* @param typedActor typed actor to register
*/
def registerTypedActor(id: String, typedActor: AnyRef): Unit = guard withGuard {
log.slf4j.debug("Registering server side remote typed actor [{}] with id [{}]", typedActor.getClass.getName, id)
if (id.startsWith(UUID_PREFIX)) registerTypedActor(id.substring(UUID_PREFIX.length), typedActor, typedActorsByUuid)
else registerTypedActor(id, typedActor, typedActors)
}
@ -645,7 +617,6 @@ trait NettyRemoteServerModule extends RemoteServerModule { self: RemoteModule =>
* @param typedActor typed actor to register
*/
def registerTypedPerSessionActor(id: String, factory: => AnyRef): Unit = guard withGuard {
log.slf4j.debug("Registering server side typed remote session actor with id [{}]", id)
registerTypedPerSessionActor(id, () => factory, typedActorsFactories)
}
@ -655,13 +626,11 @@ trait NettyRemoteServerModule extends RemoteServerModule { self: RemoteModule =>
* NOTE: If you use this method to register your remote actor then you must unregister the actor by this ID yourself.
*/
def register(id: String, actorRef: ActorRef): Unit = guard withGuard {
log.slf4j.debug("Registering server side remote actor [{}] with id [{}]", actorRef.actorClass.getName, id)
if (id.startsWith(UUID_PREFIX)) register(id.substring(UUID_PREFIX.length), actorRef, actorsByUuid)
else register(id, actorRef, actors)
}
def registerByUuid(actorRef: ActorRef): Unit = guard withGuard {
log.slf4j.debug("Registering remote actor {} to it's uuid {}", actorRef, actorRef.uuid)
register(actorRef.uuid.toString, actorRef, actorsByUuid)
}
@ -678,7 +647,6 @@ trait NettyRemoteServerModule extends RemoteServerModule { self: RemoteModule =>
* NOTE: If you use this method to register your remote actor then you must unregister the actor by this ID yourself.
*/
def registerPerSession(id: String, factory: => ActorRef): Unit = synchronized {
log.slf4j.debug("Registering server side remote session actor with id [{}]", id)
registerPerSession(id, () => factory, actorsFactories)
}
@ -702,7 +670,6 @@ trait NettyRemoteServerModule extends RemoteServerModule { self: RemoteModule =>
*/
def unregister(actorRef: ActorRef): Unit = guard withGuard {
if (_isRunning.isOn) {
log.slf4j.debug("Unregistering server side remote actor [{}] with id [{}:{}]", Array[AnyRef](actorRef.actorClass.getName, actorRef.id, actorRef.uuid))
actors.remove(actorRef.id, actorRef)
actorsByUuid.remove(actorRef.uuid, actorRef)
}
@ -715,7 +682,6 @@ trait NettyRemoteServerModule extends RemoteServerModule { self: RemoteModule =>
*/
def unregister(id: String): Unit = guard withGuard {
if (_isRunning.isOn) {
log.slf4j.info("Unregistering server side remote actor with id [{}]", id)
if (id.startsWith(UUID_PREFIX)) actorsByUuid.remove(id.substring(UUID_PREFIX.length))
else {
val actorRef = actors get id
@ -732,7 +698,6 @@ trait NettyRemoteServerModule extends RemoteServerModule { self: RemoteModule =>
*/
def unregisterPerSession(id: String): Unit = {
if (_isRunning.isOn) {
log.slf4j.info("Unregistering server side remote session actor with id [{}]", id)
actorsFactories.remove(id)
}
}
@ -744,7 +709,6 @@ trait NettyRemoteServerModule extends RemoteServerModule { self: RemoteModule =>
*/
def unregisterTypedActor(id: String):Unit = guard withGuard {
if (_isRunning.isOn) {
log.slf4j.info("Unregistering server side remote typed actor with id [{}]", id)
if (id.startsWith(UUID_PREFIX)) typedActorsByUuid.remove(id.substring(UUID_PREFIX.length))
else typedActors.remove(id)
}
@ -818,7 +782,7 @@ class RemoteServerHandler(
val name: String,
val openChannels: ChannelGroup,
val applicationLoader: Option[ClassLoader],
val server: NettyRemoteServerModule) extends SimpleChannelUpstreamHandler with Logging {
val server: NettyRemoteServerModule) extends SimpleChannelUpstreamHandler {
import RemoteServerSettings._
val CHANNEL_INIT = "channel-init".intern
@ -855,7 +819,6 @@ class RemoteServerHandler(
val clientAddress = getClientAddress(ctx)
sessionActors.set(event.getChannel(), new ConcurrentHashMap[String, ActorRef]())
typedSessionActors.set(event.getChannel(), new ConcurrentHashMap[String, AnyRef]())
log.slf4j.debug("Remote client [{}] connected to [{}]", clientAddress, server.name)
if (SECURE) {
val sslHandler: SslHandler = ctx.getPipeline.get(classOf[SslHandler])
// Begin handshake.
@ -876,17 +839,16 @@ class RemoteServerHandler(
override def channelDisconnected(ctx: ChannelHandlerContext, event: ChannelStateEvent) = {
import scala.collection.JavaConversions.asScalaIterable
val clientAddress = getClientAddress(ctx)
log.slf4j.debug("Remote client [{}] disconnected from [{}]", clientAddress, server.name)
// stop all session actors
for (map <- Option(sessionActors.remove(event.getChannel));
actor <- asScalaIterable(map.values)) {
try { actor.stop } catch { case e: Exception => log.slf4j.warn("Couldn't stop {}",actor,e) }
try { actor.stop } catch { case e: Exception => }
}
// stop all typed session actors
for (map <- Option(typedSessionActors.remove(event.getChannel));
actor <- asScalaIterable(map.values)) {
try { TypedActor.stop(actor) } catch { case e: Exception => log.slf4j.warn("Couldn't stop {}",actor,e) }
try { TypedActor.stop(actor) } catch { case e: Exception => }
}
server.notifyListeners(RemoteServerClientDisconnected(server, clientAddress))
@ -894,13 +856,11 @@ class RemoteServerHandler(
override def channelClosed(ctx: ChannelHandlerContext, event: ChannelStateEvent) = {
val clientAddress = getClientAddress(ctx)
log.slf4j.debug("Remote client [{}] channel closed from [{}]", clientAddress, server.name)
server.notifyListeners(RemoteServerClientClosed(server, clientAddress))
}
override def handleUpstream(ctx: ChannelHandlerContext, event: ChannelEvent) = {
if (event.isInstanceOf[ChannelStateEvent] && event.asInstanceOf[ChannelStateEvent].getState != ChannelState.INTEREST_OPS) {
log.slf4j.debug(event.toString)
}
super.handleUpstream(ctx, event)
}
@ -914,7 +874,6 @@ class RemoteServerHandler(
}
override def exceptionCaught(ctx: ChannelHandlerContext, event: ExceptionEvent) = {
log.slf4j.error("Unexpected exception from remote downstream", event.getCause)
event.getChannel.close
server.notifyListeners(RemoteServerError(event.getCause, server))
}
@ -926,7 +885,6 @@ class RemoteServerHandler(
}
private def handleRemoteMessageProtocol(request: RemoteMessageProtocol, channel: Channel) = {
log.slf4j.debug("Received RemoteMessageProtocol[\n{}]",request)
request.getActorInfo.getActorType match {
case SCALA_ACTOR => dispatchToActor(request, channel)
case TYPED_ACTOR => dispatchToTypedActor(request, channel)
@ -937,7 +895,6 @@ class RemoteServerHandler(
private def dispatchToActor(request: RemoteMessageProtocol, channel: Channel) {
val actorInfo = request.getActorInfo
log.slf4j.debug("Dispatching to remote actor [{}:{}]", actorInfo.getTarget, actorInfo.getUuid)
val actorRef =
try { createActor(actorInfo, channel).start } catch {
@ -967,16 +924,13 @@ class RemoteServerHandler(
None,
Some(new DefaultCompletableFuture[AnyRef](request.getActorInfo.getTimeout).
onComplete(f => {
log.slf4j.debug("Future was completed, now flushing to remote!")
val result = f.result
val exception = f.exception
if (exception.isDefined) {
log.slf4j.debug("Returning exception from actor invocation [{}]",exception.get.getClass)
write(channel, createErrorReplyMessage(exception.get, request, AkkaActorType.ScalaActor))
}
else if (result.isDefined) {
log.slf4j.debug("Returning result from actor invocation [{}]",result.get)
val messageBuilder = RemoteActorSerialization.createRemoteMessageProtocolBuilder(
Some(actorRef),
Right(request.getUuid),
@ -1004,7 +958,6 @@ class RemoteServerHandler(
private def dispatchToTypedActor(request: RemoteMessageProtocol, channel: Channel) = {
val actorInfo = request.getActorInfo
val typedActorInfo = actorInfo.getTypedActorInfo
log.slf4j.debug("Dispatching to remote typed actor [{} :: {}]", typedActorInfo.getMethod, typedActorInfo.getInterface)
val typedActor = createTypedActor(actorInfo, channel)
val args = MessageSerializer.deserialize(request.getMessage).asInstanceOf[Array[AnyRef]].toList
@ -1031,7 +984,6 @@ class RemoteServerHandler(
if (request.hasSupervisorUuid) messageBuilder.setSupervisorUuid(request.getSupervisorUuid)
write(channel, messageBuilder.build)
log.slf4j.debug("Returning result from remote typed actor invocation [{}]", result)
} catch {
case e: Throwable => server.notifyListeners(RemoteServerError(e, server))
}
@ -1100,7 +1052,6 @@ class RemoteServerHandler(
if (UNTRUSTED_MODE) throw new SecurityException(
"Remote server is operating is untrusted mode, can not create remote actors on behalf of the remote client")
log.slf4j.info("Creating a new client-managed remote actor [{}:{}]", name, uuid)
val clazz = if (applicationLoader.isDefined) applicationLoader.get.loadClass(name)
else Class.forName(name)
val actorRef = Actor.actorOf(clazz.asInstanceOf[Class[_ <: Actor]])
@ -1111,7 +1062,6 @@ class RemoteServerHandler(
actorRef
} catch {
case e =>
log.slf4j.error("Could not create remote actor instance", e)
server.notifyListeners(RemoteServerError(e, server))
throw e
}
@ -1167,8 +1117,6 @@ class RemoteServerHandler(
if (UNTRUSTED_MODE) throw new SecurityException(
"Remote server is operating is untrusted mode, can not create remote actors on behalf of the remote client")
log.slf4j.info("Creating a new remote typed actor:\n\t[{} :: {}]", interfaceClassname, targetClassname)
val (interfaceClass, targetClass) =
if (applicationLoader.isDefined) (applicationLoader.get.loadClass(interfaceClassname),
applicationLoader.get.loadClass(targetClassname))
@ -1180,7 +1128,6 @@ class RemoteServerHandler(
newInstance
} catch {
case e =>
log.slf4j.error("Could not create remote typed actor instance", e)
server.notifyListeners(RemoteServerError(e, server))
throw e
}
@ -1201,8 +1148,6 @@ class RemoteServerHandler(
private def createErrorReplyMessage(exception: Throwable, request: RemoteMessageProtocol, actorType: AkkaActorType): RemoteMessageProtocol = {
val actorInfo = request.getActorInfo
log.slf4j.error("Could not invoke remote actor [{}]", actorInfo.getTarget)
log.slf4j.debug("Could not invoke remote actor", exception)
val messageBuilder = RemoteActorSerialization.createRemoteMessageProtocolBuilder(
None,
Right(request.getUuid),
@ -1230,7 +1175,6 @@ class RemoteServerHandler(
"The remote client [" + clientAddress + "] does not have a secure cookie.")
if (!(request.getCookie == SECURE_COOKIE.get)) throw new SecurityException(
"The remote client [" + clientAddress + "] secure cookie is not the same as remote server secure cookie")
log.slf4j.info("Remote client [{}] successfully authenticated using secure cookie", clientAddress)
}
}

View file

@ -170,7 +170,6 @@ object ActorSerialization {
private[akka] def fromProtobufToLocalActorRef[T <: Actor](
protocol: SerializedActorRefProtocol, format: Format[T], loader: Option[ClassLoader]): ActorRef = {
Actor.log.slf4j.debug("Deserializing SerializedActorRefProtocol to LocalActorRef:\n" + protocol)
val serializer =
if (format.isInstanceOf[SerializerBasedActorFormat[_]])
@ -248,7 +247,6 @@ object RemoteActorSerialization {
* Deserializes a RemoteActorRefProtocol Protocol Buffers (protobuf) Message into an RemoteActorRef instance.
*/
private[akka] def fromProtobufToRemoteActorRef(protocol: RemoteActorRefProtocol, loader: Option[ClassLoader]): ActorRef = {
Actor.log.slf4j.debug("Deserializing RemoteActorRefProtocol to RemoteActorRef:\n {}", protocol)
val ref = RemoteActorRef(
protocol.getClassOrServiceName,
protocol.getActorClassname,
@ -256,8 +254,6 @@ object RemoteActorSerialization {
protocol.getHomeAddress.getPort,
protocol.getTimeout,
loader)
Actor.log.slf4j.debug("Newly deserialized RemoteActorRef has uuid: {}", ref.uuid)
ref
}
@ -267,8 +263,6 @@ object RemoteActorSerialization {
def toRemoteActorRefProtocol(ar: ActorRef): RemoteActorRefProtocol = {
import ar._
Actor.log.slf4j.debug("Register serialized Actor [{}] as remote @ [{}:{}]",actorClassName, ar.homeAddress)
Actor.remote.registerByUuid(ar)
RemoteActorRefProtocol.newBuilder
@ -396,7 +390,6 @@ object TypedActorSerialization {
private def fromProtobufToLocalTypedActorRef[T <: Actor, U <: AnyRef](
protocol: SerializedTypedActorRefProtocol, format: Format[T], loader: Option[ClassLoader]): U = {
Actor.log.slf4j.debug("Deserializing SerializedTypedActorRefProtocol to LocalActorRef:\n" + protocol)
val actorRef = ActorSerialization.fromProtobufToLocalActorRef(protocol.getActorRef, format, loader)
val intfClass = toClass(loader, protocol.getInterfaceName)
TypedActor.newInstance(intfClass, actorRef).asInstanceOf[U]
@ -436,7 +429,6 @@ object RemoteTypedActorSerialization {
* Deserializes a RemoteTypedActorRefProtocol Protocol Buffers (protobuf) Message into AW RemoteActorRef proxy.
*/
private[akka] def fromProtobufToRemoteTypedActorRef[T](protocol: RemoteTypedActorRefProtocol, loader: Option[ClassLoader]): T = {
Actor.log.slf4j.debug("Deserializing RemoteTypedActorRefProtocol to AW RemoteActorRef proxy:\n" + protocol)
val actorRef = RemoteActorSerialization.fromProtobufToRemoteActorRef(protocol.getActorRef, loader)
val intfClass = TypedActorSerialization.toClass(loader, protocol.getInterfaceName)
TypedActor.createProxyForRemoteActorRef(intfClass, actorRef).asInstanceOf[T]

View file

@ -1,7 +1,6 @@
package akka.actor.remote
import akka.actor.{Actor, ActorRegistry}
import akka.util.Logging
import Actor._
@ -41,11 +40,10 @@ object ServerInitiatedRemoteActorServer {
}
}
object ServerInitiatedRemoteActorClient extends Logging {
object ServerInitiatedRemoteActorClient {
def main(args: Array[String]) = {
val actor = Actor.remote.actorFor("hello-service", "localhost", 2552)
val result = actor !! "Hello"
log.slf4j.info("Result from Remote Actor: {}", result)
}
}

View file

@ -78,7 +78,7 @@ class Hakker(name: String,left: ActorRef, right: ActorRef) extends Actor {
//back to think about how he should obtain his chopsticks :-)
def waiting_for(chopstickToWaitFor: ActorRef, otherChopstick: ActorRef): Receive = {
case Taken(`chopstickToWaitFor`) =>
log.info("%s has picked up %s and %s, and starts to eat",name,left.id,right.id)
println("%s has picked up %s and %s, and starts to eat",name,left.id,right.id)
become(eating)
Scheduler.scheduleOnce(self,Think,5,TimeUnit.SECONDS)
@ -108,14 +108,14 @@ class Hakker(name: String,left: ActorRef, right: ActorRef) extends Actor {
become(thinking)
left ! Put(self)
right ! Put(self)
log.info("%s puts down his chopsticks and starts to think",name)
println("%s puts down his chopsticks and starts to think",name)
Scheduler.scheduleOnce(self,Eat,5,TimeUnit.SECONDS)
}
//All hakkers start in a non-eating state
def receive = {
case Think =>
log.info("%s starts to think",name)
println("%s starts to think",name)
become(thinking)
Scheduler.scheduleOnce(self,Eat,5,TimeUnit.SECONDS)
}

View file

@ -89,7 +89,7 @@ class FSMHakker(name: String, left: ActorRef, right: ActorRef) extends Actor wit
when(Waiting) {
case Event(Think, _) =>
log.info("%s starts to think", name)
println("%s starts to think", name)
startThinking(5 seconds)
}
@ -128,7 +128,7 @@ class FSMHakker(name: String, left: ActorRef, right: ActorRef) extends Actor wit
}
private def startEating(left: ActorRef, right: ActorRef): State = {
log.info("%s has picked up %s and %s, and starts to eat", name, left.id, right.id)
println("%s has picked up %s and %s, and starts to eat", name, left.id, right.id)
goto(Eating) using TakenChopsticks(Some(left), Some(right)) forMax (5 seconds)
}
@ -147,7 +147,7 @@ class FSMHakker(name: String, left: ActorRef, right: ActorRef) extends Actor wit
// then he puts down his chopsticks and starts to think
when(Eating) {
case Event(StateTimeout, _) =>
log.info("%s puts down his chopsticks and starts to think", name)
println("%s puts down his chopsticks and starts to think", name)
left ! Put
right ! Put
startThinking(5 seconds)

View file

@ -5,35 +5,29 @@
package sample.remote
import akka.actor.Actor._
import akka.util.Logging
import akka.actor. {ActorRegistry, Actor}
import Actor.remote
class RemoteHelloWorldActor extends Actor {
def receive = {
case "Hello" =>
log.slf4j.info("Received 'Hello'")
self.reply("World")
}
}
object ClientManagedRemoteActorServer extends Logging {
object ClientManagedRemoteActorServer {
def run = {
remote.start("localhost", 2552)
log.slf4j.info("Remote node started")
}
def main(args: Array[String]) = run
}
object ClientManagedRemoteActorClient extends Logging {
object ClientManagedRemoteActorClient {
def run = {
val actor = remote.actorOf[RemoteHelloWorldActor]("localhost",2552).start
log.slf4j.info("Remote actor created, moved to the server")
log.slf4j.info("Sending 'Hello' to remote actor")
val result = actor !! "Hello"
log.slf4j.info("Result from Remote Actor: '{}'", result.get)
}
def main(args: Array[String]) = run

View file

@ -5,37 +5,30 @@
package sample.remote
import akka.actor.Actor._
import akka.util.Logging
import akka.actor. {ActorRegistry, Actor}
class HelloWorldActor extends Actor {
def receive = {
case "Hello" =>
log.slf4j.info("Received 'Hello'")
self.reply("World")
}
}
object ServerManagedRemoteActorServer extends Logging {
object ServerManagedRemoteActorServer {
def run = {
Actor.remote.start("localhost", 2552)
log.slf4j.info("Remote node started")
Actor.remote.register("hello-service", actorOf[HelloWorldActor])
log.slf4j.info("Remote actor registered and started")
}
def main(args: Array[String]) = run
}
object ServerManagedRemoteActorClient extends Logging {
object ServerManagedRemoteActorClient {
def run = {
val actor = Actor.remote.actorFor("hello-service", "localhost", 2552)
log.slf4j.info("Remote client created")
log.slf4j.info("Sending 'Hello' to remote actor")
val result = actor !! "Hello"
log.slf4j.info("Result from Remote Actor: '{}'", result.get)
}
def main(args: Array[String]) = run

View file

@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicInteger
import scala.collection.mutable.HashMap
import akka.util.{Logging, ReflectiveAccess}
import akka.util.ReflectiveAccess
import akka.config.Config._
import akka.config.ModuleNotAvailableException
import akka.AkkaException
@ -88,7 +88,7 @@ object Transaction {
* The Akka-specific Transaction class.
* For integration with persistence modules and JTA support.
*/
@serializable class Transaction extends Logging {
@serializable class Transaction {
val JTA_AWARE = config.getBool("akka.stm.jta-aware", false)
val STATE_RETRIES = config.getInt("akka.storage.max-retries",10)
@ -102,17 +102,13 @@ object Transaction {
if (JTA_AWARE) Some(ReflectiveJtaModule.createTransactionContainer)
else None
log.slf4j.trace("Creating transaction " + toString)
// --- public methods ---------
def begin = synchronized {
log.slf4j.trace("Starting transaction " + toString)
jta.foreach { _.beginWithStmSynchronization(this) }
}
def commitPersistentState = synchronized {
log.trace("Committing transaction " + toString)
retry(STATE_RETRIES){
persistentStateMap.valuesIterator.foreach(_.commit)
persistentStateMap.clear
@ -125,14 +121,12 @@ object Transaction {
}
def abort = synchronized {
log.slf4j.trace("Aborting transaction " + toString)
jta.foreach(_.rollback)
persistentStateMap.valuesIterator.foreach(_.abort)
persistentStateMap.clear
}
def retry(tries:Int)(block: => Unit):Unit={
log.debug("Trying commit of persistent data structures")
if(tries==0){
throw new TransactionRetryException("Exhausted Retries while committing persistent state")
}
@ -140,7 +134,6 @@ object Transaction {
block
} catch{
case e:Exception=>{
log.warn(e,"Exception while committing persistent state, retrying")
retry(tries-1){block}
}
}
@ -169,8 +162,6 @@ object Transaction {
//have no possibility of kicking a diffferent type with the same uuid out of a transction
private[akka] def register(uuid: String, storage: Committable with Abortable) = {
if(persistentStateMap.getOrElseUpdate(uuid, {storage}) ne storage){
log.error("existing:"+System.identityHashCode(persistentStateMap.get(uuid).get))
log.error("new:"+System.identityHashCode(storage))
throw new IllegalStateException("attempted to register an instance of persistent data structure for id [%s] when there is already a different instance registered".format(uuid))
}
}

View file

@ -18,7 +18,6 @@ object CoordinatedIncrement {
implicit val txFactory = TransactionFactory(timeout = 3 seconds)
def increment = {
log.slf4j.info(name + ": incrementing")
count alter (_ + 1)
}

View file

@ -26,7 +26,6 @@ object FickleFriends {
implicit val txFactory = TransactionFactory(timeout = 3 seconds)
def increment = {
log.slf4j.info(name + ": incrementing")
count alter (_ + 1)
}
@ -65,7 +64,6 @@ object FickleFriends {
implicit val txFactory = TransactionFactory(timeout = 3 seconds)
def increment = {
log.slf4j.info(name + ": incrementing")
count alter (_ + 1)
}

View file

@ -20,7 +20,6 @@ object TransactorIncrement {
override def transactionFactory = TransactionFactory(timeout = 3 seconds)
def increment = {
log.slf4j.info(name + ": incrementing")
count alter (_ + 1)
}
@ -32,7 +31,7 @@ object TransactorIncrement {
}
override def before = {
case i: Increment => log.slf4j.info(name + ": before transaction")
case i: Increment =>
}
def atomically = {
@ -44,7 +43,7 @@ object TransactorIncrement {
}
override def after = {
case i: Increment => log.slf4j.info(name + ": after transaction")
case i: Increment =>
}
override def normally = {

View file

@ -431,7 +431,7 @@ trait TypedActorFactory {
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
object TypedActor extends Logging {
object TypedActor {
import Actor.actorOf
val ZERO_ITEM_CLASS_ARRAY = Array[Class[_]]()
@ -576,8 +576,6 @@ object TypedActor extends Logging {
actorRef.timeout = config.timeout
//log.slf4j.debug("config._host for {} is {} but homeAddress is {} and on ref {}",Array[AnyRef](intfClass, config._host, typedActor.context.homeAddress,actorRef.homeAddress))
val remoteAddress = actorRef match {
case remote: RemoteActorRef => remote.homeAddress
case local: LocalActorRef if local.clientManaged => local.homeAddress

View file

@ -24,7 +24,7 @@ import com.google.inject._
*
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
private[akka] class TypedActorGuiceConfigurator extends TypedActorConfiguratorBase with Logging {
private[akka] class TypedActorGuiceConfigurator extends TypedActorConfiguratorBase {
private var injector: Injector = _
private var supervisor: Option[Supervisor] = None
private var faultHandlingStrategy: FaultHandlingStrategy = NoFaultHandlingStrategy
@ -43,7 +43,6 @@ private[akka] class TypedActorGuiceConfigurator extends TypedActorConfiguratorBa
* @return the typed actors for the class
*/
def getInstance[T](clazz: Class[T]): List[T] = synchronized {
log.slf4j.debug("Retrieving typed actor [{}]", clazz.getName)
if (injector eq null) throw new IllegalActorStateException(
"inject() and/or supervise() must be called before invoking getInstance(clazz)")
val (proxy, targetInstance, component) =

View file

@ -26,7 +26,7 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
val javaCompileSettings = Seq("-Xlint:unchecked")
override def compileOptions = super.compileOptions ++ scalaCompileSettings.map(CompileOption)
override def compileOptions = super.compileOptions ++ scalaCompileSettings.map(CompileOption)
override def javaCompileOptions = super.javaCompileOptions ++ javaCompileSettings.map(JavaCompileOption)
// -------------------------------------------------------------------------------------------------------------------
@ -103,7 +103,6 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
lazy val multiverseModuleConfig = ModuleConfiguration("org.multiverse", CodehausRepo)
lazy val nettyModuleConfig = ModuleConfiguration("org.jboss.netty", JBossRepo)
lazy val scalaTestModuleConfig = ModuleConfiguration("org.scalatest", ScalaToolsRelRepo)
lazy val logbackModuleConfig = ModuleConfiguration("ch.qos.logback", sbt.DefaultMavenRepository)
lazy val spdeModuleConfig = ModuleConfiguration("us.technically.spde", DatabinderRepo)
lazy val processingModuleConfig = ModuleConfiguration("org.processing", DatabinderRepo)
lazy val scalazModuleConfig = ModuleConfiguration("org.scalaz", ScalaToolsSnapshotRepo)
@ -118,12 +117,9 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
lazy val JERSEY_VERSION = "1.3"
lazy val MULTIVERSE_VERSION = "0.6.2"
lazy val SCALATEST_VERSION = "1.3"
lazy val LOGBACK_VERSION = "0.9.24"
lazy val SLF4J_VERSION = "1.6.0"
lazy val JETTY_VERSION = "7.1.6.v20100715"
lazy val JAVAX_SERVLET_VERSION = "3.0"
// -------------------------------------------------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------------------------------------------------
@ -189,8 +185,6 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
lazy val sjson = "net.debasishg" % "sjson_2.8.1" % "0.9" % "compile" //ApacheV2
lazy val sjson_test = "net.debasishg" % "sjson_2.8.1" % "0.9" % "test" //ApacheV2
lazy val logback = "ch.qos.logback" % "logback-classic" % LOGBACK_VERSION % "compile" //LGPL 2.1
lazy val stax_api = "javax.xml.stream" % "stax-api" % "1.0-2" % "compile" //ApacheV2
lazy val thrift = "com.facebook" % "thrift" % "r917130" % "compile" //ApacheV2
@ -326,7 +320,6 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
val configgy = Dependencies.configgy
val hawtdispatch = Dependencies.hawtdispatch
val jsr166x = Dependencies.jsr166x
val logback = Dependencies.logback
// testing
val junit = Dependencies.junit