사용자 정의 MBean을 사용하여 WebSphere Application Server 관리 시스템 확장

WebSphere 프로세스 중 하나에 새 JMX(Java™ Management Extensions) MBeans(세부사항은 JMX 1.x 스펙 참조)를 제공 및 등록하여 WebSphere® Application Server 관리 시스템을 확장할 수 있습니다.

이 태스크 정보

JMX MBean은 특정 논리 부분에 대한 관리 인터페이스를 표시합니다. 표준 제품 인프라의 관리 자원은 모두 JMX MBeans로 표시됩니다. 자체 MBeans를 작성하고 WebSphere 프로세스에서 실행 중인 JMX MBeanServer에 등록할 수 있는 방법에는 여러 가지가 있습니다. 자세한 정보는 MBean Java API(Application Programming Interface) 문서를 참조하십시오. 이 Information Center에서 참조 > Mbean 인터페이스를 클릭하십시오.

프로시저

  1. 사용자 정의 JMX MBeans를 작성하십시오.

    MBeans를 작성하여 제품 관리 시스템을 확장하는 경우 선택할 수 있는 몇 가지 대안이 있습니다. 다른 애플리케이션에서 기존 JMX MBean 을 사용할 수 있습니다. 표준 MBeans, 동적 MBeans, 개방형 MBeans, 모델 MBeans 등 제품 프로세스에서 WebSphere Application Server 환경 외부의 JMX MBean 서버에서 테스트한 MBean을 모두 등록할 수 있습니다.

    기존의 JMX MBeans 및 제품 환경 외부에서 작성하고 테스트한 MBeans 외에도, WebSphere에서 제공한 특별 분배 확장을 사용하여 WebSphere ExtensionMBean 프로바이더를 작성할 수 있습니다. 이 대안을 사용하면 제품 관리 시스템의 모든 분배 기능을 보다 잘 통합할 수 있습니다. ExtensionMBean 프로바이더는 사용자가 제품과 함께 제공되는 DTD에 따라 MBean 디스크립터가 포함된 XML 파일을 제공함을 의미합니다. 이 디스크립터는 WebSphere 시스템에 사용자의 MBean이 지원하는 모든 속성, 조작 및 알림을 설명합니다. WebSphere 시스템은 이 정보를 사용하여 원격 요청을 사용자 MBean에 라우트하고 원격 리스너가 사용자 MBean 이벤트 알림을 수신하도록 등록할 수 있습니다.

    모든 내부 WebSphere MBeans는 모델 MBean 패턴을 따릅니다. 순수 Java 클래스는 관리 기능의 실제 로직을 제공하며 WebSphere MBeanFactory 클래스는 XML MBean 디스크립터로부터 이러한 기능에 대한 설명을 읽고 디스크립터와 일치하는 ModelMBean의 인스턴스를 작성합니다. 이 ModelMBean 인스턴스는 사용자의 Java 클래스에 바인드되어 사용자 클래스와 동일한 프로세스에서 실행 중인 MBeanServer에 등록됩니다. 이제 Java 코드를 표시하기 위해 작성 및 등록된 ModelMBean을 통해 WebSphere Application Server 관리 클라이언트에서 해당 코드를 호출할 수 있습니다.

    [z/OS]WebSphere Application Server 분배 플랫폼과 WebSphere Application Server for z/OS® 플랫폼 모두에서 실행되는 사용자 MBeans에는 z/OS 다중 프로세스 모델에서 적절히 작동하는 특수 코딩이 필요할 수 있습니다. 각 애플리케이션 서버가 단일 JVM(Java Virtual Machine)에서 실행되는 분배 플랫폼의 경우 MBean 서버가 하나만 있습니다. MBean 서버는 애플리케이션 서버에 등록된 모든 MBean을 제어합니다. z/OS 플랫폼에는 제어 프로세스 및 하위(servant) 프로세스 연합이 있으며 각 프로세스에는 고유한 MBean 서버가 있습니다. 제어 프로세스는 종속 프로세스 간에 요청을 분배할 수 있도록 고유한 MBean 프록시 서버를 갖습니다. JMX MBean 다중 프로세스 모델 요청 플로우에 대한 세부사항을 참조하십시오.

  2. 선택적으로 명시적인 MBean 보안 정책을 정의하십시오.

    MBean 보안 정책을 정의하지 않는 경우 제품에서는 기본 보안 정책을 사용합니다.

  3. 새 MBean을 등록하십시오. MBean을 등록하는 여러 가지 방법이 있습니다.

    WebSphere Application Server 관리 서비스에 MBean을 등록할 수 있습니다.

    WebSphere Application Server 프로세스에서 MBeanServer에 MBean을 등록할 수 있습니다. 다음 목록은 환경 설정 순서대로 사용 가능한 옵션을 설명합니다.
    • MBeanFactory 클래스를 수행하십시오. WebSphere Application Server 시스템과 최대한 통합하려는 경우 MBeanFactory 클래스를 사용하여 MBeanFactory 클래스의 activateMBean 및 deactivateMBean 메소드를 통해 MBean의 라이프사이클을 관리하십시오. RuntimeCollaborator 추상 수퍼클래스의 서브클래스 및 XML MBean 디스크립터 파일을 제공하여 이 메소드를 사용하십시오. 이러한 접근 방법을 사용하여 MBean 디스크립터에 정의된 관리 인터페이스를 구현하는 순수 Java 클래스를 제공하십시오. MBeanFactory 클래스는 실제 ModelMBean을 작성하여 사용자 대신 제품 관리 시스템에 등록합니다.

      이는 모델 MBean을 등록하기 위해 권장하는 옵션입니다.

    • JMXManageable 및 CustomService 인터페이스를 사용하십시오. CustomService 인터페이스를 구현(JMXManageable 인터페이스 또한 구현)하여 WebSphere 관리와의 통합 프로세스를 보다 쉽게 만들 수 있습니다. 이러한 접근 방법을 사용하면 RuntimeCollaborator를 제공하지 않아도 됩니다. CustomService 인터페이스가 초기화되면 WebSphere MBeanFactory 클래스가 XML MBean 디스크립터 파일을 읽어 CustomService 인터페이스에 MBean을 자동으로 작성, 바인드 및 등록합니다. CustomService의 종료 메소드가 호출되면 제품 시스템이 자동으로 MBean을 비활성화합니다.
    • AdminService 인터페이스를 수행하십시오. AdminService 인터페이스에서 registerMBean() 메소드를 호출할 수 있으며, 적절한 보안 검사 후 이 호출은 프로세스의 기본 MBeanServer로 위임됩니다. AdminServiceFactory 클래스의 getAdminService() 메소드를 사용하여 AdminService에 대한 참조를 가져올 수 있습니다.

      이는 표준, 동적 및 개방형 MBean을 등록하기 위해 권장하는 옵션입니다. UserCollaborator 클래스를 구현하여 MBean을 사용하고 분산 및 z/OS 플랫폼에서 일관된 레벨의 지원을 제공하십시오.

      [z/OS]z/OS 플랫폼의 경우 AdminService 인터페이스에서 registerMBean() 메소드를 통해 등록된 MBean은 서버 외부에 표시되지 않으며 등록된 하위(servant) 프로세스 내에서만 호출할 수 있습니다.

    • BeanServer 인스턴스를 직접 가져오십시오. MBeanFactory 클래스의 getMBeanServer() 메소드를 호출하여 제품 프로세스에서 실행 중인 JMX MBeanServer 인스턴스에 대한 직접 참조를 가져올 수 있습니다. AdminService 인터페이스의 getMBeanFactory() 메소드를 호출하여 MBeanFactory 클래스에 대한 참조를 가져오십시오.

      사용자 정의 MBean을 MBean 서버에 직접 등록할 경우, MBean 오브젝트 이름은 기본값으로 셀, 노드 및 프로세스 이름 키를 사용하여 향상됩니다. 이 등록을 사용하면 MBean이 관리 시스템의 분배 기능에 포함될 수 있습니다. com.ibm.websphere.mbeans.disableRouting 사용자 정의 특성을 사용하여 기본 작동을 Off로 설정할 수 있습니다.

      com.ibm.websphere.mbeans.disableRouting 사용자 정의 특성 설정 및 사용 방법에 대한 자세한 정보는 관리 서비스 사용자 정의 특성을 참조하십시오.

결과

MBean을 작성 및 등록하는 데 사용된 방법에 관계없이 새 MBean 코드에 적절한 Java 2 보안 권한을 설정해야 합니다. WebSphere AdminService 및 MBeanServer는 Java 2 보안 권한을 사용하여 강력히 보호되며 코드 기본 권한을 명확히 부여하지 않은 경우 이 클래스의 메소드를 호출하려고 시도하면 보안 예외가 발생합니다. MBean을 애플리케이션의 일부로 제공하는 경우 애플리케이션 메타데이터의 일부로 제공하는 was.policy 파일에서 권한을 설정할 수 있습니다. CustomService 인터페이스 또는 애플리케이션으로서 전달되지 않는 기타 코드를 사용하는 경우, 노드 구성의 library.policy 파일 또는 특정 설치를 위한 properties 디렉토리의 server.policy 파일도 편집할 수 있습니다.

[z/OS]

예제: SampleStateMBean MBean

MBeanDescriptor

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MBean SYSTEM "MbeanDescriptor.dtd">
<MBean type="SampleStateMBean"
  aggregationHandlerClass="com.ibm.ws390.sample.SampleStateAggregationHandler"
  eventHandlerClass="com.ibm.ws390.sample.SampleStateEventHandler"
  invocationHandlerClass="com.ibm.ws390.sample.SampleStateInvocationHandler"
  stateObjectClass="com.ibm.ws390.sample.SampleState"
  version="6.0"
  platform="dynamicproxy"
  description="Sample State MBean for the documentation example.">

  <attribute description="The name of the MBean."
    getMethod="getMBeanName" name="mbeanName" type="java.lang.String"
    proxyInvokeType="unicall"/>
  <attribute description="The state of the MBean." name="state"
    getMethod="getState" setMethod="setState" type="java.lang.String"
    proxyInvokeType="multicall" proxySetterInvokeType="multicall"/>
  <operation
    description="Initialize the State MBean."
    impact="ACTION" name="initializeState" role="operation"
    targetObjectType="objectReference" type="void" proxyInvokeType="multicall">
    <signature>
      <parameter description="The name of the MBean."
        name="mbeanName" type="java.lang.String"/>
      <parameter description="The initial state of the MBean."
        name="mbeanName" type="java.lang.String"/>
    </signature>
  </operation> 
  
  <notification name="j2ee.state.starting" severity="6" log="false"
                description="This sample state MBean is in starting state.">
      <notificationType>j2ee.state.starting</notificationType>
  </notification>    
  <notification name="j2ee.state.running" severity="6" log="false"
                description="This sample state MBean is in running state.">
      <notificationType>j2ee.state.running</notificationType>
  </notification>    
  <notification name="j2ee.state.stopping" severity="6" log="false"
                description="This sample state MBean is in stopping state.">
      <notificationType>j2ee.state.stopping</notificationType>
  </notification>    
  <notification name="j2ee.state.stopped" severity="6" log="false"
                description="This sample state MBean is in stopped state.">
      <notificationType>j2ee.state.stopped</notificationType>
  </notification>    
</MBean>

SampleState 구현

package com.ibm.ws390.sample;

import com.ibm.ejs.ras.Tr;
import com.ibm.ejs.ras.TraceComponent;
import java.io.Serializable;
import com.ibm.websphere.management.dynamicproxy.StateObject;

public class SampleState extends StateObject {
    
    private static TraceComponent tc =
    Tr.register(SampleState.class,"SampleState",null);
    
    // Package protected STATE constants.
    static final String STATE_STARTING = "j2ee.state.starting";
    static final String STATE_RUNNING  = "j2ee.state.running";
    static final String STATE_STOPPING = "j2ee.state.stopping";
    static final String STATE_STOPPED  = "j2ee.state.stopped";
    
    // Dynamicproxy State is initialized with STOPPED state.
    private String state = STATE_STOPPED;
    
    public SampleState() {
        if (tc.isEntryEnabled()) Tr.entry(tc,"<init>");
        
        // State is initialized during "state" initialization,
        // but can also be initialized here in the constructor as well.
        /*
        state = "WebSphere Application Server for z/OS ready for e-business";
        */
        
        if (tc.isEntryEnabled()) Tr.exit(tc,"<init>");
    }
    
    public synchronized String getState() {
        if (tc.isEntryEnabled()) Tr.entry(tc,"getState");
        if (tc.isEntryEnabled()) Tr.exit(tc,"getState",state);
        return state;
    }
    
    public synchronized void setState(String state) {
        if (tc.isEntryEnabled()) Tr.entry(tc,"setState",state);
        this.state = state;
        if (tc.isEntryEnabled()) Tr.exit(tc,"setState");
    }
    
    public synchronized String getStateObjectInfo() {
        return state;
    }
}

SampleStateAggregationHandler 구현

package com.ibm.ws390.sample;

import com.ibm.websphere.management.dynamicproxy.AggregationHandler;
import com.ibm.websphere.management.dynamicproxy.StateObject;

import com.ibm.ejs.ras.Tr;
import com.ibm.ejs.ras.TraceComponent;

public class SampleStateAggregationHandler implements AggregationHandler {
    
    private static TraceComponent tc =
    Tr.register(SampleStateAggregationHandler.class,"SampleState",null);
    
    /**
     * Return an aggregated result from a multicall Mbean operation which
     * compiles through all servant MBeans' results and returns a respective
     * single return value for an invoked method.
     *
     * @param  methodName           MBean method name
     * @param  params               MBean method parameters
     * @param  signatures           MBean method signatures
     * @param  servantMBeanResults  Result of each servant MBean instances
     *                              invoked by the dynamicproxy multicast 
     *                              invocation.
     *                              Note: this value can be "null" OR can be
     *                              an array of "null"s in case return value
     *                              of the method is "void." 구현
     *                              of this method MUST handle this case to
     *                              avoid a <code>NullPointerException</code>.
     * @param stateObject
     *        MBean provider provided <code>StateObject</code> used by 
     *        dynamicproxy MBean in CR to manage its state. Note: this object
     *        MAY BE null if "stateObjectClass" was not specified OR internal
     *        error occurred during initialization of this dynamicproxy MBean.
     *        Implmentation MUST properly handle "null" input.
     *                
     * @return aggregated result as defined by MBean xml for specified
     *         MBean operation.
     */
    public Object aggregateResults(String methodName,
                                   Object[] params,
                                   String[] signatures,
                                   Object[] servantMBeanResults,
                                   StateObject stateObject) {
                                       
        if (tc.isEntryEnabled()) Tr.entry(tc,"aggregateResults",methodName);
        
        // As you can see from the MBeanDescriptor of SampleStateMBean,
        // it declares the following four methods:
        // 1. String getMBeanName()         [proxyInvokeType == unicall]
        // 2. String getState()             [proxyInvokeType == multicall]
        // 3. void setState(String)         [proxyInvokeType == multicall]
        // 4. void initializeState()        [proxyInvokeType == multicall]
        //
        // From these methods, the only one that requires aggregation
        // is #2 getState method which is a multicall MBean operation AND
        // it returns a value that can be aggregated.
        //
        // In this example, we simply take each servants' getState MBean
        // request result and concatenate them into one long String that
        // displays each servants' state. 
        if (methodName.equals("getState")) {
            StringBuffer stateBuf = new StringBuffer();
            
            for (int i=0; i<servantMBeanResults.length; i++) {
                stateBuf.append("SERVANT #" + i + " state ==|" + 
                                servantMBeanResults[i] + "|== ");
            }
            return stateBuf.toString();
        }
        // If we also had an example method which returns say an int, 
        // getNumberOfMBeans(), it can take the similar approach
        // and to add each servants' getNumberOfMBeans() result together here.
        /* example added for non-existent method: int getNumberOfMBeans()
        else if (methodName.equals("getNumberOfMBeans")) {
            int aggregatedResult = 0;
            
            for (int i=0; i<servantMBeanResults.length; i++) {
                aggregatedResult += (int) servantMBeanResults[i];
            }
            return aggregatedResult;
        }
        */
        
        return methodName + " is NOT handled by " + getClass().getName() + "!";
    }
    
}

주제 유형을 표시하는 아이콘 태스크 주제



시간소인 아이콘 마지막 업데이트 날짜: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tjmx_extend
파일 이름:tjmx_extend.html