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