Merge pull request #782 from akka/wip-null-is-not-tasty-√
Changing the default sender of ! to be Actor.noSender to keep null in on...
This commit is contained in:
commit
5b0a2ec7ee
11 changed files with 19 additions and 14 deletions
|
|
@ -300,6 +300,11 @@ object Actor {
|
||||||
def apply(x: Any) = throw new UnsupportedOperationException("Empty behavior apply()")
|
def apply(x: Any) = throw new UnsupportedOperationException("Empty behavior apply()")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default placeholder (null) used for "!" to indicate that there is no sender of the message,
|
||||||
|
* that will be translated to the receiving system's deadLetters.
|
||||||
|
*/
|
||||||
|
final val noSender: ActorRef = null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ trait ScalaActorRef { ref: ActorRef ⇒
|
||||||
* </pre>
|
* </pre>
|
||||||
* <p/>
|
* <p/>
|
||||||
*/
|
*/
|
||||||
def !(message: Any)(implicit sender: ActorRef = null): Unit
|
def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -341,7 +341,7 @@ private[akka] class LocalActorRef private[akka] (
|
||||||
|
|
||||||
override def sendSystemMessage(message: SystemMessage): Unit = actorCell.sendSystemMessage(message)
|
override def sendSystemMessage(message: SystemMessage): Unit = actorCell.sendSystemMessage(message)
|
||||||
|
|
||||||
override def !(message: Any)(implicit sender: ActorRef = null): Unit = actorCell.tell(message, sender)
|
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = actorCell.tell(message, sender)
|
||||||
|
|
||||||
override def restart(cause: Throwable): Unit = actorCell.restart(cause)
|
override def restart(cause: Throwable): Unit = actorCell.restart(cause)
|
||||||
|
|
||||||
|
|
@ -395,7 +395,7 @@ private[akka] trait MinimalActorRef extends InternalActorRef with LocalRef {
|
||||||
override def stop(): Unit = ()
|
override def stop(): Unit = ()
|
||||||
override def isTerminated = false
|
override def isTerminated = false
|
||||||
|
|
||||||
override def !(message: Any)(implicit sender: ActorRef = null): Unit = ()
|
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = ()
|
||||||
|
|
||||||
override def sendSystemMessage(message: SystemMessage): Unit = ()
|
override def sendSystemMessage(message: SystemMessage): Unit = ()
|
||||||
override def restart(cause: Throwable): Unit = ()
|
override def restart(cause: Throwable): Unit = ()
|
||||||
|
|
@ -435,7 +435,7 @@ private[akka] class EmptyLocalActorRef(override val provider: ActorRefProvider,
|
||||||
|
|
||||||
override def sendSystemMessage(message: SystemMessage): Unit = specialHandle(message)
|
override def sendSystemMessage(message: SystemMessage): Unit = specialHandle(message)
|
||||||
|
|
||||||
override def !(message: Any)(implicit sender: ActorRef = null): Unit = message match {
|
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = message match {
|
||||||
case d: DeadLetter ⇒ specialHandle(d.message) // do NOT form endless loops, since deadLetters will resend!
|
case d: DeadLetter ⇒ specialHandle(d.message) // do NOT form endless loops, since deadLetters will resend!
|
||||||
case _ ⇒ if (!specialHandle(message)) eventStream.publish(DeadLetter(message, sender, this))
|
case _ ⇒ if (!specialHandle(message)) eventStream.publish(DeadLetter(message, sender, this))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,7 @@ class LocalActorRefProvider(
|
||||||
override def stop(): Unit = stopped switchOn { terminationPromise.complete(causeOfTermination.map(Failure(_)).getOrElse(Success(()))) }
|
override def stop(): Unit = stopped switchOn { terminationPromise.complete(causeOfTermination.map(Failure(_)).getOrElse(Success(()))) }
|
||||||
override def isTerminated: Boolean = stopped.isOn
|
override def isTerminated: Boolean = stopped.isOn
|
||||||
|
|
||||||
override def !(message: Any)(implicit sender: ActorRef = null): Unit = stopped.ifOff(message match {
|
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = stopped.ifOff(message match {
|
||||||
case Failed(ex, _) if sender ne null ⇒ causeOfTermination = Some(ex); sender.asInstanceOf[InternalActorRef].stop()
|
case Failed(ex, _) if sender ne null ⇒ causeOfTermination = Some(ex); sender.asInstanceOf[InternalActorRef].stop()
|
||||||
case NullMessage ⇒ // do nothing
|
case NullMessage ⇒ // do nothing
|
||||||
case _ ⇒ log.error(this + " received unexpected message [" + message + "]")
|
case _ ⇒ log.error(this + " received unexpected message [" + message + "]")
|
||||||
|
|
|
||||||
|
|
@ -70,5 +70,5 @@ object ActorSelection {
|
||||||
trait ScalaActorSelection {
|
trait ScalaActorSelection {
|
||||||
this: ActorSelection ⇒
|
this: ActorSelection ⇒
|
||||||
|
|
||||||
def !(msg: Any)(implicit sender: ActorRef = null) = tell(msg, sender)
|
def !(msg: Any)(implicit sender: ActorRef = Actor.noSender) = tell(msg, sender)
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +112,7 @@ private[akka] class RepointableActorRef(
|
||||||
}
|
}
|
||||||
} else this
|
} else this
|
||||||
|
|
||||||
def !(message: Any)(implicit sender: ActorRef = null) = underlying.tell(message, sender)
|
def !(message: Any)(implicit sender: ActorRef = Actor.noSender) = underlying.tell(message, sender)
|
||||||
|
|
||||||
def sendSystemMessage(message: SystemMessage) = underlying.sendSystemMessage(message)
|
def sendSystemMessage(message: SystemMessage) = underlying.sendSystemMessage(message)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -708,7 +708,7 @@ object Logging {
|
||||||
val path: ActorPath = new RootActorPath(Address("akka", "all-systems"), "/StandardOutLogger")
|
val path: ActorPath = new RootActorPath(Address("akka", "all-systems"), "/StandardOutLogger")
|
||||||
def provider: ActorRefProvider = throw new UnsupportedOperationException("StandardOutLogger does not provide")
|
def provider: ActorRefProvider = throw new UnsupportedOperationException("StandardOutLogger does not provide")
|
||||||
override val toString = "StandardOutLogger"
|
override val toString = "StandardOutLogger"
|
||||||
override def !(message: Any)(implicit sender: ActorRef = null): Unit = print(message)
|
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = print(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
val StandardOutLogger = new StandardOutLogger
|
val StandardOutLogger = new StandardOutLogger
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ private[akka] final class PromiseActorRef private (val provider: ActorRefProvide
|
||||||
case Registering ⇒ path // spin until registration is completed
|
case Registering ⇒ path // spin until registration is completed
|
||||||
}
|
}
|
||||||
|
|
||||||
override def !(message: Any)(implicit sender: ActorRef = null): Unit = state match {
|
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = state match {
|
||||||
case Stopped | _: StoppedWithPath ⇒ provider.deadLetters ! message
|
case Stopped | _: StoppedWithPath ⇒ provider.deadLetters ! message
|
||||||
case _ ⇒ if (!(result.tryComplete(
|
case _ ⇒ if (!(result.tryComplete(
|
||||||
message match {
|
message match {
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,12 @@ import language.implicitConversions
|
||||||
|
|
||||||
import scala.concurrent.{ Future, ExecutionContext }
|
import scala.concurrent.{ Future, ExecutionContext }
|
||||||
import scala.util.{ Failure, Success }
|
import scala.util.{ Failure, Success }
|
||||||
import akka.actor.{ Status, ActorRef }
|
import akka.actor.{ Status, ActorRef, Actor }
|
||||||
|
|
||||||
trait PipeToSupport {
|
trait PipeToSupport {
|
||||||
|
|
||||||
final class PipeableFuture[T](val future: Future[T])(implicit executionContext: ExecutionContext) {
|
final class PipeableFuture[T](val future: Future[T])(implicit executionContext: ExecutionContext) {
|
||||||
def pipeTo(recipient: ActorRef)(implicit sender: ActorRef = null): Future[T] = {
|
def pipeTo(recipient: ActorRef)(implicit sender: ActorRef = Actor.noSender): Future[T] = {
|
||||||
future onComplete {
|
future onComplete {
|
||||||
case Success(r) ⇒ recipient ! r
|
case Success(r) ⇒ recipient ! r
|
||||||
case Failure(f) ⇒ recipient ! Status.Failure(f)
|
case Failure(f) ⇒ recipient ! Status.Failure(f)
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ trait Listeners { self: Actor ⇒
|
||||||
* @param msg
|
* @param msg
|
||||||
* @param sender
|
* @param sender
|
||||||
*/
|
*/
|
||||||
protected def gossip(msg: Any)(implicit sender: ActorRef = null): Unit = {
|
protected def gossip(msg: Any)(implicit sender: ActorRef = Actor.noSender): Unit = {
|
||||||
val i = listeners.iterator
|
val i = listeners.iterator
|
||||||
while (i.hasNext) i.next ! msg
|
while (i.hasNext) i.next ! msg
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ private[akka] class RemoteActorRef private[akka] (
|
||||||
provider.deadLetters ! message
|
provider.deadLetters ! message
|
||||||
}
|
}
|
||||||
|
|
||||||
override def !(message: Any)(implicit sender: ActorRef = null): Unit =
|
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit =
|
||||||
try remote.send(message, Option(sender), this)
|
try remote.send(message, Option(sender), this)
|
||||||
catch {
|
catch {
|
||||||
case e @ (_: InterruptedException | NonFatal(_)) ⇒
|
case e @ (_: InterruptedException | NonFatal(_)) ⇒
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ private[akka] class RemoteSystemDaemon(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def !(msg: Any)(implicit sender: ActorRef = null): Unit = msg match {
|
override def !(msg: Any)(implicit sender: ActorRef = Actor.noSender): Unit = msg match {
|
||||||
case message: DaemonMsg ⇒
|
case message: DaemonMsg ⇒
|
||||||
log.debug("Received command [{}] to RemoteSystemDaemon on [{}]", message, path.address)
|
log.debug("Received command [{}] to RemoteSystemDaemon on [{}]", message, path.address)
|
||||||
message match {
|
message match {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue