use of javax.management.remote.JMXServiceURL in project LogHub by fbacchella.
the class Helper method start.
public static JMXConnectorServer start(PROTOCOL protocol, String host, int port) throws IOException, NotBoundException {
MBeanServer mbs;
JMXServiceURL url;
JMXConnectorServer cs;
String path = "/";
String protocolString = protocol.toString();
Map<String, Object> jmxenv = new HashMap<>();
if (protocol == PROTOCOL.rmi) {
// If listen bound to a given ip, and jmx protocol is rmi, use it as the rmi's property hostname.
if (!"0.0.0.0".equals(host) && System.getProperty("java.rmi.server.hostname") == null) {
System.setProperty("java.rmi.server.hostname", host);
// Not sure if it's useful, hostname is resolve in sun.rmi.transport.tcp.TCPEndpoint, using InetAddress.getLocalHost() if
// this property is not defined.
// But it might be hiding in other places
jmxenv.put("java.rmi.server.hostname", host);
}
protocolString = "rmi";
java.rmi.registry.LocateRegistry.createRegistry(port);
path = "/jndi/rmi://" + host + ":" + port + "/jmxrmi";
}
url = new JMXServiceURL(protocolString, host, port, path);
mbs = ManagementFactory.getPlatformMBeanServer();
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, jmxenv, mbs);
cs.start();
return cs;
}
use of javax.management.remote.JMXServiceURL in project jbossws-cxf by jbossws.
the class JBossWSTestHelper method getServerConnection.
private static MBeanServerConnection getServerConnection(String jmxServiceUrl) {
final String urlString = System.getProperty("jmx.service.url", jmxServiceUrl);
JMXServiceURL serviceURL = null;
JMXConnector connector = null;
try {
serviceURL = new JMXServiceURL(urlString);
} catch (MalformedURLException e1) {
throw new IllegalStateException(e1);
}
// add more tries to get the connection. Workaround to fix some test failures caused by connection is not established in 5 seconds
for (int i = 0; i < AS_SERVER_CONN_RETRIEVAL_ATTEMPTS && connector == null; i++) {
try {
connector = JMXConnectorFactory.connect(serviceURL, null);
} catch (IOException ex) {
throw new IllegalStateException("Cannot obtain MBeanServerConnection to: " + urlString, ex);
} catch (RuntimeException e) {
if (e.getMessage().contains("WAITING") && i < AS_SERVER_CONN_RETRIEVAL_ATTEMPTS - 1) {
continue;
} else {
throw e;
}
}
}
try {
return connector.getMBeanServerConnection();
} catch (Exception e) {
throw new IllegalStateException("Cannot obtain MBeanServerConnection to: " + urlString, e);
}
}
use of javax.management.remote.JMXServiceURL in project fabric8 by fabric8io.
the class RestJsonSchemaJMXTest method connectToMBserver.
private void connectToMBserver() throws IOException {
jmxServerURL = jmxServerURL == null ? DEFAULT_JMXSERVICE_URL : jmxServerURL;
JMXServiceURL url = new JMXServiceURL(jmxServerURL);
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
mbsc = jmxc.getMBeanServerConnection();
}
use of javax.management.remote.JMXServiceURL in project derby by apache.
the class JMXConnectionDecorator method getJmxUrl.
/**
* Creates a URL for connecting to the platform MBean server on the host
* specified by the network server hostname of this test configuration.
* The JMX port number used is also retreived from the test configuration.
* @return a service URL for connecting to the platform MBean server
* @throws MalformedURLException if the URL is malformed
*/
private JMXServiceURL getJmxUrl() throws MalformedURLException {
// NOTE: This hostname is only valid in a client/server configuration
String hostname = TestConfiguration.getCurrent().getHostName();
// String hostname = TestConfiguration.DEFAULT_HOSTNAME; // for embedded?
int jmxPort = TestConfiguration.getCurrent().getJmxPort();
/* "jmxrmi" is the name of the RMI server connector of the platform
* MBean server, which is used by Derby */
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + hostname + ":" + jmxPort + "/jmxrmi");
return url;
}
use of javax.management.remote.JMXServiceURL in project bboxdb by jnidzwetzki.
the class Shutdown method main.
/**
* Call the JMX service to shutdown the application
*
* @param args
*/
public static void main(final String[] args) throws Exception {
if (args.length != 2) {
System.err.println("Usage: Shutdown <Port> <Password>");
System.exit(-1);
}
final int jmxPort = MathUtil.tryParseIntOrExit(args[0], () -> args[0] + " is not a valid port");
final String password = args[1];
// Set username and password
final Map<String, String[]> env = new HashMap<>();
final String[] credentials = { "controlRoleUser", password };
env.put(JMXConnector.CREDENTIALS, credentials);
// Connect to JMX
System.out.println("Connecting to JMX shutdown service.");
final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + jmxPort + "/jmxrmi");
final JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
final ObjectName mbeanName = new ObjectName(JMXService.MBEAN_LIFECYCLE);
final LifecycleMBean mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, LifecycleMBean.class, true);
try {
mbeanProxy.shutdown();
jmxc.close();
} catch (Exception e) {
// Server performs shutdown, JMX connection will be terminated
// So, ignore exception
}
}
Aggregations