javax.management.loading.MLet Java Examples

The following examples show how to use javax.management.loading.MLet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReflectionUtilTest.java    From common-utils with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void getAllMethodsOfClass() {
    assertNull(ReflectionUtil.getAllMethodsOfClass(null));

    Method[] methods = ReflectionUtil.getAllMethodsOfClass(MLet.class);
    assertTrue(methods.length > 0);

    Method equalsMethod = ReflectionUtil.getMethod(Object.class, "equals", Object.class);

    assertTrue(methods.length > 0);
    List<Method> methodList = Arrays.asList(methods);

    assertFalse(methodList.contains(equalsMethod));

    List<Class<?>> list = ClassUtil.getAllInterfaces(MLet.class);

    int interMethodLength = 0;
    for (Class<?> clazz : list) {
        Method[] interMethods = ReflectionUtil.getAllMethodsOfClass(clazz);
        interMethodLength += interMethods.length;
    }

    assertTrue(methods.length > interMethodLength);
}
 
Example #2
Source File: PostExceptionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #3
Source File: PostExceptionTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #4
Source File: PostExceptionTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #5
Source File: PostExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #6
Source File: PostExceptionTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #7
Source File: JDKUtil.java    From marshalsec with MIT License 5 votes vote down vote up
public static URLClassLoader makeMLet ( String url ) throws MalformedURLException, Exception {
    URLClassLoader ucl = new MLet(new URL[] {
        new URL(url)
    });
    Reflections.setFieldValue(ucl, "parent", null);
    Reflections.setFieldValue(ucl, "domains", new HashSet<>());
    Reflections.setFieldValue(ucl, "defaultDomain", null);
    Reflections.setFieldValue(ucl, "acc", null);

    Reflections.setFieldValue(Reflections.getFieldValue(ucl, "ucp"), "acc", null);
    return ucl;
}
 
Example #8
Source File: PostExceptionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #9
Source File: MLetInternalsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@BeforeClass
public static void setupClass() {
    testedMethods.clear();
    try {
        Method m = MLet.class.getDeclaredMethod(
                CONSTRUCT_PARAMETER,
                String.class, String.class
        );
        m.setAccessible(true);

        testedMethods.put(CONSTRUCT_PARAMETER, m);
    } catch (Exception ex) {
        throw new Error(ex);
    }
}
 
Example #10
Source File: PostExceptionTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #11
Source File: Client.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void main(String[] args) throws Exception
{
   // The address of the connector server
   JMXServiceURL url = new JMXServiceURL("rmi", "localhost", 0, "/jndi/jmx");

   // Create and connect the connector client
   JMXConnector cntor = JMXConnectorFactory.connect(url, null);

   // The connection represent, on client-side, the remote MBeanServer
   MBeanServerConnection connection = cntor.getMBeanServerConnection();

   // The listener that will receive notifications from a remote MBean
   NotificationListener listener = new NotificationListener()
   {
      public void handleNotification(Notification notification, Object handback)
      {
         System.out.println(notification);
      }
   };

   // The MBeanServerDelegate emits notifications about registration/unregistration of MBeans
   ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");

   connection.addNotificationListener(delegateName, listener, null, null);

   // Give chance to the notification machinery to setup
   Thread.sleep(1000);

   // Now register a remote MBean, for example an MLet, so that the MBeanServerDelegate
   // will emit notifications for its registration
   ObjectName name = ObjectName.getInstance("examples:mbean=mlet");
   // First notification
   connection.createMBean(MLet.class.getName(), name, null);
   // Second notification
   connection.unregisterMBean(name);
}
 
Example #12
Source File: PostExceptionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #13
Source File: PostExceptionTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #14
Source File: PostExceptionTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #15
Source File: JDKUtil.java    From learnjavabug with MIT License 5 votes vote down vote up
public static URLClassLoader makeMLet ( String url ) throws MalformedURLException, Exception {
    URLClassLoader ucl = new MLet(new URL[] {
        new URL(url)
    });
    Reflections.setFieldValue(ucl, "parent", null);
    Reflections.setFieldValue(ucl, "domains", new HashSet<>());
    Reflections.setFieldValue(ucl, "defaultDomain", null);
    Reflections.setFieldValue(ucl, "acc", null);

    Reflections.setFieldValue(Reflections.getFieldValue(ucl, "ucp"), "acc", null);
    return ucl;
}
 
Example #16
Source File: PostExceptionTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #17
Source File: PostExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #18
Source File: PostExceptionTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public ObjectName registerMLet(MBeanServer server) throws Exception {
    final ObjectName name = new ObjectName("test:type=MLet");
    if (server.isRegistered(name)) {
        return name;
    }
    final MLet mlet = new MLet(new URL[0],
            ClassLoader.getSystemClassLoader());
    return server.registerMBean(mlet, name).getObjectName();
}
 
Example #19
Source File: GetMBeansFromURLTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        boolean error = false;

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Instantiate an MLet
        //
        System.out.println("Create the MLet");
        MLet mlet = new MLet();

        // Register the MLet MBean with the MBeanServer
        //
        System.out.println("Register the MLet MBean");
        ObjectName mletObjectName = new ObjectName("Test:type=MLet");
        mbs.registerMBean(mlet, mletObjectName);

        // Call getMBeansFromURL
        //
        System.out.println("Call mlet.getMBeansFromURL(<url>)");
        try {
            mlet.getMBeansFromURL("bogus://whatever");
            System.out.println("TEST FAILED: Expected " +
                               ServiceNotFoundException.class +
                               " exception not thrown.");
            error = true;
        } catch (ServiceNotFoundException e) {
            if (e.getCause() == null) {
                System.out.println("TEST FAILED: Got null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = true;
            } else {
                System.out.println("TEST PASSED: Got non-null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = false;
            }
            e.printStackTrace(System.out);
        }

        // Unregister the MLet MBean
        //
        System.out.println("Unregister the MLet MBean");
        mbs.unregisterMBean(mletObjectName);

        // Release MBean server
        //
        System.out.println("Release the MBean server");
        MBeanServerFactory.releaseMBeanServer(mbs);

        // End Test
        //
        System.out.println("Bye! Bye!");
        if (error) System.exit(1);
    }
 
Example #20
Source File: ParserInfiniteLoopTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        boolean error = false;

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Instantiate an MLet
        //
        System.out.println("Create the MLet");
        MLet mlet = new MLet();

        // Register the MLet MBean with the MBeanServer
        //
        System.out.println("Register the MLet MBean");
        ObjectName mletObjectName = new ObjectName("Test:type=MLet");
        mbs.registerMBean(mlet, mletObjectName);

        // Call getMBeansFromURL
        //
        System.out.println("Call mlet.getMBeansFromURL(<url>)");
        String testSrc = System.getProperty("test.src");
        System.out.println("test.src = " + testSrc);
        String urlCodebase;
        if (testSrc.startsWith("/")) {
            urlCodebase =
                "file:" + testSrc.replace(File.separatorChar, '/') + "/";
        } else {
            urlCodebase =
                "file:/" + testSrc.replace(File.separatorChar, '/') + "/";
        }
        String mletFile = urlCodebase + args[0];
        System.out.println("MLet File = " + mletFile);
        try {
            mlet.getMBeansFromURL(mletFile);
            System.out.println(
                "TEST FAILED: Expected ServiceNotFoundException not thrown");
            error = true;
        } catch (ServiceNotFoundException e) {
            if (e.getCause() == null) {
                System.out.println("TEST FAILED: Got unexpected null cause " +
                    "in ServiceNotFoundException");
                error = true;
            } else if (!(e.getCause() instanceof IOException)) {
                System.out.println("TEST FAILED: Got unexpected non-null " +
                    "cause in ServiceNotFoundException");
                error = true;
            } else {
                System.out.println("TEST PASSED: Got expected non-null " +
                    "cause in ServiceNotFoundException");
                error = false;
            }
            e.printStackTrace(System.out);
        }

        // Unregister the MLet MBean
        //
        System.out.println("Unregister the MLet MBean");
        mbs.unregisterMBean(mletObjectName);

        // Release MBean server
        //
        System.out.println("Release the MBean server");
        MBeanServerFactory.releaseMBeanServer(mbs);

        // End Test
        //
        System.out.println("Bye! Bye!");
        if (error) System.exit(1);
    }
 
Example #21
Source File: ParserInfiniteLoopTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        boolean error = false;

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Instantiate an MLet
        //
        System.out.println("Create the MLet");
        MLet mlet = new MLet();

        // Register the MLet MBean with the MBeanServer
        //
        System.out.println("Register the MLet MBean");
        ObjectName mletObjectName = new ObjectName("Test:type=MLet");
        mbs.registerMBean(mlet, mletObjectName);

        // Call getMBeansFromURL
        //
        System.out.println("Call mlet.getMBeansFromURL(<url>)");
        String testSrc = System.getProperty("test.src");
        System.out.println("test.src = " + testSrc);
        String urlCodebase;
        if (testSrc.startsWith("/")) {
            urlCodebase =
                "file:" + testSrc.replace(File.separatorChar, '/') + "/";
        } else {
            urlCodebase =
                "file:/" + testSrc.replace(File.separatorChar, '/') + "/";
        }
        String mletFile = urlCodebase + args[0];
        System.out.println("MLet File = " + mletFile);
        try {
            mlet.getMBeansFromURL(mletFile);
            System.out.println(
                "TEST FAILED: Expected ServiceNotFoundException not thrown");
            error = true;
        } catch (ServiceNotFoundException e) {
            if (e.getCause() == null) {
                System.out.println("TEST FAILED: Got unexpected null cause " +
                    "in ServiceNotFoundException");
                error = true;
            } else if (!(e.getCause() instanceof IOException)) {
                System.out.println("TEST FAILED: Got unexpected non-null " +
                    "cause in ServiceNotFoundException");
                error = true;
            } else {
                System.out.println("TEST PASSED: Got expected non-null " +
                    "cause in ServiceNotFoundException");
                error = false;
            }
            e.printStackTrace(System.out);
        }

        // Unregister the MLet MBean
        //
        System.out.println("Unregister the MLet MBean");
        mbs.unregisterMBean(mletObjectName);

        // Release MBean server
        //
        System.out.println("Release the MBean server");
        MBeanServerFactory.releaseMBeanServer(mbs);

        // End Test
        //
        System.out.println("Bye! Bye!");
        if (error) System.exit(1);
    }
 
Example #22
Source File: GetMBeansFromURLTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        boolean error = false;

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Instantiate an MLet
        //
        System.out.println("Create the MLet");
        MLet mlet = new MLet();

        // Register the MLet MBean with the MBeanServer
        //
        System.out.println("Register the MLet MBean");
        ObjectName mletObjectName = new ObjectName("Test:type=MLet");
        mbs.registerMBean(mlet, mletObjectName);

        // Call getMBeansFromURL
        //
        System.out.println("Call mlet.getMBeansFromURL(<url>)");
        try {
            mlet.getMBeansFromURL("bogus://whatever");
            System.out.println("TEST FAILED: Expected " +
                               ServiceNotFoundException.class +
                               " exception not thrown.");
            error = true;
        } catch (ServiceNotFoundException e) {
            if (e.getCause() == null) {
                System.out.println("TEST FAILED: Got null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = true;
            } else {
                System.out.println("TEST PASSED: Got non-null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = false;
            }
            e.printStackTrace(System.out);
        }

        // Unregister the MLet MBean
        //
        System.out.println("Unregister the MLet MBean");
        mbs.unregisterMBean(mletObjectName);

        // Release MBean server
        //
        System.out.println("Release the MBean server");
        MBeanServerFactory.releaseMBeanServer(mbs);

        // End Test
        //
        System.out.println("Bye! Bye!");
        if (error) System.exit(1);
    }
 
Example #23
Source File: GetMBeansFromURLTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        boolean error = false;

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Instantiate an MLet
        //
        System.out.println("Create the MLet");
        MLet mlet = new MLet();

        // Register the MLet MBean with the MBeanServer
        //
        System.out.println("Register the MLet MBean");
        ObjectName mletObjectName = new ObjectName("Test:type=MLet");
        mbs.registerMBean(mlet, mletObjectName);

        // Call getMBeansFromURL
        //
        System.out.println("Call mlet.getMBeansFromURL(<url>)");
        try {
            mlet.getMBeansFromURL("bogus://whatever");
            System.out.println("TEST FAILED: Expected " +
                               ServiceNotFoundException.class +
                               " exception not thrown.");
            error = true;
        } catch (ServiceNotFoundException e) {
            if (e.getCause() == null) {
                System.out.println("TEST FAILED: Got null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = true;
            } else {
                System.out.println("TEST PASSED: Got non-null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = false;
            }
            e.printStackTrace(System.out);
        }

        // Unregister the MLet MBean
        //
        System.out.println("Unregister the MLet MBean");
        mbs.unregisterMBean(mletObjectName);

        // Release MBean server
        //
        System.out.println("Release the MBean server");
        MBeanServerFactory.releaseMBeanServer(mbs);

        // End Test
        //
        System.out.println("Bye! Bye!");
        if (error) System.exit(1);
    }
 
Example #24
Source File: ParserInfiniteLoopTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        boolean error = false;

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Instantiate an MLet
        //
        System.out.println("Create the MLet");
        MLet mlet = new MLet();

        // Register the MLet MBean with the MBeanServer
        //
        System.out.println("Register the MLet MBean");
        ObjectName mletObjectName = new ObjectName("Test:type=MLet");
        mbs.registerMBean(mlet, mletObjectName);

        // Call getMBeansFromURL
        //
        System.out.println("Call mlet.getMBeansFromURL(<url>)");
        String testSrc = System.getProperty("test.src");
        System.out.println("test.src = " + testSrc);
        String urlCodebase;
        if (testSrc.startsWith("/")) {
            urlCodebase =
                "file:" + testSrc.replace(File.separatorChar, '/') + "/";
        } else {
            urlCodebase =
                "file:/" + testSrc.replace(File.separatorChar, '/') + "/";
        }
        String mletFile = urlCodebase + args[0];
        System.out.println("MLet File = " + mletFile);
        try {
            mlet.getMBeansFromURL(mletFile);
            System.out.println(
                "TEST FAILED: Expected ServiceNotFoundException not thrown");
            error = true;
        } catch (ServiceNotFoundException e) {
            if (e.getCause() == null) {
                System.out.println("TEST FAILED: Got unexpected null cause " +
                    "in ServiceNotFoundException");
                error = true;
            } else if (!(e.getCause() instanceof IOException)) {
                System.out.println("TEST FAILED: Got unexpected non-null " +
                    "cause in ServiceNotFoundException");
                error = true;
            } else {
                System.out.println("TEST PASSED: Got expected non-null " +
                    "cause in ServiceNotFoundException");
                error = false;
            }
            e.printStackTrace(System.out);
        }

        // Unregister the MLet MBean
        //
        System.out.println("Unregister the MLet MBean");
        mbs.unregisterMBean(mletObjectName);

        // Release MBean server
        //
        System.out.println("Release the MBean server");
        MBeanServerFactory.releaseMBeanServer(mbs);

        // End Test
        //
        System.out.println("Bye! Bye!");
        if (error) System.exit(1);
    }
 
Example #25
Source File: ParserInfiniteLoopTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        boolean error = false;

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Instantiate an MLet
        //
        System.out.println("Create the MLet");
        MLet mlet = new MLet();

        // Register the MLet MBean with the MBeanServer
        //
        System.out.println("Register the MLet MBean");
        ObjectName mletObjectName = new ObjectName("Test:type=MLet");
        mbs.registerMBean(mlet, mletObjectName);

        // Call getMBeansFromURL
        //
        System.out.println("Call mlet.getMBeansFromURL(<url>)");
        String testSrc = System.getProperty("test.src");
        System.out.println("test.src = " + testSrc);
        String urlCodebase;
        if (testSrc.startsWith("/")) {
            urlCodebase =
                "file:" + testSrc.replace(File.separatorChar, '/') + "/";
        } else {
            urlCodebase =
                "file:/" + testSrc.replace(File.separatorChar, '/') + "/";
        }
        String mletFile = urlCodebase + args[0];
        System.out.println("MLet File = " + mletFile);
        try {
            mlet.getMBeansFromURL(mletFile);
            System.out.println(
                "TEST FAILED: Expected ServiceNotFoundException not thrown");
            error = true;
        } catch (ServiceNotFoundException e) {
            if (e.getCause() == null) {
                System.out.println("TEST FAILED: Got unexpected null cause " +
                    "in ServiceNotFoundException");
                error = true;
            } else if (!(e.getCause() instanceof IOException)) {
                System.out.println("TEST FAILED: Got unexpected non-null " +
                    "cause in ServiceNotFoundException");
                error = true;
            } else {
                System.out.println("TEST PASSED: Got expected non-null " +
                    "cause in ServiceNotFoundException");
                error = false;
            }
            e.printStackTrace(System.out);
        }

        // Unregister the MLet MBean
        //
        System.out.println("Unregister the MLet MBean");
        mbs.unregisterMBean(mletObjectName);

        // Release MBean server
        //
        System.out.println("Release the MBean server");
        MBeanServerFactory.releaseMBeanServer(mbs);

        // End Test
        //
        System.out.println("Bye! Bye!");
        if (error) System.exit(1);
    }
 
Example #26
Source File: GetMBeansFromURLTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        boolean error = false;

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Instantiate an MLet
        //
        System.out.println("Create the MLet");
        MLet mlet = new MLet();

        // Register the MLet MBean with the MBeanServer
        //
        System.out.println("Register the MLet MBean");
        ObjectName mletObjectName = new ObjectName("Test:type=MLet");
        mbs.registerMBean(mlet, mletObjectName);

        // Call getMBeansFromURL
        //
        System.out.println("Call mlet.getMBeansFromURL(<url>)");
        try {
            mlet.getMBeansFromURL("bogus://whatever");
            System.out.println("TEST FAILED: Expected " +
                               ServiceNotFoundException.class +
                               " exception not thrown.");
            error = true;
        } catch (ServiceNotFoundException e) {
            if (e.getCause() == null) {
                System.out.println("TEST FAILED: Got null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = true;
            } else {
                System.out.println("TEST PASSED: Got non-null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = false;
            }
            e.printStackTrace(System.out);
        }

        // Unregister the MLet MBean
        //
        System.out.println("Unregister the MLet MBean");
        mbs.unregisterMBean(mletObjectName);

        // Release MBean server
        //
        System.out.println("Release the MBean server");
        MBeanServerFactory.releaseMBeanServer(mbs);

        // End Test
        //
        System.out.println("Bye! Bye!");
        if (error) System.exit(1);
    }
 
Example #27
Source File: Main.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void main(String[] args) throws Exception
{
   // Create the MBeanServer
   MBeanServer server = MBeanServerFactory.createMBeanServer();

   // Register the MLet in the MBeanServer
   MLet mlet = new MLet();
   ObjectName mletName = new ObjectName("system:mbean=loader");
   server.registerMBean(mlet, mletName);

   // Set the MLet as context classloader
   // Can be useful for the loaded services that want to access this classloader.
   Thread.currentThread().setContextClassLoader(mlet);

   // Resolve the file to load MBeans from
   // If we got a program argument, we load it from there, otherwise
   // we assume we have a 'mbeans.mlet' file in this example's directory
   URL mbeansURL = null;
   if (args.length == 1)
   {
      String file = args[0];
      mbeansURL = new File(file).toURL();
   }
   else
   {
      mbeansURL = mlet.getResource("examples/services/loading/mbeans.mlet");
   }

   // If the URL is still null, abort
   if (mbeansURL == null) throw new ServiceNotFoundException("Could not find MBeans to load");

   // Load the MBeans
   Set mbeans = mlet.getMBeansFromURL(mbeansURL);

   System.out.println("MLet has now the following classpath: " + Arrays.asList(mlet.getURLs()));

   // Now let's check everything is ok.
   checkMBeansLoadedSuccessfully(mbeans);

   // Now the system is loaded, but maybe we should initialize and start them
   initializeMBeans(server, mbeans);
   startMBeans(server, mbeans);

   // Now the system is up and running
   System.out.println("System up and running !");

   // The program exits because none of the loaded MBeans in this example started a non-daemon thread.
}
 
Example #28
Source File: GetMBeansFromURLTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        boolean error = false;

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Instantiate an MLet
        //
        System.out.println("Create the MLet");
        MLet mlet = new MLet();

        // Register the MLet MBean with the MBeanServer
        //
        System.out.println("Register the MLet MBean");
        ObjectName mletObjectName = new ObjectName("Test:type=MLet");
        mbs.registerMBean(mlet, mletObjectName);

        // Call getMBeansFromURL
        //
        System.out.println("Call mlet.getMBeansFromURL(<url>)");
        try {
            mlet.getMBeansFromURL("bogus://whatever");
            System.out.println("TEST FAILED: Expected " +
                               ServiceNotFoundException.class +
                               " exception not thrown.");
            error = true;
        } catch (ServiceNotFoundException e) {
            if (e.getCause() == null) {
                System.out.println("TEST FAILED: Got null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = true;
            } else {
                System.out.println("TEST PASSED: Got non-null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = false;
            }
            e.printStackTrace(System.out);
        }

        // Unregister the MLet MBean
        //
        System.out.println("Unregister the MLet MBean");
        mbs.unregisterMBean(mletObjectName);

        // Release MBean server
        //
        System.out.println("Release the MBean server");
        MBeanServerFactory.releaseMBeanServer(mbs);

        // End Test
        //
        System.out.println("Bye! Bye!");
        if (error) System.exit(1);
    }
 
Example #29
Source File: PersisterTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void doDemo(String[] args)
   {
      String jarPath1 = args[0];
      String jarPath2 = args[1];
      String storePath = args[2];
      String filename = args[3];

      m_server = MBeanServerFactory.createMBeanServer("test");
      try
      {
         // register the mlet used to load the MBeans MLet one
         ObjectName mName1 = new ObjectName("loading:test=mlet1");
         MLet mlet1 = new MLet();
         m_server.registerMBean(mlet1, mName1);
         mlet1.addURL(jarPath1);
//			mlet1.addURL(new File("one.jar").toURL());

         ObjectName mName2 = new ObjectName("loading:test=mlet2");
         MLet mlet2 = new MLet();
         m_server.registerMBean(mlet2, mName2);
         mlet2.addURL(jarPath2);
//			mlet2.addURL(new File("two.jar").toURL());

         String mbeanClass1 = "mx4j.examples.tools.persister.MBeanOne";
         ObjectName mbeanName1 = new ObjectName("test:name=MBeanOne");
         m_server.createMBean(mbeanClass1, mbeanName1, mName1,
                              new Object[]{storePath, filename}, new String[]{"java.lang.String", "java.lang.String"});

         String mbeanClass2 = "mx4j.examples.tools.persister.MBeanTwo";
         ObjectName mbeanName2 = new ObjectName("test:name=MBeanTwo");
         m_server.createMBean(mbeanClass2, mbeanName2, mName2, new Object[]{new Integer(15)},
                              new String[]{"java.lang.Integer"});

         m_server.invoke(mbeanName2, "storeIt", new Object[]{m_server, mbeanName1},
                         new String[]{"javax.management.MBeanServer", "javax.management.ObjectName"});

         Object a = m_server.invoke(mbeanName2, "loadIt", new Object[]{m_server, mbeanName1},
                                    new String[]{"javax.management.MBeanServer", "javax.management.ObjectName"});

         if (a.getClass().getName() == mbeanClass2) System.out.println("Objects are equal and the same");
      }
      catch (Exception ex)
      {
         ex.printStackTrace();
      }
      finally
      {
         endExample();
      }
   }
 
Example #30
Source File: GetMBeansFromURLTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        boolean error = false;

        // Instantiate the MBean server
        //
        System.out.println("Create the MBean server");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();

        // Instantiate an MLet
        //
        System.out.println("Create the MLet");
        MLet mlet = new MLet();

        // Register the MLet MBean with the MBeanServer
        //
        System.out.println("Register the MLet MBean");
        ObjectName mletObjectName = new ObjectName("Test:type=MLet");
        mbs.registerMBean(mlet, mletObjectName);

        // Call getMBeansFromURL
        //
        System.out.println("Call mlet.getMBeansFromURL(<url>)");
        try {
            mlet.getMBeansFromURL("bogus://whatever");
            System.out.println("TEST FAILED: Expected " +
                               ServiceNotFoundException.class +
                               " exception not thrown.");
            error = true;
        } catch (ServiceNotFoundException e) {
            if (e.getCause() == null) {
                System.out.println("TEST FAILED: Got null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = true;
            } else {
                System.out.println("TEST PASSED: Got non-null cause in " +
                                   ServiceNotFoundException.class +
                                   " exception.");
                error = false;
            }
            e.printStackTrace(System.out);
        }

        // Unregister the MLet MBean
        //
        System.out.println("Unregister the MLet MBean");
        mbs.unregisterMBean(mletObjectName);

        // Release MBean server
        //
        System.out.println("Release the MBean server");
        MBeanServerFactory.releaseMBeanServer(mbs);

        // End Test
        //
        System.out.println("Bye! Bye!");
        if (error) System.exit(1);
    }