{"action":"created","comment":{"url":"https://api.github.com/repos/node-modules/cluster-client/pulls/comments/93167396","pull_request_review_id":13688929,"id":93167396,"diff_hunk":"@@ -0,0 +1,187 @@\n+'use strict';\n+\n+const co = require('co');\n+const Base = require('sdk-base');\n+const utils = require('./utils');\n+const Leader = require('./leader');\n+const Follower = require('./follower');\n+const ClusterServer = require('./server');\n+\n+// Symbols\n+const init = Symbol.for('ClusterClient#init');\n+const logger = Symbol.for('ClusterClient#logger');\n+const isReady = Symbol.for('ClusterClient#isReady');\n+const isLeader = Symbol.for('ClusterClient#isLeader');\n+const innerClient = Symbol.for('ClusterClient#innerClient');\n+const subscribe = Symbol.for('ClusterClient#subscribe');\n+const publish = Symbol.for('ClusterClient#publish');\n+const invoke = Symbol.for('ClusterClient#invoke');\n+const subInfo = Symbol.for('ClusterClient#subInfo');\n+const pubInfo = Symbol.for('ClusterClient#pubInfo');\n+\n+class ClusterClient extends Base {\n+  /**\n+   * Share Connection among Multi-Process Mode\n+   *\n+   * @param {Object} options\n+   *  - {Number} port - the port\n+   *  - {Transcode} transcode - serialze / deseriaze methods\n+   *  - {Boolean} isLeader - wehether is leader or follower\n+   *  - {Number} maxWaitTime - leader startup max time (ONLY effective on isLeader is true)\n+   *  - {Function} createRealClient - to create the real client instance\n+   * @constructor\n+   */\n+  constructor(options) {\n+    super(options);\n+    this._options = options;\n+    this[subInfo] = new Map();\n+    this[pubInfo] = new Map();\n+\n+    this[init]();\n+  }\n+\n+  /**\n+   * log instance\n+   * @property {Logger} ClusterClient#[logger]\n+   */\n+  get [logger]() {\n+    return this._options.logger;\n+  }\n+\n+  on(eventName, listener) {\n+    super.on(eventName, listener);\n+    if (this[innerClient]) {\n+      utils.delegateEvents(this[innerClient], this, eventName);\n+    }\n+    return this;\n+  }\n+\n+  once(eventName, listener) {\n+    super.once(eventName, listener);\n+    if (this[innerClient]) {\n+      utils.delegateEvents(this[innerClient], this, eventName);\n+    }\n+    return this;\n+  }\n+\n+  /**\n+   * initialize, to  leader or follower\n+   *\n+   * @return {void}\n+   */\n+  [init]() {\n+    co(function* () {\n+      const name = this._options.name;\n+      const port = this._options.port;\n+      let server;\n+      if (this._options.isLeader === true) {","path":"lib/client.js","position":77,"original_position":77,"commit_id":"003eefcc56a97732dc365c711d8ac06419f69784","original_commit_id":"003eefcc56a97732dc365c711d8ac06419f69784","user":{"login":"gxcsoccer","id":1207064,"avatar_url":"https://avatars.githubusercontent.com/u/1207064?v=3","gravatar_id":"","url":"https://api.github.com/users/gxcsoccer","html_url":"https://github.com/gxcsoccer","followers_url":"https://api.github.com/users/gxcsoccer/followers","following_url":"https://api.github.com/users/gxcsoccer/following{/other_user}","gists_url":"https://api.github.com/users/gxcsoccer/gists{/gist_id}","starred_url":"https://api.github.com/users/gxcsoccer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gxcsoccer/subscriptions","organizations_url":"https://api.github.com/users/gxcsoccer/orgs","repos_url":"https://api.github.com/users/gxcsoccer/repos","events_url":"https://api.github.com/users/gxcsoccer/events{/privacy}","received_events_url":"https://api.github.com/users/gxcsoccer/received_events","type":"User","site_admin":false},"body":"一般人不用关注这个，就用抢占模式就好了，只有在 egg 里面才会指定 agent 是 leader。\r\n\r\n还有用 mode => 指定模式的化，还是需要有一个参数来指定那个是 leader","created_at":"2016-12-20T03:46:45Z","updated_at":"2016-12-20T03:46:45Z","html_url":"https://github.com/node-modules/cluster-client/pull/1#discussion_r93167396","pull_request_url":"https://api.github.com/repos/node-modules/cluster-client/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/node-modules/cluster-client/pulls/comments/93167396"},"html":{"href":"https://github.com/node-modules/cluster-client/pull/1#discussion_r93167396"},"pull_request":{"href":"https://api.github.com/repos/node-modules/cluster-client/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/node-modules/cluster-client/pulls/1","id":98535174,"html_url":"https://github.com/node-modules/cluster-client/pull/1","diff_url":"https://github.com/node-modules/cluster-client/pull/1.diff","patch_url":"https://github.com/node-modules/cluster-client/pull/1.patch","issue_url":"https://api.github.com/repos/node-modules/cluster-client/issues/1","number":1,"state":"open","locked":false,"title":"feat: implement cluster client","user":{"login":"gxcsoccer","id":1207064,"avatar_url":"https://avatars.githubusercontent.com/u/1207064?v=3","gravatar_id":"","url":"https://api.github.com/users/gxcsoccer","html_url":"https://github.com/gxcsoccer","followers_url":"https://api.github.com/users/gxcsoccer/followers","following_url":"https://api.github.com/users/gxcsoccer/following{/other_user}","gists_url":"https://api.github.com/users/gxcsoccer/gists{/gist_id}","starred_url":"https://api.github.com/users/gxcsoccer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gxcsoccer/subscriptions","organizations_url":"https://api.github.com/users/gxcsoccer/orgs","repos_url":"https://api.github.com/users/gxcsoccer/repos","events_url":"https://api.github.com/users/gxcsoccer/events{/privacy}","received_events_url":"https://api.github.com/users/gxcsoccer/received_events","type":"User","site_admin":false},"body":"1. Master/Slave => Leader/Follower\r\n2. 协议优化，将 body 拆分成 conn 和 app 两部分，便于 app 部分的自定义\r\n3. 订阅支持选择一个 client 分发和广播两种","created_at":"2016-12-19T09:53:30Z","updated_at":"2016-12-20T03:46:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3412d61908528dcff69b8ea5c9a26c1fd0c40e2a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/node-modules/cluster-client/pulls/1/commits","review_comments_url":"https://api.github.com/repos/node-modules/cluster-client/pulls/1/comments","review_comment_url":"https://api.github.com/repos/node-modules/cluster-client/pulls/comments{/number}","comments_url":"https://api.github.com/repos/node-modules/cluster-client/issues/1/comments","statuses_url":"https://api.github.com/repos/node-modules/cluster-client/statuses/003eefcc56a97732dc365c711d8ac06419f69784","head":{"label":"node-modules:first","ref":"first","sha":"003eefcc56a97732dc365c711d8ac06419f69784","user":{"login":"node-modules","id":7125868,"avatar_url":"https://avatars.githubusercontent.com/u/7125868?v=3","gravatar_id":"","url":"https://api.github.com/users/node-modules","html_url":"https://github.com/node-modules","followers_url":"https://api.github.com/users/node-modules/followers","following_url":"https://api.github.com/users/node-modules/following{/other_user}","gists_url":"https://api.github.com/users/node-modules/gists{/gist_id}","starred_url":"https://api.github.com/users/node-modules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/node-modules/subscriptions","organizations_url":"https://api.github.com/users/node-modules/orgs","repos_url":"https://api.github.com/users/node-modules/repos","events_url":"https://api.github.com/users/node-modules/events{/privacy}","received_events_url":"https://api.github.com/users/node-modules/received_events","type":"Organization","site_admin":false},"repo":{"id":76217388,"name":"cluster-client","full_name":"node-modules/cluster-client","owner":{"login":"node-modules","id":7125868,"avatar_url":"https://avatars.githubusercontent.com/u/7125868?v=3","gravatar_id":"","url":"https://api.github.com/users/node-modules","html_url":"https://github.com/node-modules","followers_url":"https://api.github.com/users/node-modules/followers","following_url":"https://api.github.com/users/node-modules/following{/other_user}","gists_url":"https://api.github.com/users/node-modules/gists{/gist_id}","starred_url":"https://api.github.com/users/node-modules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/node-modules/subscriptions","organizations_url":"https://api.github.com/users/node-modules/orgs","repos_url":"https://api.github.com/users/node-modules/repos","events_url":"https://api.github.com/users/node-modules/events{/privacy}","received_events_url":"https://api.github.com/users/node-modules/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/node-modules/cluster-client","description":"Sharing Connection among Multi-Process Nodejs","fork":false,"url":"https://api.github.com/repos/node-modules/cluster-client","forks_url":"https://api.github.com/repos/node-modules/cluster-client/forks","keys_url":"https://api.github.com/repos/node-modules/cluster-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/node-modules/cluster-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/node-modules/cluster-client/teams","hooks_url":"https://api.github.com/repos/node-modules/cluster-client/hooks","issue_events_url":"https://api.github.com/repos/node-modules/cluster-client/issues/events{/number}","events_url":"https://api.github.com/repos/node-modules/cluster-client/events","assignees_url":"https://api.github.com/repos/node-modules/cluster-client/assignees{/user}","branches_url":"https://api.github.com/repos/node-modules/cluster-client/branches{/branch}","tags_url":"https://api.github.com/repos/node-modules/cluster-client/tags","blobs_url":"https://api.github.com/repos/node-modules/cluster-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/node-modules/cluster-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/node-modules/cluster-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/node-modules/cluster-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/node-modules/cluster-client/statuses/{sha}","languages_url":"https://api.github.com/repos/node-modules/cluster-client/languages","stargazers_url":"https://api.github.com/repos/node-modules/cluster-client/stargazers","contributors_url":"https://api.github.com/repos/node-modules/cluster-client/contributors","subscribers_url":"https://api.github.com/repos/node-modules/cluster-client/subscribers","subscription_url":"https://api.github.com/repos/node-modules/cluster-client/subscription","commits_url":"https://api.github.com/repos/node-modules/cluster-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/node-modules/cluster-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/node-modules/cluster-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/node-modules/cluster-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/node-modules/cluster-client/contents/{+path}","compare_url":"https://api.github.com/repos/node-modules/cluster-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/node-modules/cluster-client/merges","archive_url":"https://api.github.com/repos/node-modules/cluster-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/node-modules/cluster-client/downloads","issues_url":"https://api.github.com/repos/node-modules/cluster-client/issues{/number}","pulls_url":"https://api.github.com/repos/node-modules/cluster-client/pulls{/number}","milestones_url":"https://api.github.com/repos/node-modules/cluster-client/milestones{/number}","notifications_url":"https://api.github.com/repos/node-modules/cluster-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/node-modules/cluster-client/labels{/name}","releases_url":"https://api.github.com/repos/node-modules/cluster-client/releases{/id}","deployments_url":"https://api.github.com/repos/node-modules/cluster-client/deployments","created_at":"2016-12-12T03:03:39Z","updated_at":"2016-12-12T03:03:39Z","pushed_at":"2016-12-19T18:06:49Z","git_url":"git://github.com/node-modules/cluster-client.git","ssh_url":"git@github.com:node-modules/cluster-client.git","clone_url":"https://github.com/node-modules/cluster-client.git","svn_url":"https://github.com/node-modules/cluster-client","homepage":null,"size":25,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"node-modules:master","ref":"master","sha":"1fd47d3d4f368d8166360715a9067cf8f157e7cf","user":{"login":"node-modules","id":7125868,"avatar_url":"https://avatars.githubusercontent.com/u/7125868?v=3","gravatar_id":"","url":"https://api.github.com/users/node-modules","html_url":"https://github.com/node-modules","followers_url":"https://api.github.com/users/node-modules/followers","following_url":"https://api.github.com/users/node-modules/following{/other_user}","gists_url":"https://api.github.com/users/node-modules/gists{/gist_id}","starred_url":"https://api.github.com/users/node-modules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/node-modules/subscriptions","organizations_url":"https://api.github.com/users/node-modules/orgs","repos_url":"https://api.github.com/users/node-modules/repos","events_url":"https://api.github.com/users/node-modules/events{/privacy}","received_events_url":"https://api.github.com/users/node-modules/received_events","type":"Organization","site_admin":false},"repo":{"id":76217388,"name":"cluster-client","full_name":"node-modules/cluster-client","owner":{"login":"node-modules","id":7125868,"avatar_url":"https://avatars.githubusercontent.com/u/7125868?v=3","gravatar_id":"","url":"https://api.github.com/users/node-modules","html_url":"https://github.com/node-modules","followers_url":"https://api.github.com/users/node-modules/followers","following_url":"https://api.github.com/users/node-modules/following{/other_user}","gists_url":"https://api.github.com/users/node-modules/gists{/gist_id}","starred_url":"https://api.github.com/users/node-modules/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/node-modules/subscriptions","organizations_url":"https://api.github.com/users/node-modules/orgs","repos_url":"https://api.github.com/users/node-modules/repos","events_url":"https://api.github.com/users/node-modules/events{/privacy}","received_events_url":"https://api.github.com/users/node-modules/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/node-modules/cluster-client","description":"Sharing Connection among Multi-Process Nodejs","fork":false,"url":"https://api.github.com/repos/node-modules/cluster-client","forks_url":"https://api.github.com/repos/node-modules/cluster-client/forks","keys_url":"https://api.github.com/repos/node-modules/cluster-client/keys{/key_id}","collaborators_url":"https://api.github.com/repos/node-modules/cluster-client/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/node-modules/cluster-client/teams","hooks_url":"https://api.github.com/repos/node-modules/cluster-client/hooks","issue_events_url":"https://api.github.com/repos/node-modules/cluster-client/issues/events{/number}","events_url":"https://api.github.com/repos/node-modules/cluster-client/events","assignees_url":"https://api.github.com/repos/node-modules/cluster-client/assignees{/user}","branches_url":"https://api.github.com/repos/node-modules/cluster-client/branches{/branch}","tags_url":"https://api.github.com/repos/node-modules/cluster-client/tags","blobs_url":"https://api.github.com/repos/node-modules/cluster-client/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/node-modules/cluster-client/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/node-modules/cluster-client/git/refs{/sha}","trees_url":"https://api.github.com/repos/node-modules/cluster-client/git/trees{/sha}","statuses_url":"https://api.github.com/repos/node-modules/cluster-client/statuses/{sha}","languages_url":"https://api.github.com/repos/node-modules/cluster-client/languages","stargazers_url":"https://api.github.com/repos/node-modules/cluster-client/stargazers","contributors_url":"https://api.github.com/repos/node-modules/cluster-client/contributors","subscribers_url":"https://api.github.com/repos/node-modules/cluster-client/subscribers","subscription_url":"https://api.github.com/repos/node-modules/cluster-client/subscription","commits_url":"https://api.github.com/repos/node-modules/cluster-client/commits{/sha}","git_commits_url":"https://api.github.com/repos/node-modules/cluster-client/git/commits{/sha}","comments_url":"https://api.github.com/repos/node-modules/cluster-client/comments{/number}","issue_comment_url":"https://api.github.com/repos/node-modules/cluster-client/issues/comments{/number}","contents_url":"https://api.github.com/repos/node-modules/cluster-client/contents/{+path}","compare_url":"https://api.github.com/repos/node-modules/cluster-client/compare/{base}...{head}","merges_url":"https://api.github.com/repos/node-modules/cluster-client/merges","archive_url":"https://api.github.com/repos/node-modules/cluster-client/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/node-modules/cluster-client/downloads","issues_url":"https://api.github.com/repos/node-modules/cluster-client/issues{/number}","pulls_url":"https://api.github.com/repos/node-modules/cluster-client/pulls{/number}","milestones_url":"https://api.github.com/repos/node-modules/cluster-client/milestones{/number}","notifications_url":"https://api.github.com/repos/node-modules/cluster-client/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/node-modules/cluster-client/labels{/name}","releases_url":"https://api.github.com/repos/node-modules/cluster-client/releases{/id}","deployments_url":"https://api.github.com/repos/node-modules/cluster-client/deployments","created_at":"2016-12-12T03:03:39Z","updated_at":"2016-12-12T03:03:39Z","pushed_at":"2016-12-19T18:06:49Z","git_url":"git://github.com/node-modules/cluster-client.git","ssh_url":"git@github.com:node-modules/cluster-client.git","clone_url":"https://github.com/node-modules/cluster-client.git","svn_url":"https://github.com/node-modules/cluster-client","homepage":null,"size":25,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/node-modules/cluster-client/pulls/1"},"html":{"href":"https://github.com/node-modules/cluster-client/pull/1"},"issue":{"href":"https://api.github.com/repos/node-modules/cluster-client/issues/1"},"comments":{"href":"https://api.github.com/repos/node-modules/cluster-client/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/node-modules/cluster-client/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/node-modules/cluster-client/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/node-modules/cluster-client/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/node-modules/cluster-client/statuses/003eefcc56a97732dc365c711d8ac06419f69784"}}}}
{"actor":{"display_login":"gxcsoccer"}}