You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by na...@apache.org on 2016/05/06 18:18:01 UTC
samza git commit: SAMZA-932 - JMX port collisions in JmxServer
Repository: samza
Updated Branches:
refs/heads/master d4936b899 -> 5a673604a
SAMZA-932 - JMX port collisions in JmxServer
Project: http://git-wip-us.apache.org/repos/asf/samza/repo
Commit: http://git-wip-us.apache.org/repos/asf/samza/commit/5a673604
Tree: http://git-wip-us.apache.org/repos/asf/samza/tree/5a673604
Diff: http://git-wip-us.apache.org/repos/asf/samza/diff/5a673604
Branch: refs/heads/master
Commit: 5a673604abe129cfab124265af7eba3eb05fd83b
Parents: d4936b8
Author: Jacob Maes <ja...@gmail.com>
Authored: Fri May 6 11:17:32 2016 -0700
Committer: Navina Ramesh <nr...@linkedin.com>
Committed: Fri May 6 11:17:46 2016 -0700
----------------------------------------------------------------------
.../scala/org/apache/samza/metrics/JmxServer.scala | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/samza/blob/5a673604/samza-core/src/main/scala/org/apache/samza/metrics/JmxServer.scala
----------------------------------------------------------------------
diff --git a/samza-core/src/main/scala/org/apache/samza/metrics/JmxServer.scala b/samza-core/src/main/scala/org/apache/samza/metrics/JmxServer.scala
index e6204c1..ad00ca0 100644
--- a/samza-core/src/main/scala/org/apache/samza/metrics/JmxServer.scala
+++ b/samza-core/src/main/scala/org/apache/samza/metrics/JmxServer.scala
@@ -74,10 +74,22 @@ class JmxServer(requestedPort: Int) extends Logging {
updateSystemProperty("com.sun.management.jmxremote.ssl", "false")
updateSystemProperty("java.rmi.server.hostname", hostname)
+ // There's still a race condition in which this port is released and taken by
+ // another process before it is used for our server, but that will be even more
+ // rare than the collisions we experienced when incrementing the registry port.
+ def getEphemeralPort = {
+ val serverSocket = new ServerSocket(0)
+ try {
+ serverSocket.getLocalPort
+ } finally {
+ serverSocket.close()
+ }
+ }
+
val ssFactory = new UpfrontRMIServerSocketFactory
LocateRegistry.createRegistry(requestedPort, null, ssFactory)
val registryPort = ssFactory.lastSS.getLocalPort
- val serverPort = registryPort + 1 // In comparison to the registry port. Tiny chance of collision. Sigh.
+ val serverPort = getEphemeralPort
val mbs = ManagementFactory.getPlatformMBeanServer
val env = new util.HashMap[String, Object]()
val url = new JMXServiceURL("service:jmx:rmi://localhost:" + serverPort + "/jndi/rmi://localhost:" + registryPort + "/jmxrmi")