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

GetMBeansFromURLTest.java 文件源码 项目:openjdk9 阅读 18 收藏 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);
    }
JMXHelper.java 文件源码 项目:gemfirexd-oss 阅读 17 收藏 0 点赞 0 评论 0
public static void connectToDS(String host, int port) throws Exception
{
  String url =MessageFormat.format(JMX_URI,  new Object[] { host, 
                                            String.valueOf(port) });

  try {
    JMXServiceURL jmxurl = new JMXServiceURL(url);
    connector = JMXConnectorFactory.connect(jmxurl, null);
    mbsc = connector.getMBeanServerConnection();

    String[] domains = mbsc.getDomains();
    String domain = null;
    for (int i = 0; i < domains.length; i++) {
      if (domains[i].equalsIgnoreCase(MBEAN_DOMAIN_GEMFIRE_NAME)) {
        domain = domains[i];
        break;
      }
    }

    Set set = mbsc.queryNames(new ObjectName(domain + ":*"), null);
    ObjectName on = null;
    for (Iterator iter = set.iterator(); iter.hasNext();) {
      on = (ObjectName)iter.next();
      String onType = on.getKeyProperty(MBEAN_PROPERTY_BEAN_TYPE);
      if (MBEAN_AGENT_TYPE.equalsIgnoreCase(onType))
        break;
    }
    agent = on;

    if (agent==null)
      throw new ServiceNotFoundException( MBEAN_AGENT_TYPE + 
                                         " could not be connected");

    String[] params = {}, signature = {};
    String method = "connectToSystem";
    ObjectName ret = null;

    ret = (ObjectName) mbsc.invoke(agent, method, params, signature);
    logger.info("Connected DS client");

    if (ret != null &&
        MBEAN_DISTRIBUTED_SYSTEM_TYPE.
          equalsIgnoreCase(ret.getKeyProperty(MBEAN_PROPERTY_BEAN_TYPE))) {
      distributedSys = ret;
    } else {
      ServiceNotFoundException ex = new ServiceNotFoundException(
          MBEAN_DISTRIBUTED_SYSTEM_TYPE + " could not be connected");
      throw ex;
    }
  }
  catch (NullPointerException nullEx) {
    logger.error(url + " is construed NULL", nullEx);
    throw nullEx;
  }
  catch (MalformedURLException malfEx) {
    logger.error(url + " is construed Malformed", malfEx);
    throw malfEx;
  }
  catch (SecurityException secuEx) {
    logger.error("Connection denied due to Security reasons", secuEx);
    throw secuEx;
  }
  catch (InstanceNotFoundException instEx) {
    logger.error("Did not find MBean Instance", instEx);
    throw instEx;
  }
  catch (MBeanException beanEx) {
    logger.error("Exception in MBean", beanEx.getCause());
    throw beanEx;
  }
  catch (ReflectionException reflEx) {
    logger.error("Could not get MBean Info", reflEx);
    throw reflEx;
  }
  catch (IOException ioEx) {
    logger.error("JMX Connection problem. Attempt opeartion Again", ioEx);
    throw ioEx;
  } finally {
    //shLock.unlock();
  }
}
JMXHelper.java 文件源码 项目:gemfirexd-oss 阅读 18 收藏 0 点赞 0 评论 0
public static void disconnectFromDS() throws Exception
{
  try {
    String[] domains = mbsc.getDomains();
    String domain = null;
    for (int i = 0; i < domains.length; i++) {
      if (domains[i].equalsIgnoreCase(MBEAN_DOMAIN_GEMFIRE_NAME)) {
        domain = domains[i];
        break;
      }
    }

    Set set = mbsc.queryNames(new ObjectName(domain + ":*"), null);
    ObjectName on = null;
    for (Iterator iter = set.iterator(); iter.hasNext();) {
      on = (ObjectName)iter.next();
      String onType = on.getKeyProperty(MBEAN_PROPERTY_BEAN_TYPE);
      if (MBEAN_AGENT_TYPE.equalsIgnoreCase(onType))
        break;
    }
    agent = on;

    if (agent==null)
      throw new ServiceNotFoundException( MBEAN_AGENT_TYPE + 
                                         " could not be contacted");

    String[] params = {}, signature = {};
    String method = "disconnectFromSystem";
    ObjectName ret = null;

    mbsc.invoke(agent, method, params, signature);
    logger.info("DisConnected DS client");
  }
  catch (SecurityException secuEx) {
    logger.error("Connection denied due to Security reasons", secuEx);
    throw secuEx;
  }
  catch (InstanceNotFoundException instEx) {
    logger.error("Did not find MBean Instance", instEx);
    throw instEx;
  }
  catch (MBeanException beanEx) {
    logger.error("Exception in MBean", beanEx.getCause());
    throw beanEx;
  }
  catch (ReflectionException reflEx) {
    logger.error("Could not get MBean Info", reflEx);
    throw reflEx;
  }
  catch (IOException ioEx) {
    logger.error("JMX Connection problem. Attempt opeartion Again", ioEx);
    throw ioEx;
  } finally {
    //shLock.unlock();
  }
}
ParserInfiniteLoopTest.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>)");
        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 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 17 收藏 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 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 18 收藏 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);
    }
Main.java 文件源码 项目:cacheonix-core 阅读 18 收藏 0 点赞 0 评论 0
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.
}
JMXHelper.java 文件源码 项目:gemfirexd-oss 阅读 17 收藏 0 点赞 0 评论 0
public static void connectToDS(String host, int port) throws Exception
{
  String url =MessageFormat.format(JMX_URI,  new Object[] { host, 
                                            String.valueOf(port) });

  try {
    JMXServiceURL jmxurl = new JMXServiceURL(url);
    connector = JMXConnectorFactory.connect(jmxurl, null);
    mbsc = connector.getMBeanServerConnection();

    String[] domains = mbsc.getDomains();
    String domain = null;
    for (int i = 0; i < domains.length; i++) {
      if (domains[i].equalsIgnoreCase(MBEAN_DOMAIN_GEMFIRE_NAME)) {
        domain = domains[i];
        break;
      }
    }

    Set set = mbsc.queryNames(new ObjectName(domain + ":*"), null);
    ObjectName on = null;
    for (Iterator iter = set.iterator(); iter.hasNext();) {
      on = (ObjectName)iter.next();
      String onType = on.getKeyProperty(MBEAN_PROPERTY_BEAN_TYPE);
      if (MBEAN_AGENT_TYPE.equalsIgnoreCase(onType))
        break;
    }
    agent = on;

    if (agent==null)
      throw new ServiceNotFoundException( MBEAN_AGENT_TYPE + 
                                         " could not be connected");

    String[] params = {}, signature = {};
    String method = "connectToSystem";
    ObjectName ret = null;

    ret = (ObjectName) mbsc.invoke(agent, method, params, signature);
    logger.info("Connected DS client");

    if (ret != null &&
        MBEAN_DISTRIBUTED_SYSTEM_TYPE.
          equalsIgnoreCase(ret.getKeyProperty(MBEAN_PROPERTY_BEAN_TYPE))) {
      distributedSys = ret;
    } else {
      ServiceNotFoundException ex = new ServiceNotFoundException(
          MBEAN_DISTRIBUTED_SYSTEM_TYPE + " could not be connected");
      throw ex;
    }
  }
  catch (NullPointerException nullEx) {
    logger.error(url + " is construed NULL", nullEx);
    throw nullEx;
  }
  catch (MalformedURLException malfEx) {
    logger.error(url + " is construed Malformed", malfEx);
    throw malfEx;
  }
  catch (SecurityException secuEx) {
    logger.error("Connection denied due to Security reasons", secuEx);
    throw secuEx;
  }
  catch (InstanceNotFoundException instEx) {
    logger.error("Did not find MBean Instance", instEx);
    throw instEx;
  }
  catch (MBeanException beanEx) {
    logger.error("Exception in MBean", beanEx.getCause());
    throw beanEx;
  }
  catch (ReflectionException reflEx) {
    logger.error("Could not get MBean Info", reflEx);
    throw reflEx;
  }
  catch (IOException ioEx) {
    logger.error("JMX Connection problem. Attempt opeartion Again", ioEx);
    throw ioEx;
  } finally {
    //shLock.unlock();
  }
}
JMXHelper.java 文件源码 项目:gemfirexd-oss 阅读 17 收藏 0 点赞 0 评论 0
public static void disconnectFromDS() throws Exception
{
  try {
    String[] domains = mbsc.getDomains();
    String domain = null;
    for (int i = 0; i < domains.length; i++) {
      if (domains[i].equalsIgnoreCase(MBEAN_DOMAIN_GEMFIRE_NAME)) {
        domain = domains[i];
        break;
      }
    }

    Set set = mbsc.queryNames(new ObjectName(domain + ":*"), null);
    ObjectName on = null;
    for (Iterator iter = set.iterator(); iter.hasNext();) {
      on = (ObjectName)iter.next();
      String onType = on.getKeyProperty(MBEAN_PROPERTY_BEAN_TYPE);
      if (MBEAN_AGENT_TYPE.equalsIgnoreCase(onType))
        break;
    }
    agent = on;

    if (agent==null)
      throw new ServiceNotFoundException( MBEAN_AGENT_TYPE + 
                                         " could not be contacted");

    String[] params = {}, signature = {};
    String method = "disconnectFromSystem";
    ObjectName ret = null;

    mbsc.invoke(agent, method, params, signature);
    logger.info("DisConnected DS client");
  }
  catch (SecurityException secuEx) {
    logger.error("Connection denied due to Security reasons", secuEx);
    throw secuEx;
  }
  catch (InstanceNotFoundException instEx) {
    logger.error("Did not find MBean Instance", instEx);
    throw instEx;
  }
  catch (MBeanException beanEx) {
    logger.error("Exception in MBean", beanEx.getCause());
    throw beanEx;
  }
  catch (ReflectionException reflEx) {
    logger.error("Could not get MBean Info", reflEx);
    throw reflEx;
  }
  catch (IOException ioEx) {
    logger.error("JMX Connection problem. Attempt opeartion Again", ioEx);
    throw ioEx;
  } finally {
    //shLock.unlock();
  }
}


问题


面经


文章

微信
公众号

扫码关注公众号