@BeforeClass public static void setUpClass() throws RemoteException, MalformedURLException, IOException { Registry r = LocateRegistry.createRegistry(9999); mbs = MBeanServerFactory.createMBeanServer(); person = new Test01_JavaIntrospection.Person("Alice Aho", 23); person.knows = new Test01_JavaIntrospection.Person("Bob", 30); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/server"); cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); if (cs == null) { throw new RuntimeException("Could not setUpClass() for test! JMXConnectorServerFactory.newJMXConnectorServer FAILED (Returned null...)! Url: " + url + ", mbs: " + mbs); } cs.start(); System.out.println("Registry created / JMX connector started."); }
/** * Returns MBeans server for the Pogamut Platform. All MBeans connected from * the platform should be registered in this server. There is also default * RMI connector for this server running on service:jmx:rmi:///jndi/rmi://localhost:9999/server * @return * @throws cz.cuni.amis.utils.exception.PogamutException */ @Override public synchronized MBeanServer getMBeanServer() throws PogamutException { try { if (!registryCreated) { if (log.isLoggable(Level.WARNING)) log.warning("Creating registry at " + getRMIPort() + " ..."); LocateRegistry.createRegistry(getRMIPort()); registryCreated = true; } if (mBeanServer == null) { if (log.isLoggable(Level.WARNING)) log.warning("Starting MBean server."); //start a RMI registry mBeanServer = new PogamutMBeanServer(); // also create connector for this server, server without connector // would be unreachable outside this JVM cs = JMXConnectorServerFactory.newJMXConnectorServer(getMBeanServerURL(), null, mBeanServer); cs.start(); } return mBeanServer; } catch (Exception ex) { throw new PogamutException("Error during JMX initialization.", ex); } }
/** * Maak een connector server instantie. * * @return connector server * @throws IOException bij fouten */ private JMXConnectorServer createConnectorServer() throws IOException { final Properties configuration = readConfiguration(); final MBeanServer server = locateMBeanServer(); final JMXServiceURL url = new JMXServiceURL(SimpleJmx.PROTOCOL, configuration.getProperty("jmx.host", DEFAULT_HOST), Integer.parseInt(configuration.getProperty("jmx.port", DEFAULT_PORT))); final Map<String,Object> environment = new HashMap<>(); Properties authentication = new Properties(); authentication.setProperty("admin", "admin"); environment.put("jmx.remote.authenticator", new PropertiesAuthenticator(authentication)); environment.put("jmx.remote.accesscontroller", new AllAccessController()); return JMXConnectorServerFactory.newJMXConnectorServer(url, environment, server); }
private JMXServiceURL createServerSide(Map<String, Object> serverMap) throws Exception { final int NINETY_SECONDS = 90; System.out.println("SecurityTest::createServerSide: Start") ; // Prepare server side security env HashMap<String, Object> env = setServerSecurityEnv(serverMap); // Create and start mbean server and connector server MBeanServer mbs = MBeanServerFactory.newMBeanServer(); JMXServiceURL url = new JMXServiceURL("rmi", null, 0); cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs); cs.start(); // Waits availibility of connector server Utils.waitReady(cs, NINETY_SECONDS); JMXServiceURL addr = cs.getAddress(); System.out.println("SecurityTest::createServerSide: Done.") ; return addr; }
public static void main(String[] args) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); Sender sender = new Sender(); mbs.registerMBean(sender, testObjectName); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); JMXConnector cc = JMXConnectorFactory.connect(addr); try { test(mbs, cs, cc); } finally { cc.close(); cs.stop(); } }
private JMXConnectorServer startServer(int rmiPort) throws Exception { System.out.println("DEBUG: Create RMI registry on port " + rmiPort); LocateRegistry.createRegistry(rmiPort); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); HashMap<String,Object> env = new HashMap<String,Object>(); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:" + rmiPort + "/jmxrmi"); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs); cs.start(); System.out.println("DEBUG: Started the RMI connector server"); return cs; }
private static void dotest(JMXServiceURL url, MBeanServer mbs) throws Exception { JMXConnectorServer server = null; JMXConnector client = null; server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); server.start(); JMXServiceURL outputAddr = server.getAddress(); System.out.println("Server started ["+ outputAddr+ "]"); client = JMXConnectorFactory.newJMXConnector(outputAddr, null); client.connect(); System.out.println("Client connected"); MBeanServerConnection connection = client.getMBeanServerConnection(); System.out.println(connection.getDefaultDomain()); }
public static void main(String[] args) throws Exception { if (Platform.isDebugBuild()) { System.out.println("Running on a debug build. Performance test not applicable. Skipping."); return; } MBeanServer mbs = MBeanServerFactory.newMBeanServer(); Sender sender = new Sender(); mbs.registerMBean(sender, testObjectName); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); JMXConnector cc = JMXConnectorFactory.connect(addr); try { test(mbs, cs, cc); } finally { cc.close(); cs.stop(); } }
private static void createJSR160Server() throws RemoteException, MalformedURLException, IOException { // Create RMI registry needed for JSR-160 connectors LocateRegistry.createRegistry(8998); // Create MBeanServer final MBeanServer server = MBeanServerFactory.createMBeanServer(); // Create the JMXConnectorServer final JMXServiceURL address = new JMXServiceURL("service:jmx:rmi://localhost/jndi/rmi://localhost:8998/jmxconnector"); // The environment map // Map environment = new HashMap(); // environment.put(JMXConnectorServer.AUTHENTICATOR, new // FooAuthenticator()); final JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(address, null, server); // Start the JMXConnectorServer connectorServer.start(); }
public static void main(String[] args) throws Exception { // The MBeanServer MBeanServer server = MBeanServerFactory.createMBeanServer(); // Pass null as the host name to tell JMXServiceURL to default to InetAddress.getLocalHost().getHostName() JMXServiceURL url = new JMXServiceURL("hessian+ssl", null, 8443, "/hessianssl"); // Replace the value of the configuration with the file path of the configuration file Map serverEnv = new HashMap(); serverEnv.put(HTTPConnectorServer.WEB_CONTAINER_CONFIGURATION, "<your-web-container-configuration>"); JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, serverEnv, server); connectorServer.start(); System.out.println("Server up and running " + connectorServer + " on " + url); }
public static void main(String[] args) throws Exception { // The MBeanServer MBeanServer server = MBeanServerFactory.createMBeanServer(); // Register and start the rmiregistry MBean, needed by JSR 160 RMIConnectorServer ObjectName namingName = ObjectName.getInstance("naming:type=rmiregistry"); server.createMBean("mx4j.tools.naming.NamingService", namingName, null); server.invoke(namingName, "start", null, null); int namingPort = ((Integer)server.getAttribute(namingName, "Port")).intValue(); String jndiPath = "/jmxconnector"; JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost/jndi/rmi://localhost:" + namingPort + jndiPath); // Create and start the RMIConnectorServer JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server); connectorServer.start(); System.out.println("Server up and running"); }
public static void main(String[] args) throws Exception { // The address of the connector server JMXServiceURL url = new JMXServiceURL("rmi", "localhost", 0, "/jndi/jmx"); // No need of environment variables or the MBeanServer at this point JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, null); ObjectName cntorServerName = ObjectName.getInstance(":service=" + JMXConnectorServer.class.getName() + ",protocol=" + url.getProtocol()); MBeanServer server = MBeanServerFactory.createMBeanServer("remote.notification.example"); // Register the connector server as MBean server.registerMBean(cntorServer, cntorServerName); // The rmiregistry needed to bind the RMI stub NamingService naming = new NamingService(); ObjectName namingName = ObjectName.getInstance(":service=" + NamingService.class.getName()); server.registerMBean(naming, namingName); naming.start(); // Start the connector server cntorServer.start(); System.out.println("Server up and running"); }
private void registerInstrumentationStats(MBeanServer mbServer, InstrumentationStats stats) { try { String name = args.getValue(Arg.JMX_NAME); int port = Integer.parseInt(args.getValue(Arg.JMX_PORT)); String host = args.getValue(Arg.JMX_HOST); ObjectName statsName = new ObjectName("COJAC:type=InstrumentationMXBean,name=" + name); LocateRegistry.createRegistry(port); StringBuilder sb = new StringBuilder("/jndi/rmi://").append(host).append(":").append(port); sb.append("/").append(name); JMXServiceURL url = new JMXServiceURL("rmi", null, 0, sb.toString()); JMXConnectorServer jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbServer); jmxConnectorServer.start(); if (!mbServer.isRegistered(statsName)) { mbServer.registerMBean(stats, statsName); } } catch (MalformedObjectNameException | NullPointerException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException | IOException e) { e.printStackTrace(); } }
public void startRMIConnector(int jmxPort) { try { LogUtil.getCoreLog().info("RMI port:"+jmxPort); ServerConfigHelper.setProperty("JMX_RMI_PORT", ""+jmxPort); MBeanServer mbs= ManagementFactory.getPlatformMBeanServer(); ObjectName namingName = ObjectName.getInstance("naming:type=rmiregistry"); mbs.registerMBean(new NamingService(jmxPort), namingName); mbs.invoke(namingName, "start", null, null); String jndiPath = "/jmxconnector"; String bindIp = ServerConfigHelper.getProperty(ITEMS.BINDIP.name()); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+bindIp+":" + jmxPort + jndiPath); JMXConnectorServer connector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); ObjectName connectorName = null; connectorName = new ObjectName("Gemlite:name=RMIConnector"); mbs.registerMBean(connector, connectorName); connector.start(); } catch (Exception e) { LogUtil.getCoreLog().error("Error start rmi connector",e); } }
private boolean initConnectorServer() { try { MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName numenName = new ObjectName(NumenMonitor.NUMEN_MONITOR_JMX_BEAN_NAME); mbeanServer.registerMBean(new NumenMonitor(), numenName); //about url referring to http://stackoverflow.com/questions/2768087/explain-jmx-url //protocol:rmi, host:localhot, port:random, url:/jndi/rmi://localhost:1099/jmxrmi LocateRegistry.createRegistry(CommonConstants.WATCHDOG_JMX_RMI_PORT); JMXServiceURL serviceURL = new JMXServiceURL(CommonConstants.WATCHDOG_JMX_RMI_URL); JMXConnectorServer jcs = JMXConnectorServerFactory.newJMXConnectorServer(serviceURL, null, mbeanServer); jcs.start(); return true; } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException | IOException ex) { getLogger(Numen.class.getName()).log(Level.SEVERE, "fail to start Numen Deamon JMX Connector Server due to :\n{0}", ex.getMessage()); return false; } }
public static void main(String[] args) throws Exception { JMXServiceURL inputAddr = new JMXServiceURL("service:jmx:iiop://"); JMXConnectorServer s = JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, null); MBeanServer mbs = MBeanServerFactory.createMBeanServer(); mbs.registerMBean(s, new ObjectName("a:b=c")); s.start(); JMXServiceURL outputAddr = s.getAddress(); if (!outputAddr.getURLPath().startsWith("/ior/IOR:")) { System.out.println("URL path should start with \"/ior/IOR:\": " + outputAddr); System.exit(1); } System.out.println("IIOP URL path looks OK: " + outputAddr); JMXConnector c = JMXConnectorFactory.connect(outputAddr); System.out.println("Successfully got default domain: " + c.getMBeanServerConnection().getDefaultDomain()); c.close(); s.stop(); }