Package javax.management.remote

Examples of javax.management.remote.JMXConnectorServer


      MBeanServer remoteServer1 = newMBeanServer();
      MLet mlet = new MLet(new URL[]{new URL("http", "host", 80, "/path")});
      ObjectName remoteMLetName = ObjectName.getInstance(":type=mlet");
      remoteServer1.registerMBean(mlet, remoteMLetName);
      JMXServiceURL address1 = new JMXServiceURL("rmi", "localhost", 0);
      JMXConnectorServer connectorServer1 = JMXConnectorServerFactory.newJMXConnectorServer(address1, null, null);
      ObjectName connectorServerName1 = ObjectName.getInstance(":type=connector,protocol=" + address1.getProtocol());
      remoteServer1.registerMBean(connectorServer1, connectorServerName1);
      connectorServer1.start();
      address1 = connectorServer1.getAddress();

      // The 2nd remote server
      MBeanServer remoteServer2 = newMBeanServer();
      Timer timer = new Timer();
      ObjectName remoteTimerName = ObjectName.getInstance(":type=timer");
      remoteServer2.registerMBean(timer, remoteTimerName);
      timer.start();
      JMXServiceURL address2 = new JMXServiceURL("rmi", "localhost", 0);
      JMXConnectorServer connectorServer2 = JMXConnectorServerFactory.newJMXConnectorServer(address2, null, remoteServer2);
      connectorServer2.start();
      address2 = connectorServer2.getAddress();

      // The local server
      MBeanServer localServer = newMBeanServer();
      RemoteMBeanProxy proxy1 = new RemoteMBeanProxy(remoteMLetName, address1, null, null);
      JMXConnector cntor = JMXConnectorFactory.connect(address2);
      RemoteMBeanProxy proxy2 = new RemoteMBeanProxy(remoteTimerName, cntor.getMBeanServerConnection());
      ObjectName proxyName1 = ObjectName.getInstance(":proxy=" + ObjectName.quote(remoteMLetName.getCanonicalName()));
      ObjectName proxyName2 = ObjectName.getInstance(":proxy=" + ObjectName.quote(remoteTimerName.getCanonicalName()));
      localServer.registerMBean(proxy1, proxyName1);
      localServer.registerMBean(proxy2, proxyName2);
      JMXServiceURL address3 = new JMXServiceURL("local", "localhost", 0);
      JMXConnectorServer connectorServer3 = JMXConnectorServerFactory.newJMXConnectorServer(address3, null, localServer);
      connectorServer3.start();
      address3 = connectorServer3.getAddress();

      // The client
      JMXConnector connector = JMXConnectorFactory.connect(address3);
      MBeanServerConnection mbsc = connector.getMBeanServerConnection();
View Full Code Here


   {
      // The remote MBeanServer
      MBeanServer remoteServer = newMBeanServer();

      JMXServiceURL address = new JMXServiceURL("rmi", "localhost", 0);
      JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(address, null, null);
      ObjectName connectorServerName = ObjectName.getInstance(":type=connector,protocol=" + address.getProtocol());
      remoteServer.registerMBean(connectorServer, connectorServerName);
      connectorServer.start();
      address = connectorServer.getAddress();

      ObjectName remoteDelegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");

      // The local MBeanServer
      MBeanServer localServer = newMBeanServer();
View Full Code Here

   {
      Map environment = new HashMap();
      environment.put("java.naming.corba.orb", new Object());

      JMXServiceURL url = new JMXServiceURL("iiop", null, 0, "/jndi/iiop://localhost:" + getNamingPort() + "/jmx");
      JMXConnectorServer connectorServer = null;
      try
      {
         startNaming();

         connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, newMBeanServer());
         connectorServer.start();

         JMXConnectorFactory.connect(url, environment);
         fail();
      }
      catch (IllegalArgumentException ignored)
      {
      }
      finally
      {
         if (connectorServer != null) connectorServer.stop();
         stopNaming();
      }
   }
View Full Code Here

      JMXServiceURL url = createJMXConnectorServerAddress();
      Map env = getEnvironment();
      env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, client);
      env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, server);

      JMXConnectorServer cntorServer = null;
      JMXConnector cntor = null;

      try
      {
         cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, env, newMBeanServer());
         cntorServer.start();

         cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
         assertTrue(serverCheck.get());
      }
      finally
      {
         if (cntor != null) cntor.close();
         if (cntorServer != null) cntorServer.stop();
      }
   }
View Full Code Here

      }
   }

   public void testJNDILookupWithRelativePath() throws Exception
   {
      JMXConnectorServer cntorServer = null;
      JMXConnector cntor = null;
      try
      {
         startNaming();

         JMXServiceURL url = createJMXConnectorServerAddress();
         url = new JMXServiceURL(url.getProtocol(), url.getHost(), url.getPort(), "/jndi/jmx");
         cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), newMBeanServer());
         cntorServer.start();

         cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
         MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
         mbsc.getDefaultDomain();
      }
      finally
      {
         if (cntor != null) cntor.close();
         if (cntorServer != null) cntorServer.stop();
         stopNaming();
      }
   }
View Full Code Here

      }
   }

   public void testJNDILookupWithAbsolutePath() throws Exception
   {
      JMXConnectorServer cntorServer = null;
      JMXConnector cntor = null;
      try
      {
         startNaming();

         JMXServiceURL url = createJMXConnectorServerAddress();
         url = new JMXServiceURL(url.getProtocol(), url.getHost(), url.getPort(), "/jndi/" + url.getProtocol() + "://localhost:" + getNamingPort() + "/jmx");
         cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), newMBeanServer());
         cntorServer.start();

         cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
         MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
         mbsc.getDefaultDomain();
      }
      finally
      {
         if (cntor != null) cntor.close();
         if (cntorServer != null) cntorServer.stop();
         stopNaming();
      }
   }
View Full Code Here

   public void testMX4JOnServerJMXRIOnClientGetMBeanInfo() throws Exception
   {
      MBeanServer server = newMBeanServer();
      JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost");
      JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
      cntorServer.start();
      url = cntorServer.getAddress();

      ClassLoader ri = createRemoteJMXRIWithTestsClassLoader();
      ClassLoader tccl = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(ri);
      Object cntor = connectJMXRIConnector(ri, url.toString());

      Method method = cntor.getClass().getMethod("getMBeanServerConnection", new Class[0]);
      Object cntion = method.invoke(cntor, new Object[0]);
      Class cntionClass = ri.loadClass(MBeanServerConnection.class.getName());

      Class objectNameClass = ri.loadClass(ObjectName.class.getName());
      method = objectNameClass.getMethod("getInstance", new Class[]{String.class});
      Object objectName = method.invoke(null, new Object[]{"JMImplementation:type=MBeanServerDelegate"});
      method = cntionClass.getMethod("getMBeanInfo", new Class[]{objectNameClass});
      Object info = method.invoke(cntion, new Object[]{objectName});
      assertNotNull(info);

      method = cntor.getClass().getMethod("close", new Class[0]);
      method.invoke(cntor, new Object[0]);

      Thread.currentThread().setContextClassLoader(tccl);
      cntorServer.stop();
      sleep(2000);
   }
View Full Code Here

   public void testMX4JOnServerJMXRIOnClientNotificationReceiving() throws Exception
   {
      MBeanServer server = newMBeanServer();
      JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost");
      JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
      cntorServer.start();
      url = cntorServer.getAddress();

      ClassLoader ri = createRemoteJMXRIWithTestsClassLoader();
      ClassLoader tccl = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(ri);
      Object cntor = connectJMXRIConnector(ri, url.toString());

      Method method = cntor.getClass().getMethod("getMBeanServerConnection", new Class[0]);
      Object cntion = method.invoke(cntor, new Object[0]);
      Class cntionClass = ri.loadClass(MBeanServerConnection.class.getName());

      Class objectNameClass = ri.loadClass(ObjectName.class.getName());
      method = objectNameClass.getMethod("getInstance", new Class[]{String.class});
      Object delegateName = method.invoke(null, new Object[]{"JMImplementation:type=MBeanServerDelegate"});
      Class notificationListenerClass = ri.loadClass(NotificationListener.class.getName());
      Class notificationFilterClass = ri.loadClass(NotificationFilter.class.getName());
      Object listener = ri.loadClass(InteroperabilityListener.class.getName()).newInstance();
      method = cntionClass.getMethod("addNotificationListener", new Class[]{objectNameClass, notificationListenerClass, notificationFilterClass, Object.class});
      method.invoke(cntion, new Object[]{delegateName, listener, null, null});
      sleep(1000);

      method = objectNameClass.getMethod("getInstance", new Class[]{String.class});
      Object mletName = method.invoke(null, new Object[]{":mbean=mlet"});

      method = cntionClass.getMethod("createMBean", new Class[]{String.class, objectNameClass, objectNameClass});
      method.invoke(cntion, new Object[]{MLet.class.getName(), mletName, null});
      sleep(1000);

      method = listener.getClass().getMethod("get", new Class[0]);
      Object notification = method.invoke(listener, new Object[0]);
      assertNotNull(notification);

      method = listener.getClass().getMethod("reset", new Class[0]);
      method.invoke(listener, new Object[0]);

      method = cntionClass.getMethod("removeNotificationListener", new Class[]{objectNameClass, notificationListenerClass});
      method.invoke(cntion, new Object[]{delegateName, listener});

      method = cntionClass.getMethod("unregisterMBean", new Class[]{objectNameClass});
      method.invoke(cntion, new Object[]{mletName});
      sleep(1000);

      method = listener.getClass().getMethod("get", new Class[0]);
      notification = method.invoke(listener, new Object[0]);
      assertNull(notification);

      method = cntor.getClass().getMethod("close", new Class[0]);
      method.invoke(cntor, new Object[0]);

      Thread.currentThread().setContextClassLoader(tccl);
      cntorServer.stop();
      sleep(2000);
   }
View Full Code Here

         JMXServiceURL url = new JMXServiceURL("soap", null, 8080, "/external");
         jetty.start(url, null);
         jetty.deploy(AxisServlet.class.getName(), url, null);

         // A SOAPConnector
         JMXConnectorServer cntorServer = null;
         JMXConnector cntor = null;
         try
         {
            Map environment = new HashMap();
            environment.put(HTTPConnectorServer.USE_EXTERNAL_WEB_CONTAINER, Boolean.TRUE);
            cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, environment, newMBeanServer());
            cntorServer.start();

            // Check that it works
            cntor = JMXConnectorFactory.connect(cntorServer.getAddress());
            MBeanServerConnection cntion = cntor.getMBeanServerConnection();
            Set names = cntion.queryNames(null, null);
            assertNotNull(names);
            assertFalse(names.isEmpty());
         }
         finally
         {
            if (cntor != null) cntor.close();
            if (cntorServer != null) cntorServer.stop();
         }
      }
      finally
      {
         jetty.stop();
View Full Code Here

   {
      // Format is:
      // protocol:[[host]:port] [clientId] [arbitrary]
      // Spaces are mandatory, brackets indicates optional parts

      JMXConnectorServer cntorServer = null;
      JMXConnector cntor = null;
      try
      {
         JMXServiceURL url = createJMXConnectorServerAddress();
         cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, getEnvironment(), newMBeanServer());
         cntorServer.start();
         sleep(5000);

         cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), getEnvironment());
         String connectionId = cntor.getConnectionId();
         String protocol = connectionId.substring(0, connectionId.indexOf(':'));
         assertEquals(protocol, url.getProtocol());

         // Match first mandatory space
         int space = connectionId.indexOf(' ');
         String remaining = connectionId.substring(space + 1);
         // Match second mandatory space
         space = remaining.indexOf(' ');
         String arbitrary = remaining.substring(space + 1);
         if (arbitrary.length() < 1) fail("Missing MX4J arbitrary test");
      }
      finally
      {
         if (cntor != null) cntor.close();
         if (cntorServer != null) cntorServer.stop();
      }
   }
View Full Code Here

TOP

Related Classes of javax.management.remote.JMXConnectorServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.