{"action":"created","comment":{"url":"https://api.github.com/repos/paypal/squbs/pulls/comments/92904899","pull_request_review_id":13430727,"id":92904899,"diff_hunk":"@@ -0,0 +1,100 @@\n+/*\n+ * Copyright 2015 PayPal\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.squbs.streams\n+\n+import akka.stream.ActorAttributes.SupervisionStrategy\n+import akka.stream.{Supervision, Attributes}\n+import akka.stream.impl.fusing.GraphStages.SimpleLinearGraphStage\n+import akka.stream.stage.{InHandler, OutHandler, GraphStageLogic}\n+\n+import scala.util.control.NonFatal\n+\n+object Deduplicate {\n+\n+  def apply[T, U](key: T => U, duplicateCount: Long) =\n+    new Deduplicate[T, U](key, duplicateCount, new java.util.HashMap[U, MutableLong]())\n+\n+  def apply[T, U](key: T => U, duplicateCount: Long, registry: java.util.Map[U, MutableLong]) =\n+    new Deduplicate[T, U](key, duplicateCount, registry)\n+\n+  def apply[T](duplicateCount: Long = Long.MaxValue,\n+               registry: java.util.Map[T, MutableLong] = new java.util.HashMap[T, MutableLong]()): Deduplicate[T, T] =\n+    Deduplicate(t => t, duplicateCount, registry)\n+}\n+\n+/**\n+  * Only pass on those elements that have not been seen so far.\n+  *\n+  * '''Emits when''' the element is not a duplicate\n+  *\n+  * '''Backpressures when''' the element is not a duplicate and downstream backpressures\n+  *\n+  * '''Completes when''' upstream completes\n+  *\n+  * '''Cancels when''' downstream cancels\n+  */\n+final class Deduplicate[T, U](key: T => U, duplicateCount: Long = Long.MaxValue,\n+                              registry: java.util.Map[U, MutableLong] = new java.util.HashMap[U, MutableLong]())\n+  extends SimpleLinearGraphStage[T] {\n+\n+  require(duplicateCount >= 2)\n+\n+  override def toString: String = \"Deduplicate\"\n+\n+  override def createLogic(inheritedAttributes: Attributes): GraphStageLogic =\n+    new GraphStageLogic(shape) with OutHandler with InHandler {\n+      def decider = inheritedAttributes.get[SupervisionStrategy].map(_.decider).getOrElse(Supervision.stoppingDecider)\n+\n+      import scala.compat.java8.FunctionConverters._\n+      val incrementOrRemove: (MutableLong, MutableLong) => MutableLong = (old, default) => {\n+        pull(in)\n+        if(old.increment() == duplicateCount) null else old\n+      }\n+\n+      override def onPush(): Unit = {\n+        try {\n+          val elem = grab(in)\n+          val counter = registry.merge(key(elem), MutableLong(1), incrementOrRemove.asJava)\n+          if(counter != null && counter.value == 1) {","path":"squbs-ext/src/main/scala/org/squbs/streams/Deduplicate.scala","position":72,"original_position":72,"commit_id":"4f71eb2cae0c1efbd1f33f96fffe46b0b3181c3c","original_commit_id":"4f71eb2cae0c1efbd1f33f96fffe46b0b3181c3c","user":{"login":"codacy-bot","id":19940114,"avatar_url":"https://avatars.githubusercontent.com/u/19940114?v=3","gravatar_id":"","url":"https://api.github.com/users/codacy-bot","html_url":"https://github.com/codacy-bot","followers_url":"https://api.github.com/users/codacy-bot/followers","following_url":"https://api.github.com/users/codacy-bot/following{/other_user}","gists_url":"https://api.github.com/users/codacy-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/codacy-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codacy-bot/subscriptions","organizations_url":"https://api.github.com/users/codacy-bot/orgs","repos_url":"https://api.github.com/users/codacy-bot/repos","events_url":"https://api.github.com/users/codacy-bot/events{/privacy}","received_events_url":"https://api.github.com/users/codacy-bot/received_events","type":"User","site_admin":false},"body":"![Codacy](https://www.codacy.com/assets/images/favicon.png) Issue found: [Avoid using null](https://www.codacy.com/app/akara-sucharitakul/squbs/file/4764204075/issues/source?bid=2834325&fileBranchId=3971671#l72)","created_at":"2016-12-16T23:45:54Z","updated_at":"2016-12-16T23:45:55Z","html_url":"https://github.com/paypal/squbs/pull/341#discussion_r92904899","pull_request_url":"https://api.github.com/repos/paypal/squbs/pulls/341","_links":{"self":{"href":"https://api.github.com/repos/paypal/squbs/pulls/comments/92904899"},"html":{"href":"https://github.com/paypal/squbs/pull/341#discussion_r92904899"},"pull_request":{"href":"https://api.github.com/repos/paypal/squbs/pulls/341"}}},"pull_request":{"url":"https://api.github.com/repos/paypal/squbs/pulls/341","id":96844284,"html_url":"https://github.com/paypal/squbs/pull/341","diff_url":"https://github.com/paypal/squbs/pull/341.diff","patch_url":"https://github.com/paypal/squbs/pull/341.patch","issue_url":"https://api.github.com/repos/paypal/squbs/issues/341","number":341,"state":"open","locked":false,"title":"#327 Timeout Flow and Deduplicate","user":{"login":"anilgursel","id":3316621,"avatar_url":"https://avatars.githubusercontent.com/u/3316621?v=3","gravatar_id":"","url":"https://api.github.com/users/anilgursel","html_url":"https://github.com/anilgursel","followers_url":"https://api.github.com/users/anilgursel/followers","following_url":"https://api.github.com/users/anilgursel/following{/other_user}","gists_url":"https://api.github.com/users/anilgursel/gists{/gist_id}","starred_url":"https://api.github.com/users/anilgursel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anilgursel/subscriptions","organizations_url":"https://api.github.com/users/anilgursel/orgs","repos_url":"https://api.github.com/users/anilgursel/repos","events_url":"https://api.github.com/users/anilgursel/events{/privacy}","received_events_url":"https://api.github.com/users/anilgursel/received_events","type":"User","site_admin":false},"body":"Thanks for your pull request.  Please review the following guidelines.\r\n\r\n- [x] Title includes issue id.\r\n- [x] Description of the change added.\r\n- [x] Commits are squashed.\r\n- [x] Tests added.\r\n- [x] Documentation added/updated.\r\n- [x] Also please review [CONTRIBUTING.md](https://github.com/paypal/squbs/blob/master/CONTRIBUTING.md).\r\n\r\n\r\nWe should try to optimize the flow by eliminating the `async` boundary (or limit it to the `delay` branch).  We should tackle it with https://github.com/paypal/squbs/issues/354.\r\n\r\nWe should also look at `onUpstreamFinish` and `onUpstreamFailure` scenarios in more detail with https://github.com/paypal/squbs/issues/355.\r\n\r\nAlso, created a story to add a JMX bean for the `Deduplicate` registry size: https://github.com/paypal/squbs/issues/356.","created_at":"2016-12-07T01:53:58Z","updated_at":"2016-12-16T23:45:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"29f16215d01dbb92f8854bbaf8049bef2179d58b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/paypal/squbs/pulls/341/commits","review_comments_url":"https://api.github.com/repos/paypal/squbs/pulls/341/comments","review_comment_url":"https://api.github.com/repos/paypal/squbs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/paypal/squbs/issues/341/comments","statuses_url":"https://api.github.com/repos/paypal/squbs/statuses/4f71eb2cae0c1efbd1f33f96fffe46b0b3181c3c","head":{"label":"anilgursel:circuit-breaker","ref":"circuit-breaker","sha":"4f71eb2cae0c1efbd1f33f96fffe46b0b3181c3c","user":{"login":"anilgursel","id":3316621,"avatar_url":"https://avatars.githubusercontent.com/u/3316621?v=3","gravatar_id":"","url":"https://api.github.com/users/anilgursel","html_url":"https://github.com/anilgursel","followers_url":"https://api.github.com/users/anilgursel/followers","following_url":"https://api.github.com/users/anilgursel/following{/other_user}","gists_url":"https://api.github.com/users/anilgursel/gists{/gist_id}","starred_url":"https://api.github.com/users/anilgursel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anilgursel/subscriptions","organizations_url":"https://api.github.com/users/anilgursel/orgs","repos_url":"https://api.github.com/users/anilgursel/repos","events_url":"https://api.github.com/users/anilgursel/events{/privacy}","received_events_url":"https://api.github.com/users/anilgursel/received_events","type":"User","site_admin":false},"repo":{"id":45846928,"name":"squbs","full_name":"anilgursel/squbs","owner":{"login":"anilgursel","id":3316621,"avatar_url":"https://avatars.githubusercontent.com/u/3316621?v=3","gravatar_id":"","url":"https://api.github.com/users/anilgursel","html_url":"https://github.com/anilgursel","followers_url":"https://api.github.com/users/anilgursel/followers","following_url":"https://api.github.com/users/anilgursel/following{/other_user}","gists_url":"https://api.github.com/users/anilgursel/gists{/gist_id}","starred_url":"https://api.github.com/users/anilgursel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anilgursel/subscriptions","organizations_url":"https://api.github.com/users/anilgursel/orgs","repos_url":"https://api.github.com/users/anilgursel/repos","events_url":"https://api.github.com/users/anilgursel/events{/privacy}","received_events_url":"https://api.github.com/users/anilgursel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/anilgursel/squbs","description":"Akka/Spray for Large-Scale Production Deployments","fork":true,"url":"https://api.github.com/repos/anilgursel/squbs","forks_url":"https://api.github.com/repos/anilgursel/squbs/forks","keys_url":"https://api.github.com/repos/anilgursel/squbs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anilgursel/squbs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anilgursel/squbs/teams","hooks_url":"https://api.github.com/repos/anilgursel/squbs/hooks","issue_events_url":"https://api.github.com/repos/anilgursel/squbs/issues/events{/number}","events_url":"https://api.github.com/repos/anilgursel/squbs/events","assignees_url":"https://api.github.com/repos/anilgursel/squbs/assignees{/user}","branches_url":"https://api.github.com/repos/anilgursel/squbs/branches{/branch}","tags_url":"https://api.github.com/repos/anilgursel/squbs/tags","blobs_url":"https://api.github.com/repos/anilgursel/squbs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anilgursel/squbs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anilgursel/squbs/git/refs{/sha}","trees_url":"https://api.github.com/repos/anilgursel/squbs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anilgursel/squbs/statuses/{sha}","languages_url":"https://api.github.com/repos/anilgursel/squbs/languages","stargazers_url":"https://api.github.com/repos/anilgursel/squbs/stargazers","contributors_url":"https://api.github.com/repos/anilgursel/squbs/contributors","subscribers_url":"https://api.github.com/repos/anilgursel/squbs/subscribers","subscription_url":"https://api.github.com/repos/anilgursel/squbs/subscription","commits_url":"https://api.github.com/repos/anilgursel/squbs/commits{/sha}","git_commits_url":"https://api.github.com/repos/anilgursel/squbs/git/commits{/sha}","comments_url":"https://api.github.com/repos/anilgursel/squbs/comments{/number}","issue_comment_url":"https://api.github.com/repos/anilgursel/squbs/issues/comments{/number}","contents_url":"https://api.github.com/repos/anilgursel/squbs/contents/{+path}","compare_url":"https://api.github.com/repos/anilgursel/squbs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anilgursel/squbs/merges","archive_url":"https://api.github.com/repos/anilgursel/squbs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anilgursel/squbs/downloads","issues_url":"https://api.github.com/repos/anilgursel/squbs/issues{/number}","pulls_url":"https://api.github.com/repos/anilgursel/squbs/pulls{/number}","milestones_url":"https://api.github.com/repos/anilgursel/squbs/milestones{/number}","notifications_url":"https://api.github.com/repos/anilgursel/squbs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anilgursel/squbs/labels{/name}","releases_url":"https://api.github.com/repos/anilgursel/squbs/releases{/id}","deployments_url":"https://api.github.com/repos/anilgursel/squbs/deployments","created_at":"2015-11-09T15:27:04Z","updated_at":"2016-02-29T13:50:05Z","pushed_at":"2016-12-16T23:43:51Z","git_url":"git://github.com/anilgursel/squbs.git","ssh_url":"git@github.com:anilgursel/squbs.git","clone_url":"https://github.com/anilgursel/squbs.git","svn_url":"https://github.com/anilgursel/squbs","homepage":"","size":6741,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"paypal:master","ref":"master","sha":"b2c3ff52ee97c62504b2562ee1adc3f6e9b99083","user":{"login":"paypal","id":476675,"avatar_url":"https://avatars.githubusercontent.com/u/476675?v=3","gravatar_id":"","url":"https://api.github.com/users/paypal","html_url":"https://github.com/paypal","followers_url":"https://api.github.com/users/paypal/followers","following_url":"https://api.github.com/users/paypal/following{/other_user}","gists_url":"https://api.github.com/users/paypal/gists{/gist_id}","starred_url":"https://api.github.com/users/paypal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paypal/subscriptions","organizations_url":"https://api.github.com/users/paypal/orgs","repos_url":"https://api.github.com/users/paypal/repos","events_url":"https://api.github.com/users/paypal/events{/privacy}","received_events_url":"https://api.github.com/users/paypal/received_events","type":"Organization","site_admin":false},"repo":{"id":38714007,"name":"squbs","full_name":"paypal/squbs","owner":{"login":"paypal","id":476675,"avatar_url":"https://avatars.githubusercontent.com/u/476675?v=3","gravatar_id":"","url":"https://api.github.com/users/paypal","html_url":"https://github.com/paypal","followers_url":"https://api.github.com/users/paypal/followers","following_url":"https://api.github.com/users/paypal/following{/other_user}","gists_url":"https://api.github.com/users/paypal/gists{/gist_id}","starred_url":"https://api.github.com/users/paypal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paypal/subscriptions","organizations_url":"https://api.github.com/users/paypal/orgs","repos_url":"https://api.github.com/users/paypal/repos","events_url":"https://api.github.com/users/paypal/events{/privacy}","received_events_url":"https://api.github.com/users/paypal/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/paypal/squbs","description":"Akka/Spray for Large-Scale Production Deployments","fork":false,"url":"https://api.github.com/repos/paypal/squbs","forks_url":"https://api.github.com/repos/paypal/squbs/forks","keys_url":"https://api.github.com/repos/paypal/squbs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paypal/squbs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paypal/squbs/teams","hooks_url":"https://api.github.com/repos/paypal/squbs/hooks","issue_events_url":"https://api.github.com/repos/paypal/squbs/issues/events{/number}","events_url":"https://api.github.com/repos/paypal/squbs/events","assignees_url":"https://api.github.com/repos/paypal/squbs/assignees{/user}","branches_url":"https://api.github.com/repos/paypal/squbs/branches{/branch}","tags_url":"https://api.github.com/repos/paypal/squbs/tags","blobs_url":"https://api.github.com/repos/paypal/squbs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paypal/squbs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paypal/squbs/git/refs{/sha}","trees_url":"https://api.github.com/repos/paypal/squbs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paypal/squbs/statuses/{sha}","languages_url":"https://api.github.com/repos/paypal/squbs/languages","stargazers_url":"https://api.github.com/repos/paypal/squbs/stargazers","contributors_url":"https://api.github.com/repos/paypal/squbs/contributors","subscribers_url":"https://api.github.com/repos/paypal/squbs/subscribers","subscription_url":"https://api.github.com/repos/paypal/squbs/subscription","commits_url":"https://api.github.com/repos/paypal/squbs/commits{/sha}","git_commits_url":"https://api.github.com/repos/paypal/squbs/git/commits{/sha}","comments_url":"https://api.github.com/repos/paypal/squbs/comments{/number}","issue_comment_url":"https://api.github.com/repos/paypal/squbs/issues/comments{/number}","contents_url":"https://api.github.com/repos/paypal/squbs/contents/{+path}","compare_url":"https://api.github.com/repos/paypal/squbs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paypal/squbs/merges","archive_url":"https://api.github.com/repos/paypal/squbs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paypal/squbs/downloads","issues_url":"https://api.github.com/repos/paypal/squbs/issues{/number}","pulls_url":"https://api.github.com/repos/paypal/squbs/pulls{/number}","milestones_url":"https://api.github.com/repos/paypal/squbs/milestones{/number}","notifications_url":"https://api.github.com/repos/paypal/squbs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paypal/squbs/labels{/name}","releases_url":"https://api.github.com/repos/paypal/squbs/releases{/id}","deployments_url":"https://api.github.com/repos/paypal/squbs/deployments","created_at":"2015-07-07T20:48:12Z","updated_at":"2016-12-16T15:37:22Z","pushed_at":"2016-12-16T23:43:52Z","git_url":"git://github.com/paypal/squbs.git","ssh_url":"git@github.com:paypal/squbs.git","clone_url":"https://github.com/paypal/squbs.git","svn_url":"https://github.com/paypal/squbs","homepage":"http://paypal.github.io/squbs","size":6609,"stargazers_count":758,"watchers_count":758,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":121,"mirror_url":null,"open_issues_count":45,"forks":121,"open_issues":45,"watchers":758,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/paypal/squbs/pulls/341"},"html":{"href":"https://github.com/paypal/squbs/pull/341"},"issue":{"href":"https://api.github.com/repos/paypal/squbs/issues/341"},"comments":{"href":"https://api.github.com/repos/paypal/squbs/issues/341/comments"},"review_comments":{"href":"https://api.github.com/repos/paypal/squbs/pulls/341/comments"},"review_comment":{"href":"https://api.github.com/repos/paypal/squbs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/paypal/squbs/pulls/341/commits"},"statuses":{"href":"https://api.github.com/repos/paypal/squbs/statuses/4f71eb2cae0c1efbd1f33f96fffe46b0b3181c3c"}}}}
{"actor":{"display_login":"codacy-bot"}}