Search in sources :

Example 1 with RMIConnectorServer

use of javax.management.remote.rmi.RMIConnectorServer in project jdk8u_jdk by JetBrains.

the class JMXConnectorServerProviderImpl method newJMXConnectorServer.

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");
}
Also used : JMXProviderException(javax.management.remote.JMXProviderException) RMIConnectorServer(javax.management.remote.rmi.RMIConnectorServer)

Example 2 with RMIConnectorServer

use of javax.management.remote.rmi.RMIConnectorServer in project Payara by payara.

the class RMIConnectorStarter method start.

/**
 * The start method which configures the SSLSockets needed and then starts the
 * JMXConnecterServer.
 *
 * @return
 * @throws MalformedURLException
 * @throws IOException
 */
@Override
public JMXConnectorServer start() throws MalformedURLException, IOException, UnknownHostException {
    final String name = "jmxrmi";
    final String hostname = hostname();
    final Map<String, Object> env = new HashMap<>();
    env.put("jmx.remote.jndi.rebind", "true");
    // Provide SSL-based RMI socket factories.
    env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, sslCsf);
    env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, sslServerSocketFactory);
    // For binding the JMXConnectorServer with the Registry
    env.put("com.sun.jndi.rmi.factory.socket", sslCsf);
    JMXAuthenticator authenticator = getAccessController();
    if (authenticator != null) {
        env.put("jmx.remote.authenticator", authenticator);
    }
    // env.put("jmx.remote.protocol.provider.pkgs", "com.sun.jmx.remote.protocol");
    // env.put("jmx.remote.protocol.provider.class.loader", this.getClass().getClassLoader());
    final String jmxHostPort = hostname + ":" + mPort;
    final String registryHostPort = hostname + ":" + mPort;
    // !!!
    // extended JMXServiceURL  uses the same port for both the RMIRegistry and the client port
    // see: http://blogs.sun.com/jmxetc/entry/connecting_through_firewall_using_jmx
    // the first hostPort value is the host/port to be used for the client connections; this makes it a fixed
    // port number and we're making it the same as the RMI registry port.
    // final String urlStr = "service:jmx:rmi:///jndi/rmi://" + hostPort + "/" + name;
    final String urlStr = "service:jmx:rmi://" + jmxHostPort + "/jndi/rmi://" + registryHostPort + "/" + name;
    mJMXServiceURL = new JMXServiceURL(urlStr);
    if (mBindToSingleIP) {
        RMIServerSocketFactory rmiSSF = isSecurityEnabled() ? sslServerSocketFactory : mServerSocketFactory;
        mMyServer = new MyRMIJRMPServerImpl(mPort, env, rmiSSF, hostname);
        mConnectorServer = new RMIConnectorServer(mJMXServiceURL, env, mMyServer, mMBeanServer);
    } else {
        mConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(mJMXServiceURL, env, mMBeanServer);
    }
    if (mBootListener != null) {
        mConnectorServer.addNotificationListener(mBootListener, null, mJMXServiceURL.toString());
    }
    mConnectorServer.start();
    return mConnectorServer;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) RMIConnectorServer(javax.management.remote.rmi.RMIConnectorServer) RMIServerSocketFactory(java.rmi.server.RMIServerSocketFactory) SecureRMIServerSocketFactory(org.glassfish.admin.mbeanserver.ssl.SecureRMIServerSocketFactory) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) JMXAuthenticator(javax.management.remote.JMXAuthenticator)

Example 3 with RMIConnectorServer

use of javax.management.remote.rmi.RMIConnectorServer in project cassandra by apache.

the class CQLTester method tearDownClass.

@AfterClass
public static void tearDownClass() {
    for (Session sess : sessions.values()) sess.close();
    for (Cluster cl : clusters.values()) cl.close();
    if (server != null)
        server.stop();
    // statements are not cached but re-prepared every time). So we clear the cache between test files to avoid accumulating too much.
    if (reusePrepared)
        QueryProcessor.clearInternalStatementsCache();
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    if (jmxServer != null && jmxServer instanceof RMIConnectorServer) {
        try {
            ((RMIConnectorServer) jmxServer).stop();
        } catch (IOException e) {
            logger.warn("Error shutting down jmx", e);
        }
    }
}
Also used : RMIConnectorServer(javax.management.remote.rmi.RMIConnectorServer) IOException(java.io.IOException) TokenMetadata(org.apache.cassandra.locator.TokenMetadata)

Example 4 with RMIConnectorServer

use of javax.management.remote.rmi.RMIConnectorServer in project flink by apache.

the class JMXServer method internalStart.

private void internalStart(int port) throws IOException {
    rmiServerReference.set(null);
    // this allows clients to lookup the JMX service
    rmiRegistry = new JmxRegistry(port, "jmxrmi", rmiServerReference);
    String serviceUrl = "service:jmx:rmi://localhost:" + port + "/jndi/rmi://localhost:" + port + "/jmxrmi";
    JMXServiceURL url;
    try {
        url = new JMXServiceURL(serviceUrl);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Malformed service url created " + serviceUrl, e);
    }
    final RMIJRMPServerImpl rmiServer = new RMIJRMPServerImpl(port, null, null, null);
    connector = new RMIConnectorServer(url, null, rmiServer, ManagementFactory.getPlatformMBeanServer());
    connector.start();
    // we can't pass the created stub directly to the registry since this would form a cyclic
    // dependency:
    // - you can only start the connector after the registry was started
    // - you can only create the stub after the connector was started
    // - you can only start the registry after the stub was created
    rmiServerReference.set(rmiServer.toStub());
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) RMIJRMPServerImpl(javax.management.remote.rmi.RMIJRMPServerImpl) MalformedURLException(java.net.MalformedURLException) RMIConnectorServer(javax.management.remote.rmi.RMIConnectorServer)

Example 5 with RMIConnectorServer

use of javax.management.remote.rmi.RMIConnectorServer in project tomcat by apache.

the class JmxRemoteLifecycleListener method createServer.

private JMXConnectorServer createServer(String serverName, String bindAddress, int theRmiRegistryPort, int theRmiServerPort, HashMap<String, Object> theEnv, RMIClientSocketFactory registryCsf, RMIServerSocketFactory registrySsf, RMIClientSocketFactory serverCsf, RMIServerSocketFactory serverSsf) {
    // Create the RMI registry
    Registry registry;
    try {
        registry = LocateRegistry.createRegistry(theRmiRegistryPort, registryCsf, registrySsf);
    } catch (RemoteException e) {
        log.error(sm.getString("jmxRemoteLifecycleListener.createRegistryFailed", serverName, Integer.toString(theRmiRegistryPort)), e);
        return null;
    }
    if (bindAddress == null) {
        bindAddress = "localhost";
    }
    String url = "service:jmx:rmi://" + bindAddress;
    JMXServiceURL serviceUrl;
    try {
        serviceUrl = new JMXServiceURL(url);
    } catch (MalformedURLException e) {
        log.error(sm.getString("jmxRemoteLifecycleListener.invalidURL", serverName, url), e);
        return null;
    }
    RMIConnectorServer cs = null;
    try {
        RMIJRMPServerImpl server = new RMIJRMPServerImpl(rmiServerPortPlatform, serverCsf, serverSsf, theEnv);
        cs = new RMIConnectorServer(serviceUrl, theEnv, server, ManagementFactory.getPlatformMBeanServer());
        cs.start();
        registry.bind("jmxrmi", server.toStub());
        log.info(sm.getString("jmxRemoteLifecycleListener.start", Integer.toString(theRmiRegistryPort), Integer.toString(theRmiServerPort), serverName));
    } catch (IOException | AlreadyBoundException e) {
        log.error(sm.getString("jmxRemoteLifecycleListener.createServerFailed", serverName), e);
    }
    return cs;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) RMIJRMPServerImpl(javax.management.remote.rmi.RMIJRMPServerImpl) MalformedURLException(java.net.MalformedURLException) RMIConnectorServer(javax.management.remote.rmi.RMIConnectorServer) AlreadyBoundException(java.rmi.AlreadyBoundException) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException)

Aggregations

RMIConnectorServer (javax.management.remote.rmi.RMIConnectorServer)11 JMXServiceURL (javax.management.remote.JMXServiceURL)8 RMIJRMPServerImpl (javax.management.remote.rmi.RMIJRMPServerImpl)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 InetAddress (java.net.InetAddress)3 MalformedURLException (java.net.MalformedURLException)3 AlreadyBoundException (java.rmi.AlreadyBoundException)3 Registry (java.rmi.registry.Registry)3 MBeanServer (javax.management.MBeanServer)3 RemoteException (java.rmi.RemoteException)2 LocateRegistry (java.rmi.registry.LocateRegistry)2 RMIServerSocketFactory (java.rmi.server.RMIServerSocketFactory)2 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ServerNotifForwarder (com.sun.jmx.remote.internal.ServerNotifForwarder)1 WeakReference (java.lang.ref.WeakReference)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 UnknownHostException (java.net.UnknownHostException)1