List of usage examples for javax.management.remote JMXConnectorServerFactory newJMXConnectorServer
public static JMXConnectorServer newJMXConnectorServer(JMXServiceURL serviceURL, Map<String, ?> environment, MBeanServer mbeanServer) throws IOException
Creates a connector server at the given address.
From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.MMXConfigurationTest.java
@Before public void setup() throws Exception { MMXManagedConfiguration mmxConfigMBean = new MMXManagedConfiguration(MMXConfiguration.getConfiguration()); ObjectName name = new ObjectName(MMX_MBEAN_OBJECT_NAME); server.registerMBean(mmxConfigMBean, name); url = new JMXServiceURL(JMX_SERVICE_URI); JiveGlobalsMock.setup();/*from w w w . j a va 2 s .co m*/ jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server); jmxConnectorServer.start(); new MockUp<JiveGlobals>() { @Mock public boolean isPropertyEncrypted(String name) { return false; } }; }
From source file:org.jcommon.com.util.jmx.RmiAdptor.java
public void setCserver(MBeanServer server) throws MalformedURLException, IOException { if (port == 0 || name == null || addr == null) { throw new NullPointerException("data not be ready"); }//from w w w. j a va 2 s . c o m try { registry = LocateRegistry.createRegistry(port); } catch (RemoteException e) { } HashMap<String, Object> prop = new HashMap<String, Object>(); if (CREDENTIALS != null) { authenticator = new JMXAuthenticator() { public Subject authenticate(Object credentials) { logger.info(credentials.getClass().getName() + " is trying connect..."); if (credentials instanceof String) { if (credentials.equals(CREDENTIALS)) { return new Subject(); } } else if (credentials instanceof String[]) { String[] copy = (String[]) credentials; String username = copy.length > 0 ? copy[0] : null; String passwd = copy.length > 1 ? copy[1] : null; logger.info(username + " is trying connect..."); if (passwd.equals(CREDENTIALS) && username.equals(user)) { return new Subject(); } } throw new SecurityException("not authicated"); } }; prop.put(JMXConnectorServer.AUTHENTICATOR, authenticator); } String url = "service:jmx:rmi:///jndi/rmi://" + addr + ":" + port + "/" + name; this.cserver = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL(url), prop, server); }
From source file:org.mule.module.management.agent.AbstractJmxAgent.java
public void start() throws MuleException { try {/* w w w . ja va2s . co m*/ // TODO cleanup rmi registry creation too initRMI(); if (connectorServerUrl == null) { return; } logger.info("Creating and starting JMX agent connector Server"); JMXServiceURL url = new JMXServiceURL(connectorServerUrl); if (connectorServerProperties == null) { connectorServerProperties = new HashMap<String, Object>(DEFAULT_CONNECTOR_SERVER_PROPERTIES); } if (!credentials.isEmpty()) { connectorServerProperties.put(JMXConnectorServer.AUTHENTICATOR, this.getJmxAuthenticator()); } connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, connectorServerProperties, mBeanServer); connectorServer.start(); } catch (ExportException e) { throw new JmxManagementException(CoreMessages.failedToStart("Jmx Agent"), e); } catch (Exception e) { throw new JmxManagementException(CoreMessages.failedToStart("Jmx Agent"), e); } }
From source file:net.sf.ehcache.management.ManagementServiceTest.java
/** * Creates an RMI JMXConnectorServer, connects to it and demonstrates what attributes are traversable. * The answer is not all.//from w w w. j a va2 s . co m * * Note that this test creates a Registry which will keep running until the JVM Exists. There * is no way to stop it but it should do no harm. * * */ public void testJMXConnectorServer() throws Exception { ManagementService.registerMBeans(manager, mBeanServer, true, true, true, true); LocateRegistry.createRegistry(55000); String serverUrl = "service:jmx:rmi:///jndi/rmi://localhost:55000/server"; JMXServiceURL url = new JMXServiceURL(serverUrl); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mBeanServer); cs.start(); JMXConnector connector = cs.toJMXConnector(null); connector.connect(null); MBeanServerConnection connection = connector.getMBeanServerConnection(); assertEquals(OBJECTS_IN_TEST_EHCACHE, connection.queryNames(new ObjectName("net.sf.ehcache:*"), null).size()); Ehcache ehcache = manager.getCache("sampleCache1"); ehcache.put(new Element("key1", "value1")); ehcache.put(new Element("key2", "value1")); assertNotNull(ehcache.get("key1")); assertNotNull(ehcache.get("key2")); //Test CacheManager //not all attributes are accessible due to serializability constraints //traverseMBeanAttributes(connection, "CacheManager"); //Test Cache //not all attributes are accessible due to serializability constraints //traverseMBeanAttributes(connection, "Cache"); //Test CacheStatistics traverseMBeanAttributes(connection, "CacheStatistics"); //Test CacheConfiguration traverseMBeanAttributes(connection, "CacheConfiguration"); cs.stop(); }
From source file:com.continuent.tungsten.common.jmx.JmxManager.java
/** * Starts the JMX connector for the server. *//* ww w .j a va2 s . c om*/ 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:org.red5.server.jmx.JMXAgent.java
public void init() { //environmental var holder HashMap env = null;// ww w . ja v a2 s. c om if (enableHtmlAdapter) { // setup the adapter try { //instance an html adaptor int port = htmlAdapterPort == null ? 8082 : Integer.valueOf(htmlAdapterPort); html = new HtmlAdaptorServer(port); ObjectName htmlName = new ObjectName( JMXFactory.getDefaultDomain() + ":type=HtmlAdaptorServer,port=" + port); log.debug("Created HTML adaptor on port: " + port); //add the adaptor to the server mbs.registerMBean(html, htmlName); //start the adaptor html.start(); log.info("JMX HTML connector server successfully started"); } catch (Exception e) { log.error("Error in setup of JMX subsystem (HTML adapter)", e); } } else { log.info("JMX HTML adapter was not enabled"); } if (enableRmiAdapter) { // Create an RMI connector server log.debug("Create an RMI connector server"); try { Registry r = null; try { //lookup the registry r = LocateRegistry.getRegistry(Integer.valueOf(rmiAdapterPort)); //ensure we are not already registered with the registry for (String regName : r.list()) { if (regName.equals("red5")) { //unbind connector from rmi registry r.unbind("red5"); } } } catch (RemoteException re) { log.info("RMI Registry server was not found on port " + rmiAdapterPort); //if we didnt find the registry and the user wants it created if (startRegistry) { log.info("Starting an internal RMI registry"); // create registry for rmi port 9999 r = LocateRegistry.createRegistry(Integer.valueOf(rmiAdapterPort)); } } JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + rmiAdapterPort + "/red5"); //if SSL is requested to secure rmi connections if (enableSsl) { // Environment map log.debug("Initialize the environment map"); env = new HashMap(); // Provide SSL-based RMI socket factories SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory(); SslRMIServerSocketFactory ssf = new SslRMIServerSocketFactory(); env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf); env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf); } //if authentication is requested if (StringUtils.isNotBlank(remoteAccessProperties)) { //if ssl is not used this will be null if (null == env) { env = new HashMap(); } //check the existance of the files //in the war version the full path is needed File file = new File(remoteAccessProperties); if (!file.exists()) { log.debug("Access file was not found on path, will prepend config_root"); //pre-pend the system property set in war startup remoteAccessProperties = System.getProperty("red5.config_root") + '/' + remoteAccessProperties; remotePasswordProperties = System.getProperty("red5.config_root") + '/' + remotePasswordProperties; } env.put("jmx.remote.x.access.file", remoteAccessProperties); env.put("jmx.remote.x.password.file", remotePasswordProperties); } // create the connector server cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs); // add a listener for shutdown cs.addNotificationListener(this, null, null); // Start the RMI connector server log.debug("Start the RMI connector server"); cs.start(); log.info("JMX RMI connector server successfully started"); } catch (ConnectException e) { log.warn("Could not establish RMI connection to port " + rmiAdapterPort + ", please make sure \"rmiregistry\" is running and configured to listen on this port."); } catch (IOException e) { String errMsg = e.getMessage(); if (errMsg.indexOf("NameAlreadyBoundException") != -1) { log.error("JMX connector (red5) already registered, you will need to restart your rmiregistry"); } else { log.error("{}", e); } } catch (Exception e) { log.error("Error in setup of JMX subsystem (RMI connector)", e); } } else { log.info("JMX RMI adapter was not enabled"); } }
From source file:org.apache.camel.management.DefaultManagementAgent.java
protected void createJmxConnector(String host) throws IOException { ObjectHelper.notEmpty(serviceUrlPath, "serviceUrlPath"); ObjectHelper.notNull(registryPort, "registryPort"); try {/*from w ww. j av a 2 s . c o m*/ LocateRegistry.createRegistry(registryPort); if (LOG.isDebugEnabled()) { LOG.debug("Created JMXConnector RMI registry on port " + registryPort); } } catch (RemoteException ex) { // The registry may had been created, we could get the registry instead } // must start with leading slash String path = serviceUrlPath.startsWith("/") ? serviceUrlPath : "/" + serviceUrlPath; // Create an RMI connector and start it final JMXServiceURL url; if (connectorPort > 0) { url = new JMXServiceURL("service:jmx:rmi://" + host + ":" + connectorPort + "/jndi/rmi://" + host + ":" + registryPort + path); } else { url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + registryPort + path); } cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server); if (executorService == null) { // we only need a single for the JMX connector executorService = camelContext.getExecutorServiceStrategy().newSingleThreadExecutor(this, "JMXConnector: " + url); } // execute the JMX connector executorService.execute(new Runnable() { public void run() { try { cs.start(); } catch (IOException ioe) { LOG.warn("Could not start JMXConnector thread.", ioe); } } }); LOG.info("JMX Connector thread started and listening at: " + url); }
From source file:com.cisco.oss.foundation.monitoring.RMIMonitoringAgent.java
private String javaRegister(MonitoringMXBean mxBean, String serviceURL) throws MalformedObjectNameException, IOException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException { serverInfo = new ServerInfo(mxBean, configuration); String strAppObjectName = Utility.getObjectName("Application", this.exposedObject); jurl = new JMXServiceURL(serviceURL); appObjectName = new ObjectName(strAppObjectName); jmxEnvironmentMap = null;/* ww w . j a v a 2 s .c o m*/ int agentPort = configuration.getInt(FoundationMonitoringConstants.MX_PORT); if (!RMIRegistryManager.isRMIRegistryRunning(configuration, agentPort)) { RMIRegistryManager.startRMIRegistry(configuration, agentPort); } else { LOGGER.info("rmiregistry is already running on port " + agentPort); } String serviceName = serviceURL.substring(serviceURL.indexOf("jmxrmi/")); if (isServiceExported(configuration, serviceName)) { MonitoringClient client = new MonitoringClient(serviceURL, strAppObjectName); if (client.connect()) { client.disconnect(); } else { jmxEnvironmentMap = Utility.prepareJmxEnvironmentMap(); LOGGER.info("Found a stale entry for " + serviceName + " in rmiregistry , it will be overwritten"); } } mbs = ManagementFactory.getPlatformMBeanServer(); rmis = JMXConnectorServerFactory.newJMXConnectorServer(jurl, jmxEnvironmentMap, mbs); mbs.registerMBean(mxBean, appObjectName); registerComponentInfo(); registerMonitoringConfiguration(); registerServices(); registerConnections(); registerNotificationDetails(); rmis.start(); if (mxBean instanceof INotifier) { INotifier notifier = (INotifier) mxBean; notifier.setNotificationSender(serverInfo); } serverThread = new ServerRecoveryDaemon(); serverThread.start(); return strAppObjectName; }
From source file:com.linkedin.databus2.core.container.netty.ServerContainer.java
protected void initializeContainerJmx() { if (_containerStaticConfig.getJmx().isRmiEnabled()) { try {/*from w ww . j a va 2 s. co m*/ JMXServiceURL jmxServiceUrl = new JMXServiceURL( "service:jmx:rmi://" + _containerStaticConfig.getJmx().getJmxServiceHost() + ":" + _containerStaticConfig.getJmx().getJmxServicePort() + "/jndi/rmi://" + _containerStaticConfig.getJmx().getRmiRegistryHost() + ":" + _containerStaticConfig.getJmx().getRmiRegistryPort() + "/jmxrmi" + _containerStaticConfig.getJmx().getJmxServicePort()); _jmxConnServer = JMXConnectorServerFactory.newJMXConnectorServer(jmxServiceUrl, null, getMbeanServer()); } catch (Exception e) { LOG.warn("Unable to instantiate JMX server", e); } } }
From source file:com.webobjects.monitor.wotaskd.Application.java
/** * ============================================================================================ * Methods Added for Enabling JMX in Wotaskd * ============================================================================================ * This methods sets up this application for remote monitoring. This method creates a new * connector server and associates it with the MBean Server. The server is started by calling * the start() method. The connector server listens for the client connection requests and * creates a connection for each one.//from w w w .j a v a 2 s . co m */ public void setupRemoteMonitoring() { if (_jmxPort != null) { // Create an RMI connector and start it try { // Get the port difference to use when creating our new jmx listener int intWotaskdJmxPort = Integer.parseInt(_jmxPort); // Set up the Password and Access file HashMap<String, String> envPwd = new HashMap<String, String>(); envPwd.put("jmx.remote.x.password.file", _jmxPasswordFile); envPwd.put("jmx.remote.x.access.file", _jmxAccessFile); // setup our listener java.rmi.registry.LocateRegistry.createRegistry(intWotaskdJmxPort); JMXServiceURL jsUrl = new JMXServiceURL( "service:jmx:rmi:///jndi/rmi://" + host() + ":" + intWotaskdJmxPort + "/jmxrmi"); NSLog.debug.appendln("Setting up monitoring on url : " + jsUrl); // Create an RMI Connector Server JMXConnectorServer jmxCS = JMXConnectorServerFactory.newJMXConnectorServer(jsUrl, envPwd, getMBeanServer()); jmxCS.start(); } catch (Exception anException) { NSLog.err.appendln("Error starting remote monitoring: " + anException); } } }