Wednesday, 15 April 2015

rmi - Has LocateRegistry.createRegistry(int port) changed in java 1.7? -



rmi - Has LocateRegistry.createRegistry(int port) changed in java 1.7? -

we have several server side components in our architecture. each component uses jmx expose various internal attributes. initialization done follows:

try { registry registry = null; for(int = _serverinfo.getjmxstartport(); <= _serverinfo.getjmxendport(); i++) { seek { registry = locateregistry.createregistry(i); if(registry != null) { _statusport = i; logger.info("using jmx port: "+_statusport); break; } } grab (exception e) { _statusport++; } } mbeanserver mbs = managementfactory.getplatformmbeanserver(); _abstractservicecontroller = new abstractservicecontroller(this); objectname mbeanname = new objectname("myserver:name=myserver service"); mbs.registermbean(_abstractservicecontroller, mbeanname); jmxserviceurl url = new jmxserviceurl("service:jmx:rmi:///jndi/rmi://:"+_statusport+"/jmxrmi"); jmxconnectorserver cs = jmxconnectorserverfactory.newjmxconnectorserver(url, system.getenv(), mbs); cs.start(); } grab (throwable e) { logger.error("unable register mbean jmx"); e.printstacktrace(); }

i guess have 2 questions.

does right?

the bigger question is, while runs fine on java 1.6 (each subsequent server on host uses next available port, since locateregistry.createregistry(i) throws exception if port unavailable), not on 1.7. result, next exception when sec server attempts jmxconnectorserver.start(). know if behavior changed createregistry? if so, there else should do?

2013-02-07 15:34:28,451 info [main] using jmx port: 9500 2013-02-07 15:34:28,929 error [main] unable register mbean jmx java.io.ioexception: cannot bind url [rmi://:9500/jmxrmi]: javax.naming.namealreadyboundexception: jmxrmi [root exception java.rmi.alreadyboundexception: jmxrmi] @ javax.management.remote.rmi.rmiconnectorserver.newioexception(rmiconnectorserve.java:826) @ javax.management.remote.rmi.rmiconnectorserver.start(rmiconnectorserver.java:431) @ com.theatre.services.framework.abstractservice.run(abstractservice.java:306) @ com.theatre.services.reporttree.treeserverimpl.run(treeserverimpl.java:690) @ com.theatre.services.framework.launcher.main(launcher.java:99) caused by: javax.naming.namealreadyboundexception: jmxrmi [root exception java.rmi.alreadyboundexception: jmxrmi] @ com.sun.jndi.rmi.registry.registrycontext.bind(registrycontext.java:139) @ com.sun.jndi.toolkit.url.genericurlcontext.bind(genericurlcontext.java:226) @ javax.naming.initialcontext.bind(initialcontext.java:419) @ javax.management.remote.rmi.rmiconnectorserver.bind(rmiconnectorserver.java:643) @ javax.management.remote.rmi.rmiconnectorserver.start(rmiconnectorserver.java:426) ... 3 more caused by: java.rmi.alreadyboundexception: jmxrmi @ sun.rmi.registry.registryimpl.bind(registryimpl.java:131) @ sun.rmi.registry.registryimpl_skel.dispatch(unknown source) @ sun.rmi.server.unicastserverref.olddispatch(unicastserverref.java:390) @ sun.rmi.server.unicastserverref.dispatch(unicastserverref.java:248) @ sun.rmi.transport.transport$1.run(transport.java:159) @ java.security.accesscontroller.doprivileged(native method) @ sun.rmi.transport.transport.servicecall(transport.java:155) @ sun.rmi.transport.tcp.tcptransport.handlemessages(tcptransport.java:535) @ sun.rmi.transport.tcp.tcptransport$connectionhandler.run0(tcptransport.java:790) @ sun.rmi.transport.tcp.tcptransport$connectionhandler.run(tcptransport.java:649) @ java.util.concurrent.threadpoolexecutor$worker.runtask(threadpoolexecutor.java:886) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:908) @ java.lang.thread.run(thread.java:662) @ sun.rmi.transport.streamremotecall.exceptionreceivedfromserver(streamremotecall.java:273) @ sun.rmi.transport.streamremotecall.executecall(streamremotecall.java:251) @ sun.rmi.server.unicastref.invoke(unicastref.java:377) @ sun.rmi.registry.registryimpl_stub.bind(unknown source) @ com.sun.jndi.rmi.registry.registrycontext.bind(registrycontext.java:137) ... 7 more

does right?

no. creating registry can fail several reasons, not because port in use. registry cannot null after createregistry(), testing pointless. if you're trying find free port, open (and close) serversocket(). then create registry on port if worked.

the bigger question is, while runs fine on java 1.6 (each subsequent server on host uses next available port, since locateregistry.createregistry(i) throws exception if port unavailable), not on 1.7.

see above. creating registry can fail if there 1 running on port, in jdk. in before jdks fail if there 1 running on port in same jvm.

java rmi jmx

No comments:

Post a Comment