{"action":"created","comment":{"url":"https://api.github.com/repos/paypal/squbs/pulls/comments/43341903","id":43341903,"diff_hunk":"@@ -0,0 +1,115 @@\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.admin\n+\n+import java.lang.management.ManagementFactory\n+import javax.management.ObjectName\n+import javax.management.openmbean.{CompositeData, TabularData}\n+\n+import scala.collection.JavaConversions._\n+import scala.collection.immutable.StringOps\n+\n+object MBeanUtil {\n+\n+  val indentStep = 2\n+\n+  val server = ManagementFactory.getPlatformMBeanServer\n+\n+  def allObjectNames: Seq[String] = {\n+    val beans = server.queryMBeans(null, null)\n+    beans.map { bean =>\n+      bean.getObjectName.toString\n+    } .toSeq.sorted\n+  }\n+\n+  def asJSON(beanName: String): String = {\n+    val objectName = new ObjectName(beanName)\n+    server.getMBeanInfo(objectName).getAttributes.map { _.getName } .sorted.map { name =>\n+      writeProperty(name, option { server.getAttribute(objectName, name) }, indentStep)\n+    } .mkString(\"{\\n\", \",\\n\", \"\\n}\")\n+  }\n+\n+  private def writeProperty(key: String, value: Option[AnyRef], indent: Int): String = {\n+    val pad = space(indent)\n+    value match {\n+\n+      case Some(table: TabularData) =>\n+        val list = table.values.toArray\n+        val render = option { writeKeyValueList(list, indent) } getOrElse { writeArray(list, indent) }\n+        s\"\"\"$pad\"$key\" : $render\"\"\"\n+\n+      case Some(list: Array[_]) =>\n+        val render = option { writeKeyValueList(list, indent) } getOrElse { writeArray(list, indent) }\n+        s\"\"\"$pad\"$key\" : $render\"\"\"\n+\n+      case Some(c: CompositeData) => s\"\"\"$pad\"$key\" : ${writeProperties(c, indent)}\"\"\"\n+\n+      case Some(v: java.lang.Number) => s\"\"\"$pad\"$key\" : $v\"\"\"\n+\n+      case Some(v: java.lang.Boolean) => s\"\"\"$pad\"$key\" : $v\"\"\"\n+\n+      case Some(v) => s\"\"\"$pad\"$key\" : \"${clean(v.toString)}\"\"\"\"\n+\n+      case None => s\"\"\"$pad\"$key\" : null\"\"\"\n+    }\n+  }\n+\n+  private def writeArray(list: Array[_], indent: Int): String = {\n+    val pad = space(indent)\n+    val pad2 = space(indent + indentStep)\n+    list.map {\n+      case c: CompositeData => pad2 + writeProperties(c, indent + indentStep)\n+      case n: java.lang.Number => pad2 + n\n+      case b: java.lang.Boolean => pad2 + b\n+      case v => s\"\"\"$pad2\"${clean(v.toString)}\"\"\"\"\n+    } .mkString(\"[\\n\", \",\\n\", s\"\\n$pad]\")\n+  }\n+\n+  private def writeKeyValueList(list: Array[_], indent: Int): String = {\n+    val pad = space(indent)\n+    val kv = list.map {\n+      case c: CompositeData =>\n+        val keySet = c.getCompositeType.keySet\n+        if (keySet.size == 2 && keySet.contains(\"key\") && keySet.contains(\"value\"))\n+          c.get(\"key\").asInstanceOf[String] -> c\n+        else throw new ClassCastException(\"CompositeData member is not a key/value pair\")\n+      case _ => throw new ClassCastException(\"Non-CompositeData value\")\n+    }\n+    kv.map {\n+      case (k, c) => writeProperty(k, option { c.get(\"value\") }, indent + indentStep)\n+    } .mkString(\"{\\n\", \",\\n\", s\"\\n$pad}\")\n+  }\n+\n+  private def writeProperties(c: CompositeData, indent: Int): String = {\n+    val pad = space(indent)\n+    c.getCompositeType.keySet.toSeq.sorted.map { key =>\n+      writeProperty(key, option { c.get(key) }, indent + indentStep)\n+    } .mkString(\"{\\n\", \",\\n\", s\"\\n$pad}\")\n+  }\n+\n+  private def space(indent: Int): String = new StringOps(\" \") * indent\n+\n+  private def clean(s: String): String = s.replace(\"\\n\", \"\\\\n\").replace(\"\\r\", \"\\\\r\").replace(\"\\t\", \"\\\\t\")\n+\n+  private def option[T](fn: => T): Option[T] = {\n+    try {","path":"squbs-admin/src/main/scala/org/squbs/admin/MBeanUtil.scala","position":109,"original_position":109,"commit_id":"21dbdfd6b62a390c6457597a1c1553e773f12ee7","original_commit_id":"21dbdfd6b62a390c6457597a1c1553e773f12ee7","user":{"login":"akara","id":77111,"avatar_url":"https://avatars.githubusercontent.com/u/77111?v=3","gravatar_id":"","url":"https://api.github.com/users/akara","html_url":"https://github.com/akara","followers_url":"https://api.github.com/users/akara/followers","following_url":"https://api.github.com/users/akara/following{/other_user}","gists_url":"https://api.github.com/users/akara/gists{/gist_id}","starred_url":"https://api.github.com/users/akara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akara/subscriptions","organizations_url":"https://api.github.com/users/akara/orgs","repos_url":"https://api.github.com/users/akara/repos","events_url":"https://api.github.com/users/akara/events{/privacy}","received_events_url":"https://api.github.com/users/akara/received_events","type":"User","site_admin":false},"body":"![Codacy](https://www.codacy.com/versioned/images/favicon.png) Issue found: [Consider using util.Try instead of a try-catch block](https://www.codacy.com/app/akara-sucharitakul/squbs/file/1210170920/issues/source?bid=2917668&fileBranchId=2928728#l109)","created_at":"2015-10-29T02:06:11Z","updated_at":"2015-10-29T02:06:11Z","html_url":"https://github.com/paypal/squbs/pull/121#discussion_r43341903","pull_request_url":"https://api.github.com/repos/paypal/squbs/pulls/121","_links":{"self":{"href":"https://api.github.com/repos/paypal/squbs/pulls/comments/43341903"},"html":{"href":"https://github.com/paypal/squbs/pull/121#discussion_r43341903"},"pull_request":{"href":"https://api.github.com/repos/paypal/squbs/pulls/121"}}},"pull_request":{"url":"https://api.github.com/repos/paypal/squbs/pulls/121","id":49072501,"html_url":"https://github.com/paypal/squbs/pull/121","diff_url":"https://github.com/paypal/squbs/pull/121.diff","patch_url":"https://github.com/paypal/squbs/pull/121.patch","issue_url":"https://api.github.com/repos/paypal/squbs/issues/121","number":121,"state":"open","locked":false,"title":"#31 Admin Console","user":{"login":"akara","id":77111,"avatar_url":"https://avatars.githubusercontent.com/u/77111?v=3","gravatar_id":"","url":"https://api.github.com/users/akara","html_url":"https://github.com/akara","followers_url":"https://api.github.com/users/akara/followers","following_url":"https://api.github.com/users/akara/following{/other_user}","gists_url":"https://api.github.com/users/akara/gists{/gist_id}","starred_url":"https://api.github.com/users/akara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akara/subscriptions","organizations_url":"https://api.github.com/users/akara/orgs","repos_url":"https://api.github.com/users/akara/repos","events_url":"https://api.github.com/users/akara/events{/privacy}","received_events_url":"https://api.github.com/users/akara/received_events","type":"User","site_admin":false},"body":"Please do code review and provide me feedback. But do not merge until after you've seen the demo and all feedback has been given.","created_at":"2015-10-28T21:54:09Z","updated_at":"2015-10-29T02:06:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"17c80081b0579ae38ec38d0d28ea4e2137ef0171","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/paypal/squbs/pulls/121/commits","review_comments_url":"https://api.github.com/repos/paypal/squbs/pulls/121/comments","review_comment_url":"https://api.github.com/repos/paypal/squbs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/paypal/squbs/issues/121/comments","statuses_url":"https://api.github.com/repos/paypal/squbs/statuses/21dbdfd6b62a390c6457597a1c1553e773f12ee7","head":{"label":"akara:admin","ref":"admin","sha":"21dbdfd6b62a390c6457597a1c1553e773f12ee7","user":{"login":"akara","id":77111,"avatar_url":"https://avatars.githubusercontent.com/u/77111?v=3","gravatar_id":"","url":"https://api.github.com/users/akara","html_url":"https://github.com/akara","followers_url":"https://api.github.com/users/akara/followers","following_url":"https://api.github.com/users/akara/following{/other_user}","gists_url":"https://api.github.com/users/akara/gists{/gist_id}","starred_url":"https://api.github.com/users/akara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akara/subscriptions","organizations_url":"https://api.github.com/users/akara/orgs","repos_url":"https://api.github.com/users/akara/repos","events_url":"https://api.github.com/users/akara/events{/privacy}","received_events_url":"https://api.github.com/users/akara/received_events","type":"User","site_admin":false},"repo":{"id":40934086,"name":"squbs","full_name":"akara/squbs","owner":{"login":"akara","id":77111,"avatar_url":"https://avatars.githubusercontent.com/u/77111?v=3","gravatar_id":"","url":"https://api.github.com/users/akara","html_url":"https://github.com/akara","followers_url":"https://api.github.com/users/akara/followers","following_url":"https://api.github.com/users/akara/following{/other_user}","gists_url":"https://api.github.com/users/akara/gists{/gist_id}","starred_url":"https://api.github.com/users/akara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akara/subscriptions","organizations_url":"https://api.github.com/users/akara/orgs","repos_url":"https://api.github.com/users/akara/repos","events_url":"https://api.github.com/users/akara/events{/privacy}","received_events_url":"https://api.github.com/users/akara/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/akara/squbs","description":"","fork":true,"url":"https://api.github.com/repos/akara/squbs","forks_url":"https://api.github.com/repos/akara/squbs/forks","keys_url":"https://api.github.com/repos/akara/squbs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akara/squbs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akara/squbs/teams","hooks_url":"https://api.github.com/repos/akara/squbs/hooks","issue_events_url":"https://api.github.com/repos/akara/squbs/issues/events{/number}","events_url":"https://api.github.com/repos/akara/squbs/events","assignees_url":"https://api.github.com/repos/akara/squbs/assignees{/user}","branches_url":"https://api.github.com/repos/akara/squbs/branches{/branch}","tags_url":"https://api.github.com/repos/akara/squbs/tags","blobs_url":"https://api.github.com/repos/akara/squbs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akara/squbs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akara/squbs/git/refs{/sha}","trees_url":"https://api.github.com/repos/akara/squbs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akara/squbs/statuses/{sha}","languages_url":"https://api.github.com/repos/akara/squbs/languages","stargazers_url":"https://api.github.com/repos/akara/squbs/stargazers","contributors_url":"https://api.github.com/repos/akara/squbs/contributors","subscribers_url":"https://api.github.com/repos/akara/squbs/subscribers","subscription_url":"https://api.github.com/repos/akara/squbs/subscription","commits_url":"https://api.github.com/repos/akara/squbs/commits{/sha}","git_commits_url":"https://api.github.com/repos/akara/squbs/git/commits{/sha}","comments_url":"https://api.github.com/repos/akara/squbs/comments{/number}","issue_comment_url":"https://api.github.com/repos/akara/squbs/issues/comments{/number}","contents_url":"https://api.github.com/repos/akara/squbs/contents/{+path}","compare_url":"https://api.github.com/repos/akara/squbs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akara/squbs/merges","archive_url":"https://api.github.com/repos/akara/squbs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akara/squbs/downloads","issues_url":"https://api.github.com/repos/akara/squbs/issues{/number}","pulls_url":"https://api.github.com/repos/akara/squbs/pulls{/number}","milestones_url":"https://api.github.com/repos/akara/squbs/milestones{/number}","notifications_url":"https://api.github.com/repos/akara/squbs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akara/squbs/labels{/name}","releases_url":"https://api.github.com/repos/akara/squbs/releases{/id}","created_at":"2015-08-17T22:35:29Z","updated_at":"2015-08-17T22:35:30Z","pushed_at":"2015-10-28T21:50:47Z","git_url":"git://github.com/akara/squbs.git","ssh_url":"git@github.com:akara/squbs.git","clone_url":"https://github.com/akara/squbs.git","svn_url":"https://github.com/akara/squbs","homepage":null,"size":5776,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"paypal:develop","ref":"develop","sha":"08b639620276d0f69a62265df20633eb24eb1091","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}","created_at":"2015-07-07T20:48:12Z","updated_at":"2015-10-25T08:18:45Z","pushed_at":"2015-10-28T21:54:11Z","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":"","size":6354,"stargazers_count":11,"watchers_count":11,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":33,"forks":15,"open_issues":33,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/paypal/squbs/pulls/121"},"html":{"href":"https://github.com/paypal/squbs/pull/121"},"issue":{"href":"https://api.github.com/repos/paypal/squbs/issues/121"},"comments":{"href":"https://api.github.com/repos/paypal/squbs/issues/121/comments"},"review_comments":{"href":"https://api.github.com/repos/paypal/squbs/pulls/121/comments"},"review_comment":{"href":"https://api.github.com/repos/paypal/squbs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/paypal/squbs/pulls/121/commits"},"statuses":{"href":"https://api.github.com/repos/paypal/squbs/statuses/21dbdfd6b62a390c6457597a1c1553e773f12ee7"}}}}