public static void main(String[] args) throws Exception { JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); RMIJRMPServerImplSub impl = new RMIJRMPServerImplSub(); System.out.println("Creating connectorServer"); connectorServer = new RMIConnectorServer(url, null, impl, mbs); System.out.println("Starting connectorServer"); connectorServer.start(); System.out.println("Making client"); RMIConnection cc = impl.newClient(null); System.out.println("Closing client"); cc.close(); if (connectorServer.isActive()) { System.out.println("Stopping connectorServer"); connectorServer.stop(); } if (failure == null) System.out.println("TEST PASSED, no deadlock"); else System.out.println("TEST FAILED"); }
private void connect() throws IOException { System.out.println( "JMXConnectorThread: Attempting JMX connection on: " + addr + " on port " + jmxPort); JMXServiceURL url; try { url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + addr + ":" + jmxPort + "/jmxrmi"); } catch (MalformedURLException e) { throw new RuntimeException("Test failed.", e); } Map<String, Object> env = new HashMap<>(); if (useSSL) { SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory(); env.put("com.sun.jndi.rmi.factory.socket", csf); env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf); } // connect and immediately close JMXConnector c = JMXConnectorFactory.connect(url, env); c.close(); System.out.println("JMXConnectorThread: connection to JMX worked"); jmxConnectWorked = true; checkRmiSocket(); latch.countDown(); // signal we are done. }
static JmxConnector init(Properties props) throws IOException { Integer port = Integer.decode(props.getProperty(JMXEndpoint.JMX_RMI_PORT_PROPERTY)); if (!JmxConnectors.isPortAvailable(port)) return null; String name = "com.devexperts.qd.monitoring:type=RmiServer,port=" + port; RMIJRMPServerImpl srvImpl = new RMIJRMPServerImpl(port, null, null, null); RMIConnectorServer rmiServer = new RMIConnectorServer( new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + port + "/jmxrmi"), null, srvImpl, ManagementFactory.getPlatformMBeanServer()); ConnectorImpl connector = new ConnectorImpl(name, rmiServer); if (!JmxConnectors.addConnector(port, connector)) return null; // port is already taken LocateRegistry.createRegistry(port); connector.setRegistration(Management.registerMBean(rmiServer, null, name)); rmiServer.start(); QDLog.log.info("RMI management port is " + port); return connector; }
private void maybeInitJmx() { if (System.getProperty("com.sun.management.jmxremote.port") != null) return; String jmxPort = System.getProperty("cassandra.jmx.local.port"); if (jmxPort == null) return; System.setProperty("java.rmi.server.hostname", InetAddress.getLoopbackAddress().getHostAddress()); RMIServerSocketFactory serverFactory = new RMIServerSocketFactoryImpl(); Map<String, ?> env = Collections.singletonMap(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, serverFactory); try { LocateRegistry.createRegistry(Integer.valueOf(jmxPort), null, serverFactory); JMXServiceURL url = new JMXServiceURL(String.format("service:jmx:rmi://localhost/jndi/rmi://localhost:%s/jmxrmi", jmxPort)); jmxServer = new RMIConnectorServer(url, env, ManagementFactory.getPlatformMBeanServer()); jmxServer.start(); } catch (IOException e) { exitOrFail(1, e.getMessage(), e.getCause()); } }
public JMXConnectorServer newJMXConnectorServer(JMXServiceURL serviceURL, Map<String,?> environment, MBeanServer mbeanServer) throws IOException { if (!serviceURL.getProtocol().equals("rmi")) { throw new MalformedURLException("Protocol not rmi: " + serviceURL.getProtocol()); } return new RMIConnectorServer(serviceURL, environment, mbeanServer); }
public JMXConnectorServer newJMXConnectorServer(JMXServiceURL serviceURL, Map<String,?> environment, MBeanServer mbeanServer) throws IOException { if (!serviceURL.getProtocol().equals("iiop")) { throw new MalformedURLException("Protocol not iiop: " + serviceURL.getProtocol()); } return new RMIConnectorServer(serviceURL, environment, mbeanServer); }
@Override public @NotNull JMXConnector connect() throws IOException { final Map<String, Object> environment = environment(); if (ssl) { environment.put(Context.SECURITY_PROTOCOL, "ssl"); final SslRMIClientSocketFactory clientSocketFactory = new SslRMIClientSocketFactory(); environment.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, clientSocketFactory); environment.put("com.sun.jndi.rmi.factory.socket", clientSocketFactory); } final JMXServiceURL address = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + address() + "/jmxrmi"); return JMXConnectorFactory.connect(address, environment); }
private static boolean test(String proto, MBeanServer mbs) throws Exception { System.out.println("Testing for proto " + proto); JMXConnectorServer cs; JMXServiceURL url = new JMXServiceURL(proto, null, 0); try { cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); } catch (MalformedURLException e) { System.out.println("System does not recognize URL: " + url + "; ignoring"); return true; } cs.start(); JMXServiceURL addr = cs.getAddress(); JMXServiceURL rmiurl = new JMXServiceURL("rmi", null, 0); JMXConnector client = JMXConnectorFactory.connect(addr); MBeanServerConnection mbsc = client.getMBeanServerConnection(); ObjectName on = new ObjectName("x:proto=" + proto + ",ok=yes"); mbsc.createMBean(RMIConnectorServer.class.getName(), on, mletName, new Object[] {rmiurl, null}, new String[] {JMXServiceURL.class.getName(), Map.class.getName()}); System.out.println("Successfully deserialized with " + proto); mbsc.unregisterMBean(on); client.close(); cs.stop(); return true; }
public JMXConnectorServer newJMXConnectorServer(JMXServiceURL url, Map<String,?> map, MBeanServer mbeanServer) throws IOException { final String protocol = url.getProtocol(); called = true; System.out.println("JMXConnectorServerProviderImpl called"); if(protocol.equals("rmi")) return new RMIConnectorServer(url, map, mbeanServer); if(protocol.equals("throw-provider-exception")) throw new JMXProviderException("I have been asked to throw"); throw new IllegalArgumentException("UNKNOWN PROTOCOL"); }
private JMXConnector createJMXConnector() throws Exception { JMXServiceURL url = new JMXServiceURL(this.urlString); RMIServerSocketFactory ssf = new MX4JServerSocketFactory( true, true, "any", "any", new LocalLogWriter(LogWriterImpl.FINE_LEVEL), new Properties()); RMIClientSocketFactory csf = new SslRMIClientSocketFactory(); Map env = new HashMap(); env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf); env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf); return JMXConnectorFactory.connect(url, env); }