Example usage for javax.management.remote.rmi RMIConnectorServer JNDI_REBIND_ATTRIBUTE

List of usage examples for javax.management.remote.rmi RMIConnectorServer JNDI_REBIND_ATTRIBUTE

Introduction

In this page you can find the example usage for javax.management.remote.rmi RMIConnectorServer JNDI_REBIND_ATTRIBUTE.

Prototype

String JNDI_REBIND_ATTRIBUTE

To view the source code for javax.management.remote.rmi RMIConnectorServer JNDI_REBIND_ATTRIBUTE.

Click Source Link

Document

Name of the attribute that specifies whether the RMIServer stub that represents an RMI connector server should override an existing stub at the same address.

Usage

From source file:com.cisco.oss.foundation.monitoring.Utility.java

static Map<String, String> prepareJmxEnvironmentMap() {
    Map<String, String> env = new HashMap<String, String>();
    env.put(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE, Boolean.TRUE.toString());
    return env;//from   w  ww  . ja  v  a 2 s .c  o m
}

From source file:com.continuent.tungsten.common.jmx.JmxManager.java

/**
 * Starts the JMX connector for the server.
 *///  w  w  w  .j ava  2 s.  co  m
protected void startJmxConnector() {
    String serviceAddress = null;
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

        serviceAddress = generateServiceAddress(host, beanPort, registryPort, serviceName);
        JMXServiceURL address = new JMXServiceURL(serviceAddress);

        // --- Define security attributes ---
        HashMap<String, Object> env = new HashMap<String, Object>();

        // --- Authentication based on password and access files---
        if (authenticationInfo != null && authenticationInfo.isAuthenticationNeeded()) {

            if (authenticationInfo.isUseTungstenAuthenticationRealm())
                env.put(JMXConnectorServer.AUTHENTICATOR, new RealmJMXAuthenticator(authenticationInfo));
            else
                env.put("jmx.remote.x.password.file", authenticationInfo.getPasswordFileLocation());

            env.put("jmx.remote.x.access.file", authenticationInfo.getAccessFileLocation());
        }

        // --- SSL encryption ---
        if (authenticationInfo != null && authenticationInfo.isEncryptionNeeded()) {
            // Keystore
            System.setProperty("javax.net.ssl.keyStore", authenticationInfo.getKeystoreLocation());
            System.setProperty("javax.net.ssl.keyStorePassword", authenticationInfo.getKeystorePassword());
            /**
             * Configure SSL. Protocols and ciphers are set in
             * securityHelper.setSecurityProperties and used by
             * SslRMIClientSocketFactory
             */
            try {
                String[] protocolArray = authenticationInfo.getEnabledProtocols().toArray(new String[0]);
                String[] allowedCipherSuites = authenticationInfo.getEnabledCipherSuites()
                        .toArray(new String[0]);
                String[] cipherArray;

                if (protocolArray.length == 0)
                    protocolArray = null;
                if (allowedCipherSuites.length == 0)
                    cipherArray = null;
                else {
                    // Ensure we choose an allowed cipher suite.
                    cipherArray = authenticationInfo.getJvmEnabledCipherSuites().toArray(new String[0]);
                    if (cipherArray.length == 0) {
                        // We don't have any cipher suites in common. This
                        // is not good!
                        String message = "Unable to find approved ciphers in the supported cipher suites on this JVM";
                        StringBuffer sb = new StringBuffer(message).append("\n");
                        sb.append(String.format("JVM supported cipher suites: %s\n",
                                StringUtils.join(SecurityHelper.getJvmSupportedCiphers())));
                        sb.append(String.format("Approved cipher suites from security.properties: %s\n",
                                StringUtils.join(allowedCipherSuites)));
                        logger.error(sb.toString());
                        throw new RuntimeException(message);
                    }
                }

                logger.info("Setting allowed JMX server protocols: " + StringUtils.join(protocolArray, ","));
                logger.info("Setting allowed JMX server ciphers: " + StringUtils.join(cipherArray, ","));
                SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory();
                SslRMIServerSocketFactory ssf = new SslRMIServerSocketFactory(cipherArray, protocolArray,
                        false);
                env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
                env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);
            } catch (IllegalArgumentException ie) {
                logger.warn("Some of the protocols or ciphers are not supported. " + ie.getMessage());
                throw new RuntimeException(ie.getLocalizedMessage(), ie);
            }
        }

        env.put(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE, "true");
        JMXConnectorServer connector = JMXConnectorServerFactory.newJMXConnectorServer(address, env, mbs);
        connector.start();

        logger.info(MessageFormat.format("JMXConnector: security.properties={0}",
                (authenticationInfo != null) ? authenticationInfo.getParentPropertiesFileLocation()
                        : "No security.properties file found !..."));
        if (authenticationInfo != null)
            logger.info(authenticationInfo.toString());
        logger.info(String.format("JMXConnector started at address %s", serviceAddress));

        jmxConnectorServer = connector;
    } catch (Throwable e) {
        throw new ServerRuntimeException(
                MessageFormat.format("Unable to create RMI listener: {0} -> {1}", getServiceProps(), e), e);
    }
}

From source file:net.timewalker.ffmq4.jmx.rmi.JMXOverRMIAgent.java

private void init() throws JMSException {
    try {/*from w  w  w .  j a  va2 s  . c om*/
        log.info("Starting JMX agent");

        // Get or create an RMI registry
        if (rmiListenAddr == null || rmiListenAddr.equals("auto"))
            rmiListenAddr = InetAddress.getLocalHost().getHostName();

        // Connector JNDI name
        String jndiName = "jmxconnector-" + agentName;

        try {
            registry = LocateRegistry.getRegistry(rmiListenAddr, jndiRmiPort);
            registry.lookup(jndiName);

            // Remove the old registered connector
            registry.unbind(jndiName);

            log.debug("RMI registry found at " + rmiListenAddr + ":" + jndiRmiPort
                    + " with connector already registered");
        } catch (NotBoundException e) {
            // Registry already exists
            log.debug("RMI registry found at " + rmiListenAddr + ":" + jndiRmiPort);
        } catch (RemoteException e) {
            log.debug("Creating RMI registry at " + rmiListenAddr + ":" + jndiRmiPort);
            RMIServerSocketFactory ssf = new JMXOverRMIServerSocketFactory(10, rmiListenAddr, false);
            registry = LocateRegistry.createRegistry(jndiRmiPort, null, ssf);
        }

        // Get the JVM MBean server
        mBeanServer = ManagementFactory.getPlatformMBeanServer();

        // Service URL
        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + rmiListenAddr + "/jndi/rmi://"
                + rmiListenAddr + ":" + jndiRmiPort + "/" + jndiName);
        log.info("JMX Service URL : " + url);

        // Create and start the RMIConnectorServer
        Map<String, Object> env = new HashMap<>();
        mBeanServerSocketFactory = new JMXOverRMIServerSocketFactory(10, rmiListenAddr, true);
        env.put(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE, "true");
        //env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, new JMXRMIClientSocketFactory(rmiListenAddr));
        env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, mBeanServerSocketFactory);
        connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mBeanServer);
        connectorServer.start();
    } catch (Exception e) {
        throw new FFMQException("Could not initialize JMX agent", "JMX_ERROR", e);
    }
}