incorporate review comments
This commit is contained in:
parent
13eb1b6c8b
commit
3c06992d2e
7 changed files with 38 additions and 49 deletions
|
|
@ -102,7 +102,7 @@ private[akka] class ActorCell(
|
|||
var childrenRefs: TreeMap[String, ChildRestartStats] = emptyChildrenRefs
|
||||
|
||||
def actorOf(props: Props, name: String): ActorRef = {
|
||||
if (name == null || name == "" || name.startsWith("$"))
|
||||
if (name == null || name == "" || name.charAt(0) == '$')
|
||||
throw new InvalidActorNameException("actor name must not be null, empty or start with $")
|
||||
if (childrenRefs contains name)
|
||||
throw new InvalidActorNameException("actor name " + name + " is not unique!")
|
||||
|
|
|
|||
|
|
@ -5,15 +5,11 @@ package akka.actor
|
|||
import scala.annotation.tailrec
|
||||
|
||||
object ActorPath {
|
||||
// this cannot really be changed due to usage of standard URI syntax
|
||||
final val separator = "/"
|
||||
final val sepLen = separator.length
|
||||
|
||||
def split(s: String): List[String] = {
|
||||
@tailrec
|
||||
def rec(pos: Int, acc: List[String]): List[String] = {
|
||||
val from = s.lastIndexOf(separator, pos - 1)
|
||||
val sub = s.substring(from + sepLen, pos)
|
||||
val from = s.lastIndexOf('/', pos - 1)
|
||||
val sub = s.substring(from + 1, pos)
|
||||
val l = sub :: acc
|
||||
if (from == -1) l else rec(from, l)
|
||||
}
|
||||
|
|
@ -74,7 +70,7 @@ sealed trait ActorPath extends Comparable[ActorPath] {
|
|||
* Root of the hierarchy of ActorPaths. There is exactly root per ActorSystem
|
||||
* and node (for remote-enabled or clustered systems).
|
||||
*/
|
||||
final case class RootActorPath(address: Address, name: String = ActorPath.separator) extends ActorPath {
|
||||
final case class RootActorPath(address: Address, name: String = "/") extends ActorPath {
|
||||
|
||||
def parent: ActorPath = this
|
||||
|
||||
|
|
@ -124,12 +120,11 @@ final class ChildActorPath(val parent: ActorPath, val name: String) extends Acto
|
|||
*/
|
||||
override def toString = {
|
||||
@tailrec
|
||||
def rec(p: ActorPath, s: String): String = p match {
|
||||
case r: RootActorPath ⇒ r + s
|
||||
case _ if s.isEmpty ⇒ rec(p.parent, name)
|
||||
case _ ⇒ rec(p.parent, p.name + ActorPath.separator + s)
|
||||
def rec(p: ActorPath, s: StringBuilder): StringBuilder = p match {
|
||||
case r: RootActorPath ⇒ s.insert(0, r.toString)
|
||||
case _ ⇒ rec(p.parent, s.insert(0, '/').insert(0, p.name))
|
||||
}
|
||||
rec(this, "")
|
||||
rec(parent, new StringBuilder(32).append(name)).toString
|
||||
}
|
||||
|
||||
override def equals(other: Any): Boolean = {
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ abstract class ActorRef extends java.lang.Comparable[ActorRef] with Serializable
|
|||
/**
|
||||
* Comparison only takes address into account.
|
||||
*/
|
||||
def compareTo(other: ActorRef) = this.path compareTo other.path
|
||||
final def compareTo(other: ActorRef) = this.path compareTo other.path
|
||||
|
||||
/**
|
||||
* Sends the specified message to the sender, i.e. fire-and-forget semantics.<p/>
|
||||
|
|
@ -112,9 +112,9 @@ abstract class ActorRef extends java.lang.Comparable[ActorRef] with Serializable
|
|||
def isTerminated: Boolean
|
||||
|
||||
// FIXME RK check if we should scramble the bits or whether they can stay the same
|
||||
override def hashCode: Int = path.hashCode
|
||||
final override def hashCode: Int = path.hashCode
|
||||
|
||||
override def equals(that: Any): Boolean = that match {
|
||||
final override def equals(that: Any): Boolean = that match {
|
||||
case other: ActorRef ⇒ path == other.path
|
||||
case _ ⇒ false
|
||||
}
|
||||
|
|
@ -161,6 +161,8 @@ trait ScalaActorRef { ref: ActorRef ⇒
|
|||
/**
|
||||
* Internal trait for assembling all the functionality needed internally on
|
||||
* ActorRefs. NOTE THAT THIS IS NOT A STABLE EXTERNAL INTERFACE!
|
||||
*
|
||||
* DO NOT USE THIS UNLESS INTERNALLY WITHIN AKKA!
|
||||
*/
|
||||
private[akka] abstract class InternalActorRef extends ActorRef with ScalaActorRef {
|
||||
def resume(): Unit
|
||||
|
|
@ -412,7 +414,7 @@ class AskActorRef(
|
|||
result onTimeout callback
|
||||
}
|
||||
|
||||
protected def whenDone(): Unit = {}
|
||||
protected def whenDone(): Unit = ()
|
||||
|
||||
override def !(message: Any)(implicit sender: ActorRef = null): Unit = message match {
|
||||
case Status.Success(r) ⇒ result.completeWithResult(r)
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ trait ActorRefProvider {
|
|||
* and then—when the ActorSystem is constructed—the second phase during
|
||||
* which actors may be created (e.g. the guardians).
|
||||
*/
|
||||
def init(system: ActorSystemImpl)
|
||||
def init(system: ActorSystemImpl): Unit
|
||||
|
||||
private[akka] def deployer: Deployer
|
||||
|
||||
|
|
@ -293,6 +293,9 @@ trait ActorRefFactory {
|
|||
|
||||
class ActorRefProviderException(message: String) extends AkkaException(message)
|
||||
|
||||
/**
|
||||
* Internal Akka use only, used in implementation of system.actorOf.
|
||||
*/
|
||||
private[akka] case class CreateChild(props: Props, name: String)
|
||||
|
||||
/**
|
||||
|
|
@ -324,7 +327,7 @@ class LocalActorRefProvider(
|
|||
|
||||
private val tempNode = rootPath / "temp"
|
||||
|
||||
def tempPath() = tempNode / tempName
|
||||
def tempPath() = tempNode / tempName()
|
||||
|
||||
/**
|
||||
* Top-level anchor for the supervision hierarchy of this actor system. Will
|
||||
|
|
@ -348,7 +351,7 @@ class LocalActorRefProvider(
|
|||
override def isTerminated = stopped.isOn
|
||||
|
||||
override def !(message: Any)(implicit sender: ActorRef = null): Unit = stopped.ifOff(message match {
|
||||
case Failed(ex) ⇒ causeOfTermination = Some(ex); sender.stop()
|
||||
case Failed(ex) if sender ne null ⇒ causeOfTermination = Some(ex); sender.stop()
|
||||
case _ ⇒ log.error(this + " received unexpected message " + message)
|
||||
})
|
||||
|
||||
|
|
@ -422,12 +425,12 @@ class LocalActorRefProvider(
|
|||
def path = tempNode
|
||||
override def getParent = rootGuardian
|
||||
override def getChild(name: Iterable[String]): InternalActorRef = {
|
||||
val c = children.get(name.head)
|
||||
if (c == null) Nobody
|
||||
else {
|
||||
children.get(name.head) match {
|
||||
case null ⇒ Nobody
|
||||
case some ⇒
|
||||
val t = name.tail
|
||||
if (t.isEmpty) c
|
||||
else c.getChild(t)
|
||||
if (t.isEmpty) some
|
||||
else some.getChild(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -563,22 +566,22 @@ class LocalDeathWatch extends DeathWatch with ActorClassification {
|
|||
class DefaultScheduler(hashedWheelTimer: HashedWheelTimer, log: LoggingAdapter, dispatcher: ⇒ MessageDispatcher) extends Scheduler with Closeable {
|
||||
import org.jboss.netty.akka.util.{ Timeout ⇒ HWTimeout }
|
||||
|
||||
private def exec(task: TimerTask, delay: Duration): HWTimeout = hashedWheelTimer.newTimeout(task, delay)
|
||||
private def schedule(task: TimerTask, delay: Duration): HWTimeout = hashedWheelTimer.newTimeout(task, delay)
|
||||
|
||||
def schedule(receiver: ActorRef, message: Any, initialDelay: Duration, delay: Duration): Cancellable =
|
||||
new DefaultCancellable(exec(createContinuousTask(receiver, message, delay), initialDelay))
|
||||
new DefaultCancellable(schedule(createContinuousTask(receiver, message, delay), initialDelay))
|
||||
|
||||
def schedule(f: () ⇒ Unit, initialDelay: Duration, delay: Duration): Cancellable =
|
||||
new DefaultCancellable(exec(createContinuousTask(f, delay), initialDelay))
|
||||
new DefaultCancellable(schedule(createContinuousTask(f, delay), initialDelay))
|
||||
|
||||
def scheduleOnce(runnable: Runnable, delay: Duration): Cancellable =
|
||||
new DefaultCancellable(exec(createSingleTask(runnable), delay))
|
||||
new DefaultCancellable(schedule(createSingleTask(runnable), delay))
|
||||
|
||||
def scheduleOnce(receiver: ActorRef, message: Any, delay: Duration): Cancellable =
|
||||
new DefaultCancellable(exec(createSingleTask(receiver, message), delay))
|
||||
new DefaultCancellable(schedule(createSingleTask(receiver, message), delay))
|
||||
|
||||
def scheduleOnce(f: () ⇒ Unit, delay: Duration): Cancellable =
|
||||
new DefaultCancellable(exec(createSingleTask(f), delay))
|
||||
new DefaultCancellable(schedule(createSingleTask(f), delay))
|
||||
|
||||
private def createSingleTask(runnable: Runnable): TimerTask =
|
||||
new TimerTask() {
|
||||
|
|
@ -637,7 +640,7 @@ class DefaultScheduler(hashedWheelTimer: HashedWheelTimer, log: LoggingAdapter,
|
|||
|
||||
def close() = {
|
||||
import scala.collection.JavaConverters._
|
||||
hashedWheelTimer.stop().asScala foreach (t ⇒ execDirectly(t))
|
||||
hashedWheelTimer.stop().asScala foreach execDirectly
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,11 +36,8 @@ object LocalActorPath {
|
|||
def unapply(addr: String): Option[(LocalAddress, Iterable[String])] = {
|
||||
try {
|
||||
val uri = new URI(addr)
|
||||
if (uri.getScheme != "akka") return None
|
||||
if (uri.getUserInfo != null) return None
|
||||
if (uri.getHost == null) return None
|
||||
if (uri.getPath == null) return None
|
||||
Some(LocalAddress(uri.getHost), ActorPath.split(uri.getPath).drop(1))
|
||||
if (uri.getScheme != "akka" || uri.getUserInfo != null || uri.getHost == null || uri.getPath == null) None
|
||||
else Some(LocalAddress(uri.getHost), ActorPath.split(uri.getPath).drop(1))
|
||||
} catch {
|
||||
case _: URISyntaxException ⇒ None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,12 +41,8 @@ object RemoteActorPath {
|
|||
def unapply(addr: String): Option[(RemoteAddress, Iterable[String])] = {
|
||||
try {
|
||||
val uri = new URI(addr)
|
||||
if (uri.getScheme != "akka") return None
|
||||
if (uri.getUserInfo == null) return None
|
||||
if (uri.getHost == null) return None
|
||||
if (uri.getPort == -1) return None
|
||||
if (uri.getPath == null) return None
|
||||
Some(RemoteAddress(uri.getUserInfo, uri.getHost, uri.getPort), ActorPath.split(uri.getPath).drop(1))
|
||||
if (uri.getScheme != "akka" || uri.getUserInfo == null || uri.getHost == null || uri.getPort == -1 || uri.getPath == null) None
|
||||
else Some(RemoteAddress(uri.getUserInfo, uri.getHost, uri.getPort), ActorPath.split(uri.getPath).drop(1))
|
||||
} catch {
|
||||
case _: URISyntaxException ⇒ None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,10 +62,6 @@ class TestActorRef[T <: Actor](
|
|||
|
||||
override def toString = "TestActor[" + path + "]"
|
||||
|
||||
override def equals(other: Any) = other match {
|
||||
case r: TestActorRef[_] ⇒ path == r.path
|
||||
case _ ⇒ false
|
||||
}
|
||||
}
|
||||
|
||||
object TestActorRef {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue