{"action":"created","comment":{"url":"https://api.github.com/repos/akka/akka/pulls/comments/37406861","id":37406861,"diff_hunk":"@@ -0,0 +1,102 @@\n+/**\n+ * Copyright (C) 2015 Typesafe Inc. <http://www.typesafe.com>\n+ */\n+package akka.persistence.query.journal.leveldb\n+\n+import scala.concurrent.duration._\n+\n+import akka.actor.ActorLogging\n+import akka.actor.ActorRef\n+import akka.actor.Props\n+import akka.persistence.JournalProtocol._\n+import akka.persistence.Persistence\n+import akka.stream.actor.ActorPublisher\n+import akka.stream.actor.ActorPublisherMessage.Cancel\n+import akka.stream.actor.ActorPublisherMessage.Request\n+import akka.persistence.journal.leveldb.LeveldbJournal\n+\n+object EventsByPersistenceIdPublisher {\n+  def props(persistenceId: String, fromSequenceNr: Long, toSequenceNr: Long, refreshInterval: Option[FiniteDuration]): Props =\n+    Props(new EventsByPersistenceIdPublisher(persistenceId, fromSequenceNr, toSequenceNr, refreshInterval))\n+\n+  private case object Continue\n+}\n+\n+class EventsByPersistenceIdPublisher(persistenceId: String, fromSequenceNr: Long, toSequenceNr: Long,\n+                                     refreshInterval: Option[FiniteDuration])\n+  extends ActorPublisher[Any] with DeliveryBuffer[Any] with ActorLogging {\n+  import EventsByPersistenceIdPublisher._\n+\n+  // FIXME change log.info to log.debug\n+\n+  val writeJournalPluginId = \"akka.persistence.journal.leveldb\" // FIXME from config\n+  val journal: ActorRef = Persistence(context.system).journalFor(writeJournalPluginId)\n+\n+  val replayMax = 100 // FIXME from config\n+  var currSeqNo = fromSequenceNr\n+  var replayCompleted = false\n+  var replayCount = 0\n+\n+  val tickTask = refreshInterval.map { interval ⇒\n+    import context.dispatcher\n+    context.system.scheduler.schedule(interval, interval, self, Continue)\n+  }\n+\n+  override def postStop(): Unit = {\n+    tickTask.foreach(_.cancel())\n+  }\n+\n+  def receive = init\n+\n+  def init: Receive = {\n+    case _: Request ⇒\n+      journal ! LeveldbJournal.SubscribePersistenceId(persistenceId)\n+      log.info(\"initial request ReplayMessages for persistenceId [{}] from [{}] to [{}]\", persistenceId, currSeqNo, toSequenceNr)\n+      journal ! ReplayMessages(currSeqNo, toSequenceNr, replayMax, persistenceId, self)\n+      context.become(active)\n+    case Continue ⇒\n+    case Cancel ⇒\n+      context.stop(self)\n+  }\n+\n+  def active: Receive = {","path":"akka-persistence-query/src/main/scala/akka/persistence/query/journal/leveldb/EventsByPersistenceIdPublisher.scala","position":62,"original_position":62,"commit_id":"bcc36af85a8ba431b14882482644c92ace2f66d0","original_commit_id":"bcc36af85a8ba431b14882482644c92ace2f66d0","user":{"login":"patriknw","id":336161,"avatar_url":"https://avatars.githubusercontent.com/u/336161?v=3","gravatar_id":"","url":"https://api.github.com/users/patriknw","html_url":"https://github.com/patriknw","followers_url":"https://api.github.com/users/patriknw/followers","following_url":"https://api.github.com/users/patriknw/following{/other_user}","gists_url":"https://api.github.com/users/patriknw/gists{/gist_id}","starred_url":"https://api.github.com/users/patriknw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patriknw/subscriptions","organizations_url":"https://api.github.com/users/patriknw/orgs","repos_url":"https://api.github.com/users/patriknw/repos","events_url":"https://api.github.com/users/patriknw/events{/privacy}","received_events_url":"https://api.github.com/users/patriknw/received_events","type":"User","site_admin":false},"body":"I'm rewriting this to be more readable","created_at":"2015-08-19T12:10:20Z","updated_at":"2015-08-19T12:10:20Z","html_url":"https://github.com/akka/akka/pull/18264#discussion_r37406861","pull_request_url":"https://api.github.com/repos/akka/akka/pulls/18264","_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/comments/37406861"},"html":{"href":"https://github.com/akka/akka/pull/18264#discussion_r37406861"},"pull_request":{"href":"https://api.github.com/repos/akka/akka/pulls/18264"}}},"pull_request":{"url":"https://api.github.com/repos/akka/akka/pulls/18264","id":42799913,"html_url":"https://github.com/akka/akka/pull/18264","diff_url":"https://github.com/akka/akka/pull/18264.diff","patch_url":"https://github.com/akka/akka/pull/18264.patch","issue_url":"https://api.github.com/repos/akka/akka/issues/18264","number":18264,"state":"open","locked":false,"title":"+per #18190 leveldb impl of EventsByPersistenceId query","user":{"login":"patriknw","id":336161,"avatar_url":"https://avatars.githubusercontent.com/u/336161?v=3","gravatar_id":"","url":"https://api.github.com/users/patriknw","html_url":"https://github.com/patriknw","followers_url":"https://api.github.com/users/patriknw/followers","following_url":"https://api.github.com/users/patriknw/following{/other_user}","gists_url":"https://api.github.com/users/patriknw/gists{/gist_id}","starred_url":"https://api.github.com/users/patriknw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patriknw/subscriptions","organizations_url":"https://api.github.com/users/patriknw/orgs","repos_url":"https://api.github.com/users/patriknw/repos","events_url":"https://api.github.com/users/patriknw/events{/privacy}","received_events_url":"https://api.github.com/users/patriknw/received_events","type":"User","site_admin":false},"body":"Not ready. Requires some cleanup and documentation.\r\n\r\nAlso tinkering if we could skip the scheduled ticks altogether and rely on the Changed notifications. However, if there are many changes all the time its good to not do the query too often.","created_at":"2015-08-19T10:42:06Z","updated_at":"2015-08-19T12:10:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bb313ee28547a7fb41b0fdace21877e4f66104ba","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/akka/akka/pulls/18264/commits","review_comments_url":"https://api.github.com/repos/akka/akka/pulls/18264/comments","review_comment_url":"https://api.github.com/repos/akka/akka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akka/akka/issues/18264/comments","statuses_url":"https://api.github.com/repos/akka/akka/statuses/bcc36af85a8ba431b14882482644c92ace2f66d0","head":{"label":"akka:wip-18190-leveldb-EventsByPersistenceId-patriknw","ref":"wip-18190-leveldb-EventsByPersistenceId-patriknw","sha":"bcc36af85a8ba431b14882482644c92ace2f66d0","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}","created_at":"2009-02-16T12:51:54Z","updated_at":"2015-08-19T08:23:38Z","pushed_at":"2015-08-19T12:05:29Z","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":268036,"stargazers_count":4342,"watchers_count":4342,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1273,"mirror_url":null,"open_issues_count":703,"forks":1273,"open_issues":703,"watchers":4342,"default_branch":"master"}},"base":{"label":"akka:master","ref":"master","sha":"3e2063bac2d7ccd3d6c7ab14a527651acdfd7476","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}","created_at":"2009-02-16T12:51:54Z","updated_at":"2015-08-19T08:23:38Z","pushed_at":"2015-08-19T12:05:29Z","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":268036,"stargazers_count":4342,"watchers_count":4342,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1273,"mirror_url":null,"open_issues_count":703,"forks":1273,"open_issues":703,"watchers":4342,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/18264"},"html":{"href":"https://github.com/akka/akka/pull/18264"},"issue":{"href":"https://api.github.com/repos/akka/akka/issues/18264"},"comments":{"href":"https://api.github.com/repos/akka/akka/issues/18264/comments"},"review_comments":{"href":"https://api.github.com/repos/akka/akka/pulls/18264/comments"},"review_comment":{"href":"https://api.github.com/repos/akka/akka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akka/akka/pulls/18264/commits"},"statuses":{"href":"https://api.github.com/repos/akka/akka/statuses/bcc36af85a8ba431b14882482644c92ace2f66d0"}}}}