Main.java 文件源码

java
阅读 18 收藏 0 点赞 0 评论 0

项目:cacheonix-core 作者:
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.
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号