{"action":"created","comment":{"url":"https://api.github.com/repos/apache/storm/pulls/comments/54664622","id":54664622,"diff_hunk":"@@ -0,0 +1,390 @@\n+/**\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  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+package org.apache.storm.daemon;\n+\n+import com.codahale.metrics.Meter;\n+import com.codahale.metrics.MetricRegistry;\n+import com.sun.net.httpserver.HttpsServer;\n+import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;\n+import org.apache.commons.lang.StringUtils;\n+import org.apache.storm.Config;\n+import org.apache.storm.daemon.metrics.MetricsUtils;\n+import org.apache.storm.daemon.metrics.reporters.PreparableReporter;\n+import org.apache.storm.generated.*;\n+import org.apache.storm.logging.ThriftAccessLogger;\n+import org.apache.storm.security.auth.*;\n+import org.apache.storm.security.auth.authorizer.DRPCAuthorizerBase;\n+import org.apache.storm.ui.FilterConfiguration;\n+import org.apache.storm.ui.IConfigurator;\n+import org.apache.storm.ui.UIHelpers;\n+import org.apache.storm.utils.ConfigUtils;\n+import org.apache.storm.utils.Time;\n+import org.apache.storm.utils.Utils;\n+import org.apache.storm.utils.VersionInfo;\n+import org.apache.thrift.TException;\n+import org.eclipse.jetty.server.Server;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import javax.servlet.Servlet;\n+import java.security.Principal;\n+import java.util.*;\n+import java.util.concurrent.*;\n+import java.util.concurrent.atomic.AtomicInteger;\n+\n+public class DrpcServer implements DistributedRPC.Iface, DistributedRPCInvocations.Iface, Shutdownable {\n+\n+    private static final Logger LOG = LoggerFactory.getLogger(DrpcServer.class);\n+    private final Long timeoutCheckSecs = 5L;\n+\n+    private Map conf;\n+\n+    private ThriftServer handlerServer;\n+    private ThriftServer invokeServer;\n+    private IHttpCredentialsPlugin httpCredsHandler;\n+\n+    private Thread clearThread;\n+\n+    private IAuthorizer authorizer;\n+\n+    // To be removed after porting drpc.clj\n+    private Servlet httpServlet;\n+\n+    private AtomicInteger ctr = new AtomicInteger(0);\n+    private ConcurrentHashMap<String, Semaphore> idtoSem = new ConcurrentHashMap<String, Semaphore>();\n+    private ConcurrentHashMap<String, Object> idtoResult = new ConcurrentHashMap<String, Object>();\n+    private ConcurrentHashMap<String, Integer> idtoStart = new ConcurrentHashMap<String, Integer>();\n+    private ConcurrentHashMap<String, String> idtoFunction = new ConcurrentHashMap<String, String>();\n+    private ConcurrentHashMap<String, DRPCRequest> idtoRequest = new ConcurrentHashMap<String, DRPCRequest>();\n+    private ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>> requestQueues = new ConcurrentHashMap<String, ConcurrentLinkedQueue<DRPCRequest>>();\n+\n+    private final Meter meterHttpRequests = new MetricRegistry().meter(\"drpc:num-execute-http-requests\");\n+    private final Meter meterExecuteCalls = new MetricRegistry().meter(\"drpc:num-execute-calls\");\n+    private final Meter meterResultCalls = new MetricRegistry().meter(\"drpc:num-result-calls\");\n+    private final Meter meterFailRequestCalls = new MetricRegistry().meter(\"drpc:num-failRequest-calls\");\n+    private final Meter meterFetchRequestCalls = new MetricRegistry().meter(\"drpc:num-fetchRequest-calls\");\n+    private final Meter meterShutdownCalls = new MetricRegistry().meter(\"drpc:num-shutdown-calls\");\n+    \n+    public DrpcServer() {\n+\n+    }\n+\n+    public IHttpCredentialsPlugin getHttpCredsHandler() {\n+        return httpCredsHandler;\n+    }\n+\n+    public void setHttpCredsHandler(IHttpCredentialsPlugin httpCredsHandler) {\n+        this.httpCredsHandler = httpCredsHandler;\n+    }\n+\n+    public Servlet getHttpServlet() {\n+        return httpServlet;\n+    }\n+\n+    public void setHttpServlet(Servlet httpServlet) {\n+        this.httpServlet = httpServlet;\n+    }\n+\n+\n+\n+    private ThriftServer initHandlerServer(Map conf, final DrpcServer service) throws Exception {\n+        int port = (int) conf.get(Config.DRPC_PORT);\n+        if (port > 0) {\n+            handlerServer = new ThriftServer(conf, new DistributedRPC.Processor<DistributedRPC.Iface>(service), ThriftConnectionType.DRPC);\n+        }\n+        return handlerServer;\n+    }\n+\n+    private ThriftServer initInvokeServer(Map conf, final DrpcServer service) throws Exception {\n+        invokeServer = new ThriftServer(conf, new DistributedRPCInvocations.Processor<DistributedRPCInvocations.Iface>(service),\n+                ThriftConnectionType.DRPC_INVOCATIONS);\n+        return invokeServer;\n+    }\n+\n+    private void initServer() throws Exception {\n+        Integer drpcHttpPort = (Integer) conf.get(Config.DRPC_HTTP_PORT);\n+        handlerServer = initHandlerServer(conf, this);\n+        invokeServer = initInvokeServer(conf, this);\n+        httpCredsHandler = AuthUtils.GetDrpcHttpCredentialsPlugin(conf);\n+        Utils.addShutdownHookWithForceKillIn1Sec(new Runnable() {\n+            @Override\n+            public void run() {\n+                if (handlerServer != null) {\n+                    handlerServer.stop();\n+                } else {","path":"storm-core/src/jvm/org/apache/storm/daemon/DrpcServer.java","position":160,"original_position":129,"commit_id":"491ff9856eaaa8bc0bab6dbc073016b920500216","original_commit_id":"8e350d1cf1f16b0101d699de0016bb762061f1e3","user":{"login":"hustfxj","id":7270212,"avatar_url":"https://avatars.githubusercontent.com/u/7270212?v=3","gravatar_id":"","url":"https://api.github.com/users/hustfxj","html_url":"https://github.com/hustfxj","followers_url":"https://api.github.com/users/hustfxj/followers","following_url":"https://api.github.com/users/hustfxj/following{/other_user}","gists_url":"https://api.github.com/users/hustfxj/gists{/gist_id}","starred_url":"https://api.github.com/users/hustfxj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hustfxj/subscriptions","organizations_url":"https://api.github.com/users/hustfxj/orgs","repos_url":"https://api.github.com/users/hustfxj/repos","events_url":"https://api.github.com/users/hustfxj/events{/privacy}","received_events_url":"https://api.github.com/users/hustfxj/received_events","type":"User","site_admin":false},"body":"sorry. I make mistake","created_at":"2016-03-02T01:07:03Z","updated_at":"2016-03-02T01:07:03Z","html_url":"https://github.com/apache/storm/pull/1156#discussion_r54664622","pull_request_url":"https://api.github.com/repos/apache/storm/pulls/1156","_links":{"self":{"href":"https://api.github.com/repos/apache/storm/pulls/comments/54664622"},"html":{"href":"https://github.com/apache/storm/pull/1156#discussion_r54664622"},"pull_request":{"href":"https://api.github.com/repos/apache/storm/pulls/1156"}}},"pull_request":{"url":"https://api.github.com/repos/apache/storm/pulls/1156","id":60856121,"html_url":"https://github.com/apache/storm/pull/1156","diff_url":"https://github.com/apache/storm/pull/1156.diff","patch_url":"https://github.com/apache/storm/pull/1156.patch","issue_url":"https://api.github.com/repos/apache/storm/issues/1156","number":1156,"state":"open","locked":false,"title":"[STORM-1270]  [STORM-1274] port drpc&LocalDRPC  to java ","user":{"login":"hustfxj","id":7270212,"avatar_url":"https://avatars.githubusercontent.com/u/7270212?v=3","gravatar_id":"","url":"https://api.github.com/users/hustfxj","html_url":"https://github.com/hustfxj","followers_url":"https://api.github.com/users/hustfxj/followers","following_url":"https://api.github.com/users/hustfxj/following{/other_user}","gists_url":"https://api.github.com/users/hustfxj/gists{/gist_id}","starred_url":"https://api.github.com/users/hustfxj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hustfxj/subscriptions","organizations_url":"https://api.github.com/users/hustfxj/orgs","repos_url":"https://api.github.com/users/hustfxj/repos","events_url":"https://api.github.com/users/hustfxj/events{/privacy}","received_events_url":"https://api.github.com/users/hustfxj/received_events","type":"User","site_admin":false},"body":"1. Port \"org.apache.storm.daemon.drpc\" to java at \"org.apache.storm.daemon.DrpcServer\".\r\n2. Port \"org.apache.storm.LocalDRPC\" to java at \"org.apache.storm.LocalDRPC\".\r\n3. I keep the \"webapp\" of drpc.clj , as it's hard to translate and we will move ring to other REST framework. ","created_at":"2016-02-26T15:17:30Z","updated_at":"2016-03-02T01:07:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d0ba466fd23e0034a981fbf871a6a241cf6e6a38","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/storm/pulls/1156/commits","review_comments_url":"https://api.github.com/repos/apache/storm/pulls/1156/comments","review_comment_url":"https://api.github.com/repos/apache/storm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/storm/issues/1156/comments","statuses_url":"https://api.github.com/repos/apache/storm/statuses/491ff9856eaaa8bc0bab6dbc073016b920500216","head":{"label":"hustfxj:DRPC","ref":"DRPC","sha":"491ff9856eaaa8bc0bab6dbc073016b920500216","user":{"login":"hustfxj","id":7270212,"avatar_url":"https://avatars.githubusercontent.com/u/7270212?v=3","gravatar_id":"","url":"https://api.github.com/users/hustfxj","html_url":"https://github.com/hustfxj","followers_url":"https://api.github.com/users/hustfxj/followers","following_url":"https://api.github.com/users/hustfxj/following{/other_user}","gists_url":"https://api.github.com/users/hustfxj/gists{/gist_id}","starred_url":"https://api.github.com/users/hustfxj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hustfxj/subscriptions","organizations_url":"https://api.github.com/users/hustfxj/orgs","repos_url":"https://api.github.com/users/hustfxj/repos","events_url":"https://api.github.com/users/hustfxj/events{/privacy}","received_events_url":"https://api.github.com/users/hustfxj/received_events","type":"User","site_admin":false},"repo":{"id":50340543,"name":"storm","full_name":"hustfxj/storm","owner":{"login":"hustfxj","id":7270212,"avatar_url":"https://avatars.githubusercontent.com/u/7270212?v=3","gravatar_id":"","url":"https://api.github.com/users/hustfxj","html_url":"https://github.com/hustfxj","followers_url":"https://api.github.com/users/hustfxj/followers","following_url":"https://api.github.com/users/hustfxj/following{/other_user}","gists_url":"https://api.github.com/users/hustfxj/gists{/gist_id}","starred_url":"https://api.github.com/users/hustfxj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hustfxj/subscriptions","organizations_url":"https://api.github.com/users/hustfxj/orgs","repos_url":"https://api.github.com/users/hustfxj/repos","events_url":"https://api.github.com/users/hustfxj/events{/privacy}","received_events_url":"https://api.github.com/users/hustfxj/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hustfxj/storm","description":"Mirror of Apache Storm","fork":true,"url":"https://api.github.com/repos/hustfxj/storm","forks_url":"https://api.github.com/repos/hustfxj/storm/forks","keys_url":"https://api.github.com/repos/hustfxj/storm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hustfxj/storm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hustfxj/storm/teams","hooks_url":"https://api.github.com/repos/hustfxj/storm/hooks","issue_events_url":"https://api.github.com/repos/hustfxj/storm/issues/events{/number}","events_url":"https://api.github.com/repos/hustfxj/storm/events","assignees_url":"https://api.github.com/repos/hustfxj/storm/assignees{/user}","branches_url":"https://api.github.com/repos/hustfxj/storm/branches{/branch}","tags_url":"https://api.github.com/repos/hustfxj/storm/tags","blobs_url":"https://api.github.com/repos/hustfxj/storm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hustfxj/storm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hustfxj/storm/git/refs{/sha}","trees_url":"https://api.github.com/repos/hustfxj/storm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hustfxj/storm/statuses/{sha}","languages_url":"https://api.github.com/repos/hustfxj/storm/languages","stargazers_url":"https://api.github.com/repos/hustfxj/storm/stargazers","contributors_url":"https://api.github.com/repos/hustfxj/storm/contributors","subscribers_url":"https://api.github.com/repos/hustfxj/storm/subscribers","subscription_url":"https://api.github.com/repos/hustfxj/storm/subscription","commits_url":"https://api.github.com/repos/hustfxj/storm/commits{/sha}","git_commits_url":"https://api.github.com/repos/hustfxj/storm/git/commits{/sha}","comments_url":"https://api.github.com/repos/hustfxj/storm/comments{/number}","issue_comment_url":"https://api.github.com/repos/hustfxj/storm/issues/comments{/number}","contents_url":"https://api.github.com/repos/hustfxj/storm/contents/{+path}","compare_url":"https://api.github.com/repos/hustfxj/storm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hustfxj/storm/merges","archive_url":"https://api.github.com/repos/hustfxj/storm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hustfxj/storm/downloads","issues_url":"https://api.github.com/repos/hustfxj/storm/issues{/number}","pulls_url":"https://api.github.com/repos/hustfxj/storm/pulls{/number}","milestones_url":"https://api.github.com/repos/hustfxj/storm/milestones{/number}","notifications_url":"https://api.github.com/repos/hustfxj/storm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hustfxj/storm/labels{/name}","releases_url":"https://api.github.com/repos/hustfxj/storm/releases{/id}","deployments_url":"https://api.github.com/repos/hustfxj/storm/deployments","created_at":"2016-01-25T09:34:58Z","updated_at":"2016-01-25T09:35:02Z","pushed_at":"2016-02-27T13:12:05Z","git_url":"git://github.com/hustfxj/storm.git","ssh_url":"git@github.com:hustfxj/storm.git","clone_url":"https://github.com/hustfxj/storm.git","svn_url":"https://github.com/hustfxj/storm","homepage":null,"size":153860,"stargazers_count":0,"watchers_count":0,"language":"Java","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":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"73312ad56060567ffde044515d8193ed94f3b07f","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":14135470,"name":"storm","full_name":"apache/storm","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/storm","description":"Mirror of Apache Storm","fork":false,"url":"https://api.github.com/repos/apache/storm","forks_url":"https://api.github.com/repos/apache/storm/forks","keys_url":"https://api.github.com/repos/apache/storm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/storm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/storm/teams","hooks_url":"https://api.github.com/repos/apache/storm/hooks","issue_events_url":"https://api.github.com/repos/apache/storm/issues/events{/number}","events_url":"https://api.github.com/repos/apache/storm/events","assignees_url":"https://api.github.com/repos/apache/storm/assignees{/user}","branches_url":"https://api.github.com/repos/apache/storm/branches{/branch}","tags_url":"https://api.github.com/repos/apache/storm/tags","blobs_url":"https://api.github.com/repos/apache/storm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/storm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/storm/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/storm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/storm/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/storm/languages","stargazers_url":"https://api.github.com/repos/apache/storm/stargazers","contributors_url":"https://api.github.com/repos/apache/storm/contributors","subscribers_url":"https://api.github.com/repos/apache/storm/subscribers","subscription_url":"https://api.github.com/repos/apache/storm/subscription","commits_url":"https://api.github.com/repos/apache/storm/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/storm/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/storm/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/storm/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/storm/contents/{+path}","compare_url":"https://api.github.com/repos/apache/storm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/storm/merges","archive_url":"https://api.github.com/repos/apache/storm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/storm/downloads","issues_url":"https://api.github.com/repos/apache/storm/issues{/number}","pulls_url":"https://api.github.com/repos/apache/storm/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/storm/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/storm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/storm/labels{/name}","releases_url":"https://api.github.com/repos/apache/storm/releases{/id}","deployments_url":"https://api.github.com/repos/apache/storm/deployments","created_at":"2013-11-05T08:00:14Z","updated_at":"2016-03-01T11:08:58Z","pushed_at":"2016-03-02T00:47:47Z","git_url":"git://github.com/apache/storm.git","ssh_url":"git@github.com:apache/storm.git","clone_url":"https://github.com/apache/storm.git","svn_url":"https://github.com/apache/storm","homepage":null,"size":158809,"stargazers_count":2891,"watchers_count":2891,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":2172,"mirror_url":"git://git.apache.org/storm.git","open_issues_count":94,"forks":2172,"open_issues":94,"watchers":2891,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/storm/pulls/1156"},"html":{"href":"https://github.com/apache/storm/pull/1156"},"issue":{"href":"https://api.github.com/repos/apache/storm/issues/1156"},"comments":{"href":"https://api.github.com/repos/apache/storm/issues/1156/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/storm/pulls/1156/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/storm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/storm/pulls/1156/commits"},"statuses":{"href":"https://api.github.com/repos/apache/storm/statuses/491ff9856eaaa8bc0bab6dbc073016b920500216"}}}}