Top


定義場所(file name)

jdk/src/share/classes/sun/management/Agent.java

名前(function name)

    public static void startAgent() throws Exception {

本体部(body)

  {- -------------------------------------------
  (1) (-Dcom.sun.management.agent.class が指定されているかどうかで 2通りに分岐する)
      ---------------------------------------- -}

  {- -------------------------------------------
  (1) -Dcom.sun.management.agent.class の値を (もしあれば) 取得する.
      ---------------------------------------- -}

            String prop = System.getProperty("com.sun.management.agent.class");

  {- -------------------------------------------
  (1) -Dcom.sun.management.agent.class が指定されていなければ, 
      startAgent(Properties props) で JMX Management Server を起動させる.
      ---------------------------------------- -}

            // -Dcom.sun.management.agent.class not set so read management
            // properties and start agent
            if (prop == null) {
                // initialize management properties
                Properties props = getManagementProperties();
                if (props != null) {
                    startAgent(props);
                }
                return;
            }

  {- -------------------------------------------
  (1) -Dcom.sun.management.agent.class が指定されていた場合は, 
      (クラス名とオプション値にパースした後で)
      指定されたクラスの premain() メソッドを呼び出す.

      なお, 
      ---------------------------------------- -}

            // -Dcom.sun.management.agent.class=<agent classname>:<agent args>
            String[] values = prop.split(":");
            if (values.length < 1 || values.length > 2) {
                error(AGENT_CLASS_INVALID, "\"" + prop + "\"");
            }
            String cname = values[0];
            String args = (values.length == 2 ? values[1] : null);

            if (cname == null || cname.length() == 0) {
                error(AGENT_CLASS_INVALID, "\"" + prop + "\"");
            }

            if (cname != null) {
                try {
                    // Instantiate the named class.
                    // invoke the premain(String args) method
                    Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(cname);
                    Method premain = clz.getMethod("premain",
                                                   new Class[] { String.class });
                    premain.invoke(null, /* static */
                                   new Object[] { args });
                } catch (ClassNotFoundException ex) {
                    error(AGENT_CLASS_NOT_FOUND, "\"" + cname + "\"");
                } catch (NoSuchMethodException ex) {
                    error(AGENT_CLASS_PREMAIN_NOT_FOUND, "\"" + cname + "\"");
                } catch (SecurityException ex) {
                    error(AGENT_CLASS_ACCESS_DENIED);
                } catch (Exception ex) {
                    String msg = (ex.getCause() == null
                                     ? ex.getMessage()
                                     : ex.getCause().getMessage());
                    error(AGENT_CLASS_FAILED, msg);
                }
            }
        }

This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.