{"action":"created","comment":{"url":"https://api.github.com/repos/akka/akka/pulls/comments/28974148","id":28974148,"diff_hunk":"@@ -468,8 +465,47 @@ private[stream] class MaterializedValuePublisher extends Publisher[Any] {\n private[stream] abstract class MaterializerSession(val topLevel: StreamLayout.Module) {\n   import StreamLayout._\n \n-  private val subscribers = collection.mutable.HashMap[InPort, Subscriber[Any]]().withDefaultValue(null)\n-  private val publishers = collection.mutable.HashMap[OutPort, Publisher[Any]]().withDefaultValue(null)\n+  private var subscribersStack: List[mutable.Map[InPort, Subscriber[Any]]] =\n+    mutable.Map.empty[InPort, Subscriber[Any]].withDefaultValue(null) :: Nil\n+  private var publishersStack: List[mutable.Map[OutPort, Publisher[Any]]] =\n+    mutable.Map.empty[OutPort, Publisher[Any]].withDefaultValue(null) :: Nil\n+  private var moduleStack: List[Module] = topLevel :: Nil\n+\n+  private def subscribers: mutable.Map[InPort, Subscriber[Any]] = subscribersStack.head\n+  private def publishers: mutable.Map[OutPort, Publisher[Any]] = publishersStack.head\n+  private def currentLayout: Module = moduleStack.head\n+\n+  // Enters a copied module and establishes a scope that prevents internals to leak out and interfere with copies\n+  // of the same module.\n+  private def enterScope(enclosing: CopiedModule): Unit = {\n+    subscribersStack ::= mutable.Map.empty.withDefaultValue(null)\n+    publishersStack ::= mutable.Map.empty.withDefaultValue(null)\n+    moduleStack ::= enclosing.copyOf\n+  }\n+\n+  // Exits the scope of the copied module and propagates Publishers/Subscribers to the enclosing scope assigning\n+  // them to the copied ports instead of the original ones (since there might be multiple copies of the same module\n+  // leading to port identity collisions)\n+  private def exitScope(enclosing: CopiedModule): Unit = {","path":"akka-stream/src/main/scala/akka/stream/impl/StreamLayout.scala","position":300,"original_position":300,"commit_id":"5c61baa21b2fd80cf86bb26a42b8bf3b457af991","original_commit_id":"5c61baa21b2fd80cf86bb26a42b8bf3b457af991","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":"ah, I see, that subtlety escaped me (so the purpose of asking this question has been fulfilled ;-) )","created_at":"2015-04-23T15:36:38Z","updated_at":"2015-04-23T15:36:38Z","html_url":"https://github.com/akka/akka/pull/17280#discussion_r28974148","pull_request_url":"https://api.github.com/repos/akka/akka/pulls/17280","_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/comments/28974148"},"html":{"href":"https://github.com/akka/akka/pull/17280#discussion_r28974148"},"pull_request":{"href":"https://api.github.com/repos/akka/akka/pulls/17280"}}},"pull_request":{"url":"https://api.github.com/repos/akka/akka/pulls/17280","id":33950499,"html_url":"https://github.com/akka/akka/pull/17280","diff_url":"https://github.com/akka/akka/pull/17280.diff","patch_url":"https://github.com/akka/akka/pull/17280.patch","issue_url":"https://api.github.com/repos/akka/akka/issues/17280","number":17280,"state":"open","locked":false,"title":"=str #16940: Implement shallow copy for stream layouts","user":{"login":"drewhk","id":932285,"avatar_url":"https://avatars.githubusercontent.com/u/932285?v=3","gravatar_id":"","url":"https://api.github.com/users/drewhk","html_url":"https://github.com/drewhk","followers_url":"https://api.github.com/users/drewhk/followers","following_url":"https://api.github.com/users/drewhk/following{/other_user}","gists_url":"https://api.github.com/users/drewhk/gists{/gist_id}","starred_url":"https://api.github.com/users/drewhk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drewhk/subscriptions","organizations_url":"https://api.github.com/users/drewhk/orgs","repos_url":"https://api.github.com/users/drewhk/repos","events_url":"https://api.github.com/users/drewhk/events{/privacy}","received_events_url":"https://api.github.com/users/drewhk/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-04-23T12:32:40Z","updated_at":"2015-04-23T15:36:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7ec7ac6658cc956d309a7e623de8b05f04c620bd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/akka/akka/pulls/17280/commits","review_comments_url":"https://api.github.com/repos/akka/akka/pulls/17280/comments","review_comment_url":"https://api.github.com/repos/akka/akka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akka/akka/issues/17280/comments","statuses_url":"https://api.github.com/repos/akka/akka/statuses/5c61baa21b2fd80cf86bb26a42b8bf3b457af991","head":{"label":"drewhk:wip-16940-shallow-layout-copy-drewhk","ref":"wip-16940-shallow-layout-copy-drewhk","sha":"5c61baa21b2fd80cf86bb26a42b8bf3b457af991","user":{"login":"drewhk","id":932285,"avatar_url":"https://avatars.githubusercontent.com/u/932285?v=3","gravatar_id":"","url":"https://api.github.com/users/drewhk","html_url":"https://github.com/drewhk","followers_url":"https://api.github.com/users/drewhk/followers","following_url":"https://api.github.com/users/drewhk/following{/other_user}","gists_url":"https://api.github.com/users/drewhk/gists{/gist_id}","starred_url":"https://api.github.com/users/drewhk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drewhk/subscriptions","organizations_url":"https://api.github.com/users/drewhk/orgs","repos_url":"https://api.github.com/users/drewhk/repos","events_url":"https://api.github.com/users/drewhk/events{/privacy}","received_events_url":"https://api.github.com/users/drewhk/received_events","type":"User","site_admin":false},"repo":{"id":4322312,"name":"akka","full_name":"drewhk/akka","owner":{"login":"drewhk","id":932285,"avatar_url":"https://avatars.githubusercontent.com/u/932285?v=3","gravatar_id":"","url":"https://api.github.com/users/drewhk","html_url":"https://github.com/drewhk","followers_url":"https://api.github.com/users/drewhk/followers","following_url":"https://api.github.com/users/drewhk/following{/other_user}","gists_url":"https://api.github.com/users/drewhk/gists{/gist_id}","starred_url":"https://api.github.com/users/drewhk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drewhk/subscriptions","organizations_url":"https://api.github.com/users/drewhk/orgs","repos_url":"https://api.github.com/users/drewhk/repos","events_url":"https://api.github.com/users/drewhk/events{/privacy}","received_events_url":"https://api.github.com/users/drewhk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/drewhk/akka","description":"Akka Project","fork":true,"url":"https://api.github.com/repos/drewhk/akka","forks_url":"https://api.github.com/repos/drewhk/akka/forks","keys_url":"https://api.github.com/repos/drewhk/akka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/drewhk/akka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/drewhk/akka/teams","hooks_url":"https://api.github.com/repos/drewhk/akka/hooks","issue_events_url":"https://api.github.com/repos/drewhk/akka/issues/events{/number}","events_url":"https://api.github.com/repos/drewhk/akka/events","assignees_url":"https://api.github.com/repos/drewhk/akka/assignees{/user}","branches_url":"https://api.github.com/repos/drewhk/akka/branches{/branch}","tags_url":"https://api.github.com/repos/drewhk/akka/tags","blobs_url":"https://api.github.com/repos/drewhk/akka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/drewhk/akka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/drewhk/akka/git/refs{/sha}","trees_url":"https://api.github.com/repos/drewhk/akka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/drewhk/akka/statuses/{sha}","languages_url":"https://api.github.com/repos/drewhk/akka/languages","stargazers_url":"https://api.github.com/repos/drewhk/akka/stargazers","contributors_url":"https://api.github.com/repos/drewhk/akka/contributors","subscribers_url":"https://api.github.com/repos/drewhk/akka/subscribers","subscription_url":"https://api.github.com/repos/drewhk/akka/subscription","commits_url":"https://api.github.com/repos/drewhk/akka/commits{/sha}","git_commits_url":"https://api.github.com/repos/drewhk/akka/git/commits{/sha}","comments_url":"https://api.github.com/repos/drewhk/akka/comments{/number}","issue_comment_url":"https://api.github.com/repos/drewhk/akka/issues/comments{/number}","contents_url":"https://api.github.com/repos/drewhk/akka/contents/{+path}","compare_url":"https://api.github.com/repos/drewhk/akka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/drewhk/akka/merges","archive_url":"https://api.github.com/repos/drewhk/akka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/drewhk/akka/downloads","issues_url":"https://api.github.com/repos/drewhk/akka/issues{/number}","pulls_url":"https://api.github.com/repos/drewhk/akka/pulls{/number}","milestones_url":"https://api.github.com/repos/drewhk/akka/milestones{/number}","notifications_url":"https://api.github.com/repos/drewhk/akka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/drewhk/akka/labels{/name}","releases_url":"https://api.github.com/repos/drewhk/akka/releases{/id}","created_at":"2012-05-14T09:57:34Z","updated_at":"2015-02-17T12:40:08Z","pushed_at":"2015-04-23T14:33:26Z","git_url":"git://github.com/drewhk/akka.git","ssh_url":"git@github.com:drewhk/akka.git","clone_url":"https://github.com/drewhk/akka.git","svn_url":"https://github.com/drewhk/akka","homepage":"http://akka.io","size":161508,"stargazers_count":1,"watchers_count":1,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"akka:release-2.3-dev","ref":"release-2.3-dev","sha":"45a6418c74d68d75e70324b4daad75148157ca64","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-04-23T12:26:32Z","pushed_at":"2015-04-23T15:30:30Z","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":247969,"stargazers_count":3850,"watchers_count":3850,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1102,"mirror_url":null,"open_issues_count":646,"forks":1102,"open_issues":646,"watchers":3850,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/17280"},"html":{"href":"https://github.com/akka/akka/pull/17280"},"issue":{"href":"https://api.github.com/repos/akka/akka/issues/17280"},"comments":{"href":"https://api.github.com/repos/akka/akka/issues/17280/comments"},"review_comments":{"href":"https://api.github.com/repos/akka/akka/pulls/17280/comments"},"review_comment":{"href":"https://api.github.com/repos/akka/akka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akka/akka/pulls/17280/commits"},"statuses":{"href":"https://api.github.com/repos/akka/akka/statuses/5c61baa21b2fd80cf86bb26a42b8bf3b457af991"}}}}