java类javax.management.ServiceNotFoundException的实例源码

Main.java 文件源码 项目:cacheonix-core 阅读 20 收藏 0 点赞 0 评论 0
private static void checkMBeansLoadedSuccessfully(Set mbeans) throws ServiceNotFoundException
{
   // MLet.getMBeansFromURL returns a Set containing exceptions if an MBean could not be loaded
   boolean allLoaded = true;
   for (Iterator i = mbeans.iterator(); i.hasNext();)
   {
      Object mbean = i.next();
      if (mbean instanceof Throwable)
      {
         ((Throwable)mbean).printStackTrace();
         allLoaded = false;
         // And go on with the next
      }
      else
      {
         // Ok, the MBean was registered successfully
         System.out.println("Registered MBean: " + mbean);
      }
   }

   if (!allLoaded) throw new ServiceNotFoundException("Some MBean could not be loaded");
}
ServiceDiscovery.java 文件源码 项目:vert.x-microservice 阅读 26 收藏 0 点赞 0 评论 0
private ServiceInfo getServiceInfoByVertx(Consumer<ServiceInfoResult> consumer, Function<ServiceInfo,Boolean> criteria) {
    // TODO add caching mechanism with TTL to reduce
    vertx.eventBus().send(GlobalKeyHolder.SERVICE_REGISTRY_GET, "xyz", (AsyncResultHandler<Message<byte[]>>) h ->
            {
                if (h.succeeded()) {
                    final List<ServiceInfo> serviceInfos = getServiceInfoFromMessage(h).filter(info -> criteria.apply(info)).collect(Collectors.toList());
                    if(!serviceInfos.isEmpty()){
                        consumer.accept(new ServiceInfoResult(serviceInfos.stream(),h.succeeded(),h.cause()));
                    }else {
                        consumer.accept(new ServiceInfoResult(serviceInfos.stream(),false,new ServiceNotFoundException("selected service not found")));
                    }
                } else {
                    consumer.accept(new ServiceInfoResult(Stream.<ServiceInfo>empty(),h.succeeded(),h.cause()));
                }

            }
    );

    return null;
}
FormService.java 文件源码 项目:abstractform 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Find in the Service Loader a {@link FormToolkit} that returns the required form instance type of rendered forms
 * 
 * @param implementationClass
 *            The specific implementation class that the form toolkit must return
 * @return The FormToolkit that build form instances of that its specific implementation returns the given class
 * @throws ServiceNotFoundException
 *             When a FormToolkit is not found
 */
@SuppressWarnings("unchecked")
public <S> FormToolkit<S> getFormToolkit(Class<S> implementationClass) throws ServiceNotFoundException {
    Iterator<FormToolkit> it = loader.iterator();
    FormToolkit toolkit = null;
    while (toolkit == null && it.hasNext()) {
        FormToolkit tl = it.next();
        if (implementationClass.isAssignableFrom(tl.getImplementationClass())) {
            toolkit = tl;
        }
    }
    if (toolkit == null) {
        throw new ServiceNotFoundException();
    } else {
        return toolkit;
    }
}
BFormService.java 文件源码 项目:abstractform 阅读 19 收藏 0 点赞 0 评论 0
@SuppressWarnings({ "unchecked" })
public <S> BFormToolkit<S> getFormToolkit(Class<S> implementationClass) throws ServiceNotFoundException {
    Iterator<BFormToolkit> it = loader.iterator();
    BFormToolkit toolkit = null;
    while (toolkit == null && it.hasNext()) {
        BFormToolkit tl = it.next();
        if (implementationClass.isAssignableFrom(tl.getImplementationClass())) {
            toolkit = tl;
        }
    }
    if (toolkit == null) {
        throw new ServiceNotFoundException();
    } else {
        return toolkit;
    }
}
TestVaadinBuilder.java 文件源码 项目:abstractform 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void testServiceLoader() throws ServiceNotFoundException {
    FormToolkit<Component> toolkit = FormService.getInstance().getFormToolkit(Component.class);

    Form form = new SampleForm();
    VaadinFormInstance instance = (VaadinFormInstance) toolkit.buildForm(form);
    assertNotNull(instance);
    Component component = instance.getImplementation();
    assertThat(component, instanceOf(VerticalLayout.class));

    Component cifCode = instance.getComponentById("fCif");
    assertThat(cifCode, instanceOf(TextField.class));

    Component active = instance.getComponentById("fActive");
    assertThat(active, instanceOf(CheckBox.class));

}
MLet.java 文件源码 项目:OpenJSharp 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
MLet.java 文件源码 项目:jdk8u-jdk 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
MLet.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.DEBUG)) {
            MLET_LOGGER.log(Level.DEBUG, "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
MLet.java 文件源码 项目:openjdk9 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
MLet.java 文件源码 项目:Java8CN 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
MLet.java 文件源码 项目:jdk8u_jdk 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
MLet.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
MBean.java 文件源码 项目:TayzGrid 阅读 25 收藏 0 点赞 0 评论 0
public Object invoke(String actionName, Object[] params, String[] argTypes)
        throws MBeanException, ReflectionException
{
    assertNotNull("actionName", actionName);

    // params argTypes are allowed to be null and mean no-arg method
    if (params == null) {
        params = NO_PARAMS;
    }
    if (argTypes == null) {
        argTypes = NO_ARGS;
    }

    for (int i = 0; i < argTypes.length; i++) {
        assertNotNull("argTypes[" + i + "]", argTypes[i]);
    }

    Signature signature = new Signature(actionName, argTypes);
    MBeanOperation operation = operations.get(signature);
    if (operation == null) {
        String message = "Operation " + signature + " not found";
        throw new MBeanException(new ServiceNotFoundException(message), message);
    }

    Object result = operation.invoke(params);
    return result;
}
MLet.java 文件源码 项目:infobip-open-jdk-8 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
MLet.java 文件源码 项目:jdk8u-dev-jdk 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
MLet.java 文件源码 项目:jdk7-jdk 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
MLet.java 文件源码 项目:openjdk-source-code-learn 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
ServiceInfo.java 文件源码 项目:vert.x-microservice 阅读 24 收藏 0 点赞 0 评论 0
public ServiceInfo operation(final String name, Consumer<OperationResult> consumer) {
    final Optional<Operation> first = Stream.of(operations).filter(op -> op.getName().equalsIgnoreCase(name)).findFirst();
    if(first.isPresent()){
         consumer.accept(new OperationResult(first.get(),true,null));
    }   else {
        consumer.accept(new OperationResult(null,false,new ServiceNotFoundException("no operation "+name+" was found")));
    }
    return this;
}
MLet.java 文件源码 项目:OLD-OpenJDK8 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
VaadinBindingFormToolkit.java 文件源码 项目:abstractform 阅读 22 收藏 0 点赞 0 评论 0
@Override
public <U> VaadinBindingFormInstance<U> buildForm(BForm<U> form) {
    try {
        return buildForm(form, BindingService.getInstance().getBindingToolkit());
    } catch (ServiceNotFoundException e) {
        throw new UnsupportedOperationException("Default binding toolkit not found", e);
    }
}
BindingService.java 文件源码 项目:abstractform 阅读 23 收藏 0 点赞 0 评论 0
public BindingToolkit getBindingToolkit() throws ServiceNotFoundException {
    Iterator<BindingToolkit> it = loader.iterator();
    BindingToolkit toolkit = null;
    while (toolkit == null && it.hasNext()) {
        BindingToolkit tl = it.next();
        toolkit = tl;
    }
    if (toolkit == null) {
        throw new ServiceNotFoundException();
    } else {
        return toolkit;
    }
}
TestSwingBuilder.java 文件源码 项目:abstractform 阅读 22 收藏 0 点赞 0 评论 0
@Test
public void testServiceLoader() throws ServiceNotFoundException {
    FormToolkit<JComponent> toolkit = FormService.getInstance().getFormToolkit(JComponent.class);

    Form form = new SampleForm();
    FormInstance<JComponent> instance = toolkit.buildForm(form);
    assertNotNull(instance);

}
MLet.java 文件源码 项目:openjdk-jdk7u-jdk 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
MLet.java 文件源码 项目:openjdk-icedtea7 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Appends the specified URL to the list of URLs to search for classes and
 * resources.
 * @exception ServiceNotFoundException The specified URL is malformed.
 */
public void addURL(String url) throws ServiceNotFoundException {
    try {
        URL ur = new URL(url);
        if (!Arrays.asList(getURLs()).contains(ur))
            super.addURL(ur);
    } catch (MalformedURLException e) {
        if (MLET_LOGGER.isLoggable(Level.FINEST)) {
            MLET_LOGGER.logp(Level.FINEST, MLet.class.getName(),
                    "addUrl", "Malformed URL: " + url, e);
        }
        throw new
            ServiceNotFoundException("The specified URL is malformed");
    }
}
PPTApi.java 文件源码 项目:lodms-plugins 阅读 21 收藏 0 点赞 0 评论 0
public List<Project> getProjects() throws AuthenticationFailedException, ServiceNotFoundException, Exception {
    HttpURLConnection con = getServiceConnection("api/projects");
    if (con.getResponseCode() == 401) {
        throw new AuthenticationFailedException();
    } else if (con.getResponseCode() == 404) {
        throw new ServiceNotFoundException();
    }
    JavaType type = CollectionType.construct(ArrayList.class, SimpleType.construct(Project.class));
    InputStream in = con.getInputStream();
    try {
        return (List<Project>) objectMapper.readValue(in, type);
    } finally {
        in.close();
    }
}
ParserInfiniteLoopTest.java 文件源码 项目:jdk8u-jdk 阅读 21 收藏 0 点赞 0 评论 0
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);
    }
GetMBeansFromURLTest.java 文件源码 项目:jdk8u-jdk 阅读 19 收藏 0 点赞 0 评论 0
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);
    }
ParserInfiniteLoopTest.java 文件源码 项目:openjdk-jdk10 阅读 20 收藏 0 点赞 0 评论 0
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);
    }
GetMBeansFromURLTest.java 文件源码 项目:openjdk-jdk10 阅读 20 收藏 0 点赞 0 评论 0
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);
    }
ParserInfiniteLoopTest.java 文件源码 项目:openjdk9 阅读 20 收藏 0 点赞 0 评论 0
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);
    }


问题


面经


文章

微信
公众号

扫码关注公众号