{"action":"created","comment":{"url":"https://api.github.com/repos/akka/akka/pulls/comments/75142384","id":75142384,"diff_hunk":"@@ -0,0 +1,433 @@\n+/**\n+ * Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com/>\n+ */\n+package akka.typed\n+package internal\n+\n+import akka.actor.InvalidActorNameException\n+import akka.util.Helpers\n+import scala.concurrent.duration.{ Duration, FiniteDuration }\n+import akka.dispatch.ExecutionContexts\n+import scala.concurrent.ExecutionContextExecutor\n+import akka.actor.Cancellable\n+import akka.util.Unsafe.{ instance ⇒ unsafe }\n+import java.util.concurrent.ConcurrentLinkedQueue\n+import java.util.Queue\n+import scala.annotation.{ tailrec, switch }\n+import scala.util.control.NonFatal\n+import scala.util.control.Exception.Catcher\n+import akka.event.Logging.Error\n+import akka.event.Logging\n+\n+/**\n+ * INTERNAL API\n+ */\n+object ActorCell {\n+  /*\n+   * Description of the _status field bit structure:\n+   *\n+   * bit 0-29: activation count (number of (system)messages)\n+   * bit 30: terminating (or terminated)\n+   * bit 31: terminated\n+   *\n+   * Activation count is a bit special:\n+   * 0 means inactive\n+   * 1 means active without normal messages (i.e. only system messages)\n+   * N means active with N-1 normal messages (plus possibly system messages)\n+   */\n+  final val terminatingShift = 30\n+\n+  final val activationMask = (1 << terminatingShift) - 1\n+  // ensure that if all processors enqueue “the last message” concurrently, there is still no overflow\n+  val maxActivations = activationMask - Runtime.getRuntime.availableProcessors - 1\n+\n+  final val terminatingBit = 1 << terminatingShift\n+  final val closedBit = 1 << 31\n+\n+  def isTerminating(status: Int): Boolean = (status & terminatingBit) != 0\n+  def isClosed(status: Int): Boolean = status < 0\n+  def isActive(status: Int): Boolean = (status & ~activationMask) == 0\n+\n+  def activations(status: Int): Int = status & activationMask\n+  def messageCount(status: Int): Int = Math.max(0, activations(status) - 1)\n+\n+  val statusOffset = unsafe.objectFieldOffset(classOf[ActorCell[_]].getDeclaredField(\"_status\"))\n+  val systemQueueOffset = unsafe.objectFieldOffset(classOf[ActorCell[_]].getDeclaredField(\"_systemQueue\"))\n+\n+  final val DefaultState = 0\n+  final val SuspendedState = 1\n+  final val SuspendedWaitForChildrenState = 2\n+\n+  final val Debug = false\n+}\n+\n+/**\n+ * INTERNAL API\n+ */\n+private[typed] class ActorCell[T](\n+  override val system: ActorSystem[Nothing],\n+  override val props: Props[T],\n+  val parent: ActorRefImpl[Nothing])\n+    extends ActorContext[T] with Runnable with SupervisionMechanics[T] with DeathWatch[T] {\n+  import ActorCell._\n+\n+  /*\n+   * Implementation of the ActorContext trait.\n+   */\n+\n+  protected var childrenMap = Map.empty[String, ActorRefImpl[Nothing]]\n+  protected var terminatingMap = Map.empty[String, ActorRefImpl[Nothing]]\n+  override def children: Iterable[ActorRef[Nothing]] = childrenMap.values\n+  override def child(name: String): Option[ActorRef[Nothing]] = childrenMap.get(name)\n+  protected def removeChild(actor: ActorRefImpl[Nothing]): Unit = {\n+    val n = actor.path.name\n+    childrenMap.get(n) match {\n+      case Some(`actor`) ⇒ childrenMap -= n\n+      case _ ⇒\n+        terminatingMap.get(n) match {\n+          case Some(`actor`) ⇒ terminatingMap -= n\n+          case _             ⇒\n+        }\n+    }\n+  }\n+  private[typed] def terminating: Iterable[ActorRef[Nothing]] = terminatingMap.values\n+\n+  private var _self: ActorRefImpl[T] = _\n+  private[typed] def setSelf(ref: ActorRefImpl[T]): Unit = _self = ref\n+  override def self: ActorRefImpl[T] = _self\n+\n+  protected def ctx: ActorContext[T] = this\n+\n+  override def spawn[U](props: Props[U], name: String): ActorRef[U] = {\n+    if (childrenMap contains name) throw new InvalidActorNameException(s\"actor name [$name] is not unique\")\n+    if (terminatingMap contains name) throw new InvalidActorNameException(s\"actor name [$name] is not yet free\")\n+    val cell = new ActorCell[U](system, props, self)\n+    val ref = new LocalActorRef[U](self.path / name, cell)\n+    cell.setSelf(ref)\n+    childrenMap = childrenMap.updated(name, ref)\n+    ref.sendSystem(Create())\n+    ref\n+  }\n+\n+  private var nextName = 0L\n+  override def spawnAnonymous[U](props: Props[U]): ActorRef[U] = {\n+    val name = Helpers.base64(nextName)\n+    nextName += 1\n+    spawn(props, name)\n+  }\n+\n+  override def stop(child: ActorRef[Nothing]): Boolean = {\n+    val name = child.path.name\n+    childrenMap.get(name) match {\n+      case None                      ⇒ false\n+      case Some(ref) if ref != child ⇒ false\n+      case Some(ref) ⇒\n+        ref.sendSystem(Terminate())\n+        childrenMap -= name\n+        terminatingMap = terminatingMap.updated(name, ref)\n+        true\n+    }\n+  }\n+\n+  protected def stopAll(): Unit = {\n+    childrenMap.valuesIterator.foreach { ref ⇒\n+      ref.sendSystem(Terminate())\n+      terminatingMap = terminatingMap.updated(ref.path.name, ref)\n+    }\n+    childrenMap = Map.empty\n+  }\n+\n+  override def schedule[U](delay: FiniteDuration, target: ActorRef[U], msg: U): Cancellable =\n+    system.scheduler.scheduleOnce(delay)(target ! msg)(ExecutionContexts.sameThreadExecutionContext)\n+\n+  override val executionContext: ExecutionContextExecutor = system.dispatchers.lookup(props.dispatcher)\n+\n+  override def spawnAdapter[U](f: U ⇒ T): ActorRef[U] = {\n+    val name = Helpers.base64(nextName)\n+    nextName += 1\n+    val ref = new FunctionRef[U](self.path / name,\n+      (msg, _) ⇒ send(f(msg)),\n+      (self) ⇒ sendSystem(DeathWatchNotification(self, null)))\n+    childrenMap = childrenMap.updated(name, ref)\n+    ref\n+  }\n+\n+  private[this] var receiveTimeout: (FiniteDuration, T) = null\n+  override def setReceiveTimeout(d: FiniteDuration, msg: T): Unit = {","path":"akka-typed/src/main/scala/akka/typed/internal/ActorCell.scala","position":156,"original_position":156,"commit_id":"101d83b0bd6e436d9583758a04a1227a205d3a34","original_commit_id":"101d83b0bd6e436d9583758a04a1227a205d3a34","user":{"login":"ktoso","id":120979,"avatar_url":"https://avatars.githubusercontent.com/u/120979?v=3","gravatar_id":"","url":"https://api.github.com/users/ktoso","html_url":"https://github.com/ktoso","followers_url":"https://api.github.com/users/ktoso/followers","following_url":"https://api.github.com/users/ktoso/following{/other_user}","gists_url":"https://api.github.com/users/ktoso/gists{/gist_id}","starred_url":"https://api.github.com/users/ktoso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ktoso/subscriptions","organizations_url":"https://api.github.com/users/ktoso/orgs","repos_url":"https://api.github.com/users/ktoso/repos","events_url":"https://api.github.com/users/ktoso/events{/privacy}","received_events_url":"https://api.github.com/users/ktoso/received_events","type":"User","site_admin":false},"body":"nice improvement over current 👍 ","created_at":"2016-08-17T15:11:54Z","updated_at":"2016-08-17T15:11:54Z","html_url":"https://github.com/akka/akka/pull/21128#discussion_r75142384","pull_request_url":"https://api.github.com/repos/akka/akka/pulls/21128","_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/comments/75142384"},"html":{"href":"https://github.com/akka/akka/pull/21128#discussion_r75142384"},"pull_request":{"href":"https://api.github.com/repos/akka/akka/pulls/21128"}}},"pull_request":{"url":"https://api.github.com/repos/akka/akka/pulls/21128","id":80372150,"html_url":"https://github.com/akka/akka/pull/21128","diff_url":"https://github.com/akka/akka/pull/21128.diff","patch_url":"https://github.com/akka/akka/pull/21128.patch","issue_url":"https://api.github.com/repos/akka/akka/issues/21128","number":21128,"state":"open","locked":false,"title":"New implementation for Akka Typed","user":{"login":"rkuhn","id":470469,"avatar_url":"https://avatars.githubusercontent.com/u/470469?v=3","gravatar_id":"","url":"https://api.github.com/users/rkuhn","html_url":"https://github.com/rkuhn","followers_url":"https://api.github.com/users/rkuhn/followers","following_url":"https://api.github.com/users/rkuhn/following{/other_user}","gists_url":"https://api.github.com/users/rkuhn/gists{/gist_id}","starred_url":"https://api.github.com/users/rkuhn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkuhn/subscriptions","organizations_url":"https://api.github.com/users/rkuhn/orgs","repos_url":"https://api.github.com/users/rkuhn/repos","events_url":"https://api.github.com/users/rkuhn/events{/privacy}","received_events_url":"https://api.github.com/users/rkuhn/received_events","type":"User","site_admin":false},"body":"This is the first step towards a completely new and optimized actor implementation for Akka Typed. The full previously existing test suite passes for both implementations. The following is an incomplete list of things that remain to be done:\r\n\r\n* document the semantic differences between untyped and typed, in particular around actor restarts and the delivery ordering guarantees for Terminated messages (also document the difference between ActorSystemImpl and ActorSystemAdapter)\r\n* implement EventStream and logging—this currently just delegates to an extra untyped ActorSystem (of course To Be Fixed)\r\n* implement dispatcher selection\r\n* implement and test queue size limitation\r\n* implement optimized message queue instead of CLQ (for zero-allocation messaging)\r\n* clean up test log output (something does not work with TestEventListener and EventFilter for ActorSystemImpl tests)\r\n* document the capabilities (or more appropriately: the limitations) of interoperability between ActorSystemImpl and ActorSystemAdapter\r\n* fix ActorPath UID generation (i.e. make sure that everything gets a meaningful value instead of zero)\r\n\r\nOther things that are missing will surely be discovered; my proposal is to collect them in this PR via comments and then ticketify them before the PR is merged.\r\n\r\nCurrently the branch does not merge, I’ll squash and rebase after review.\r\n\r\nOh, and by the way: as per PerformanceSpec (doing simple ping-pong) the new implementation is ca. 30% faster than the adapter over akka-actor :-)","created_at":"2016-08-07T17:00:24Z","updated_at":"2016-08-17T15:11:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2171273b03e8842649d1f2a9bf1380a39404231f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/akka/akka/pulls/21128/commits","review_comments_url":"https://api.github.com/repos/akka/akka/pulls/21128/comments","review_comment_url":"https://api.github.com/repos/akka/akka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akka/akka/issues/21128/comments","statuses_url":"https://api.github.com/repos/akka/akka/statuses/101d83b0bd6e436d9583758a04a1227a205d3a34","head":{"label":"akka:wip-new-Typed-Impl-RK","ref":"wip-new-Typed-Impl-RK","sha":"101d83b0bd6e436d9583758a04a1227a205d3a34","user":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"repo":{"id":130013,"name":"akka","full_name":"akka/akka","owner":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akka/akka","description":"Akka Project","fork":false,"url":"https://api.github.com/repos/akka/akka","forks_url":"https://api.github.com/repos/akka/akka/forks","keys_url":"https://api.github.com/repos/akka/akka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akka/akka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akka/akka/teams","hooks_url":"https://api.github.com/repos/akka/akka/hooks","issue_events_url":"https://api.github.com/repos/akka/akka/issues/events{/number}","events_url":"https://api.github.com/repos/akka/akka/events","assignees_url":"https://api.github.com/repos/akka/akka/assignees{/user}","branches_url":"https://api.github.com/repos/akka/akka/branches{/branch}","tags_url":"https://api.github.com/repos/akka/akka/tags","blobs_url":"https://api.github.com/repos/akka/akka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akka/akka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akka/akka/git/refs{/sha}","trees_url":"https://api.github.com/repos/akka/akka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akka/akka/statuses/{sha}","languages_url":"https://api.github.com/repos/akka/akka/languages","stargazers_url":"https://api.github.com/repos/akka/akka/stargazers","contributors_url":"https://api.github.com/repos/akka/akka/contributors","subscribers_url":"https://api.github.com/repos/akka/akka/subscribers","subscription_url":"https://api.github.com/repos/akka/akka/subscription","commits_url":"https://api.github.com/repos/akka/akka/commits{/sha}","git_commits_url":"https://api.github.com/repos/akka/akka/git/commits{/sha}","comments_url":"https://api.github.com/repos/akka/akka/comments{/number}","issue_comment_url":"https://api.github.com/repos/akka/akka/issues/comments{/number}","contents_url":"https://api.github.com/repos/akka/akka/contents/{+path}","compare_url":"https://api.github.com/repos/akka/akka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akka/akka/merges","archive_url":"https://api.github.com/repos/akka/akka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akka/akka/downloads","issues_url":"https://api.github.com/repos/akka/akka/issues{/number}","pulls_url":"https://api.github.com/repos/akka/akka/pulls{/number}","milestones_url":"https://api.github.com/repos/akka/akka/milestones{/number}","notifications_url":"https://api.github.com/repos/akka/akka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akka/akka/labels{/name}","releases_url":"https://api.github.com/repos/akka/akka/releases{/id}","deployments_url":"https://api.github.com/repos/akka/akka/deployments","created_at":"2009-02-16T12:51:54Z","updated_at":"2016-08-17T13:15:52Z","pushed_at":"2016-08-17T13:43:49Z","git_url":"git://github.com/akka/akka.git","ssh_url":"git@github.com:akka/akka.git","clone_url":"https://github.com/akka/akka.git","svn_url":"https://github.com/akka/akka","homepage":"http://akka.io","size":227643,"stargazers_count":5892,"watchers_count":5892,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1870,"mirror_url":null,"open_issues_count":708,"forks":1870,"open_issues":708,"watchers":5892,"default_branch":"master"}},"base":{"label":"akka:master","ref":"master","sha":"d5f84d4ad8325f1ab04820711af45a92964ab438","user":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"repo":{"id":130013,"name":"akka","full_name":"akka/akka","owner":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akka/akka","description":"Akka Project","fork":false,"url":"https://api.github.com/repos/akka/akka","forks_url":"https://api.github.com/repos/akka/akka/forks","keys_url":"https://api.github.com/repos/akka/akka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akka/akka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akka/akka/teams","hooks_url":"https://api.github.com/repos/akka/akka/hooks","issue_events_url":"https://api.github.com/repos/akka/akka/issues/events{/number}","events_url":"https://api.github.com/repos/akka/akka/events","assignees_url":"https://api.github.com/repos/akka/akka/assignees{/user}","branches_url":"https://api.github.com/repos/akka/akka/branches{/branch}","tags_url":"https://api.github.com/repos/akka/akka/tags","blobs_url":"https://api.github.com/repos/akka/akka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akka/akka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akka/akka/git/refs{/sha}","trees_url":"https://api.github.com/repos/akka/akka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akka/akka/statuses/{sha}","languages_url":"https://api.github.com/repos/akka/akka/languages","stargazers_url":"https://api.github.com/repos/akka/akka/stargazers","contributors_url":"https://api.github.com/repos/akka/akka/contributors","subscribers_url":"https://api.github.com/repos/akka/akka/subscribers","subscription_url":"https://api.github.com/repos/akka/akka/subscription","commits_url":"https://api.github.com/repos/akka/akka/commits{/sha}","git_commits_url":"https://api.github.com/repos/akka/akka/git/commits{/sha}","comments_url":"https://api.github.com/repos/akka/akka/comments{/number}","issue_comment_url":"https://api.github.com/repos/akka/akka/issues/comments{/number}","contents_url":"https://api.github.com/repos/akka/akka/contents/{+path}","compare_url":"https://api.github.com/repos/akka/akka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akka/akka/merges","archive_url":"https://api.github.com/repos/akka/akka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akka/akka/downloads","issues_url":"https://api.github.com/repos/akka/akka/issues{/number}","pulls_url":"https://api.github.com/repos/akka/akka/pulls{/number}","milestones_url":"https://api.github.com/repos/akka/akka/milestones{/number}","notifications_url":"https://api.github.com/repos/akka/akka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akka/akka/labels{/name}","releases_url":"https://api.github.com/repos/akka/akka/releases{/id}","deployments_url":"https://api.github.com/repos/akka/akka/deployments","created_at":"2009-02-16T12:51:54Z","updated_at":"2016-08-17T13:15:52Z","pushed_at":"2016-08-17T13:43:49Z","git_url":"git://github.com/akka/akka.git","ssh_url":"git@github.com:akka/akka.git","clone_url":"https://github.com/akka/akka.git","svn_url":"https://github.com/akka/akka","homepage":"http://akka.io","size":227643,"stargazers_count":5892,"watchers_count":5892,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1870,"mirror_url":null,"open_issues_count":708,"forks":1870,"open_issues":708,"watchers":5892,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/21128"},"html":{"href":"https://github.com/akka/akka/pull/21128"},"issue":{"href":"https://api.github.com/repos/akka/akka/issues/21128"},"comments":{"href":"https://api.github.com/repos/akka/akka/issues/21128/comments"},"review_comments":{"href":"https://api.github.com/repos/akka/akka/pulls/21128/comments"},"review_comment":{"href":"https://api.github.com/repos/akka/akka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akka/akka/pulls/21128/commits"},"statuses":{"href":"https://api.github.com/repos/akka/akka/statuses/101d83b0bd6e436d9583758a04a1227a205d3a34"}}}}
{"actor":{"display_login":"ktoso"}}