Liberty:設定 JMX 遞送環境的範例

您可以透過群體控制器伺服器,使用 Liberty 來呼叫群體成員伺服器上的「Java™ 管理延伸 (JMX)」管理 Bean (MBean)。

適用於分散式平台適用於 IBM i 平台註: 只有在 WebSphere® Application Server Liberty Network Deployment 和 WebSphere Application Server Liberty for z/OS® 中,才能使用 collectiveController-1.0 特性及其功能。在 WebSphere Application Server Liberty 或 WebSphere Application Server Liberty Core 中,此特性無法使用。如果您已安裝 WebSphere Application Server Liberty Network Deployment,您可以使用其 collectiveController-1.0 特性,來使用 WebSphere Application Server Liberty、WebSphere Application Server Liberty - Express® 或 WebSphere Application Server Liberty Core 安裝架構中的群體成員。

collectiveMember-1.0 特性可讓伺服器接受群體控制器(collectiveController-1.0 特性)的管理。 將伺服器配置成接受由群體控制器來管理之後,您可以透過群體控制器伺服器來直接呼叫群體成員上的任何 MBean。

以下是如何透過群體控制器伺服器來呼叫群體成員上的 MBean 的範例。

// 設定群體控制器伺服器的信任儲存庫。

    System.setProperty("javax.net.ssl.trustStore", "<trustStore for https connection to collective controller>");
    System.setProperty("javax.net.ssl.trustStorePassword", "<trustStore password>");

    Map<String, Object> environment = new HashMap<String, Object>();
    environment.put("jmx.remote.protocol.provider.pkgs", "com.ibm.ws.jmx.connector.client");
    environment.put(JMXConnector.CREDENTIALS, new String[] { "<username>", "<password>" });
    environment.put(ClientProvider.DISABLE_HOSTNAME_VERIFICATION, true);
    environment.put(ClientProvider.READ_TIMEOUT, 2 * 60 * 1000);

    JMXServiceURL url = new JMXServiceURL(
        "REST", "<hostname of collective controller server>", <https port>, "/IBMJMXConnectorREST");
    jmxConnector = JMXConnectorFactory.connect(url, environment);
    MBeanServerConnection exmbsc = jmxConnector.getMBeanServerConnection();

// 現在您有一個 MBeanServerConnection;不過,這時您的所有 MBean 呼叫
// 都是在群體控制器伺服器上。

// 以下幾行程式碼是設定遞送環境定義,// 以便所有呼叫都能遞送給群體成員。

   ObjectName rmObjectName = new ObjectName(
       "WebSphere:feature=collectiveController,type=RoutingContext,name=RoutingContext");

// 呼叫 MBeanRoutingContext MBean 來設定遞送環境定義。

    Object rcObj = connection.invoke(rmObjectName, "assignServerContext",
    new Object[] {
        "<hostname of the collective member>", "<collective member server usr dir>", "<collective member server name>"
    },  

// 使用群體成員伺服器使用者目錄及群體成員伺服器名稱,// 可以唯一識別在某部主機上的受管理伺服器。

    new String[] { "java.lang.String", "java.lang.String", "java.lang.String" });

    if (rcObj instanceof Boolean) {
        Boolean result = (Boolean) rcObj;
    if (result.booleanValue()) {
       System.out.println("routing context is configured correctly");
       }
    Or if (!result.booleanValue()) {
       System.out.println("routing context result is false");
       }
    } else {
        System.out.println("failed to configure routing context");
    }
如果已正確配置遞送環境定義,未來對這個 MBeanServerConnection 的所有呼叫都會遞送到目標群體成員伺服器。

指示主題類型的圖示 參照主題



「時間戳記」圖示 前次更新: 2016 年 11 月 30 日
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=rwlp_jmx_routing
檔名:rwlp_jmx_routing.html