登録されたMBeanからの通知をリッスンするNotificationListenerを追加しようとしています。
MBeanのセットアップを通じて、WAS7テスト環境に接続し、「HelloMBean」を表示/管理できます。また、を介してメソッドを呼び出すこともできますcom.ibm.websphere.management.AdminClient
。テストリスナークラスを作成しました。
/**
* Inner class that will handle the notifications.
*/
public static class ClientListener implements NotificationListener {
public void handleNotification(Notification notification, Object handback) {
RasMessage rasMessage = (RasMessage) notification.getUserData();
System.out.println("Localized message: " + rasMessage.getLocalizedMessage(null));
System.out.println("\nReceived notification:");
System.out.println("\tClassName: " + notification.getClass().getName());
System.out.println("\tSource: " + notification.getSource());
System.out.println("\tType: " + notification.getType());
System.out.println("\tMessage: " + notification.getMessage());
if (notification instanceof AttributeChangeNotification) {
AttributeChangeNotification acn = (AttributeChangeNotification) notification;
System.out.println("\tAttributeName: " + acn.getAttributeName());
System.out.println("\tAttributeType: " + acn.getAttributeType());
System.out.println("\tNewValue: " + acn.getNewValue());
System.out.println("\tOldValue: " + acn.getOldValue());
}
}
}
私が取るステップは次のとおりです。
- MBeanを作成する
- MBeanを登録します(コンソールで確認できます)。
- 次に、正しいObjectNameを使用して、通知リスナーを3つの異なる方法で追加しようとします。
これらはすべて、MBeanでaddNotificationListenerを呼び出すことはありません
ClientListener listener = new ClientListener();
adminClient.addNotificationListenerExtended(objectName, listener, null, null);
adminClient.addNotificationListener(objectName, listener, null, null);
AdminServiceFactory.getMBeanFactory().getMBeanServer().addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, null, null);
次に、通知を送信するMBeanのメソッドを呼び出します。
問題は、NotificationBroadcasterSupport.sendNotification()で、このMBeanのリスナーリストにリスナーがないことです。
前の手順で追加しようとすると、mbeanの'addNotificationListener()'メソッドが呼び出されるはずですが、呼び出されることはありません。
何かご意見は?
また、手動で追加しようとしていますが、これも機能していません。
//インターフェース
public interface HelloMBean extends TUFMBean {
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback);
public abstract String getName();
public abstract int getCacheSize();
public abstract void setCacheSize(int size);
public abstract void sayHello();
public abstract int add(int x, int y);
public abstract MBeanNotificationInfo[] getNotificationInfo();
public String getIdentification();
public void initialize(Object paramObject);
}
// impl:
package cat.dcs.core.services.mbean;
import javax.management.AttributeChangeNotification;
import javax.management.MBeanNotificationInfo;
import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import junitx.util.PrivateAccessor;
public class HelloNotificationImpl extends NotificationBroadcasterSupport implements HelloMBean {
private String name = "HelloMBean";
private int cacheSize = DEFAULT_CACHE_SIZE;
private static final int DEFAULT_CACHE_SIZE = 200;
private long sequenceNumber = 1;
public HelloNotificationImpl() {
System.out.println(">>>>> CONSTRUCTOR " + this);
}
/*
* ***************************************************
* TUFMBeanImpl req's
* ***************************************************
*/
public HelloNotificationImpl(String paramString) {
setIdentification(paramString);
}
private void setIdentification(String paramString) {
name = paramString;
}
@Override
public String getIdentification() {
System.out.println(">>>>> getIdentification " + this);
return name;
}
@Override
public void initialize(Object paramObject) {
System.out.println(">>>>> INIT "+ this);
}
@Override
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) {
System.out.println(">>>>> ADD NOTIFICATION LISTENER " + this);
super.addNotificationListener(listener, filter, handback);
try {
System.out.println(PrivateAccessor.getField(this, "listenerList"));
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
/*
* ***************************************************
* notification broadcaster use
* ***************************************************
*/
/**
* TODO Update method documentation for Hello.setCacheSize Description of the method.
*
* @param size
* @see cat.cis.junk.x#setCacheSize(int)
* @since 1.0 Jul 5, 2012 9:40:01 AM DudekTA
*/
public synchronized void setCacheSize(int size) {
System.out.println(">>>>> SET CACHE SIZE ON"+ this);
int oldSize = cacheSize;
cacheSize = size;
System.out.println("Cache size now " + cacheSize);
Notification n = new AttributeChangeNotification(this, sequenceNumber++, System.currentTimeMillis(),
"CacheSize changed", "CacheSize", "int", oldSize, cacheSize);
try {
System.out.println(">>>LISTENER LIST ON MBEAN: " + PrivateAccessor.getField(this, "listenerList"));
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
sendNotification(n);
}
/**
* TODO Update method documentation for Hello.getNotificationInfo Description of the method.
*
* @return
* @since 1.0 Jul 5, 2012 9:40:01 AM DudekTA
*/
@Override
public MBeanNotificationInfo[] getNotificationInfo() {
String[] types = new String[] { AttributeChangeNotification.ATTRIBUTE_CHANGE };
String name = AttributeChangeNotification.class.getName();
String description = "An attribute of this MBean has changed";
MBeanNotificationInfo info = new MBeanNotificationInfo(types, name, description);
return new MBeanNotificationInfo[] { info };
}
/*
* ***************************************************
* test methods
* ***************************************************
*/
/**
* TODO Update method documentation for Hello.sayHello Description of the method.
*
* @see cat.cis.junk.x#sayHello()
* @since 1.0 Jul 5, 2012 9:40:01 AM DudekTA
*/
public void sayHello() {
System.out.println("hello, world : " + this);
}
/**
* TODO Update method documentation for Hello.add Description of the method.
*
* @param x
* @param y
* @return
* @see cat.cis.junk.x#add(int, int)
* @since 1.0 Jul 5, 2012 9:40:01 AM DudekTA
*/
public int add(int x, int y) {
return x + y;
}
/**
* TODO Update method documentation for Hello.getName Description of the method.
*
* @return
* @see cat.cis.junk.x#getName()
* @since 1.0 Jul 5, 2012 9:40:01 AM DudekTA
*/
public String getName() {
return name;
}
/**
* TODO Update method documentation for Hello.getCacheSize Description of the method.
*
* @return
* @see cat.cis.junk.x#getCacheSize()
* @since 1.0 Jul 5, 2012 9:40:01 AM DudekTA
*/
public int getCacheSize() {
return cacheSize;
}
}
ところでこれも機能していません:
adminClient.invoke(objectName,"addNotificationListener" ,new Object[]{listener,null, null},new String[]{ "javax.management.NotificationListener","javax.management.NotificationFilter", "java.lang.Object" });
XMLの追加:
<?xml version="1.0" encoding="UTF-8"?>
<attribute name="name" getMethod="getName" type="java.lang.String"
proxyInvokeType="unicall" />
<attribute name="cacheSize" getMethod="getCacheSize" type="int"
setMethod="setCacheSize" proxyInvokeType="unicall" />
<operation name="sayHello" role="operation" type="void"
targetObjectType="objectReference" impact="ACTION" proxyInvokeType="multicall">
<signature>
</signature>
</operation>
<operation name="add" role="operation" type="int"
targetObjectType="objectReference" impact="ACTION" proxyInvokeType="multicall">
<signature>
<parameter name="x" description="x" type="int" />
<parameter name="y" description="x" type="int" />
</signature>
</operation>
<operation name="getNotificationInfo" role="operation" type="javax.management.MBeanNotificationInfo[]"
targetObjectType="objectReference" impact="ACTION" proxyInvokeType="multicall">
<signature>
</signature>
</operation>
<operation name="addNotificationListener" role="operation" type="void"
targetObjectType="objectReference" impact="ACTION" proxyInvokeType="multicall">
<signature>
<!-- javax.management.NotificationListener","javax.management.NotificationFilter", "java.lang.Object -->
<parameter name="listener" description="javax.management.NotificationListener" type="javax.management.NotificationListener" />
<parameter name="filter" description="javax.management.NotificationFilter" type="javax.management.NotificationFilter" />
<parameter name="handback" description="java.lang.Object" type="java.lang.Object" />
</signature>
</operation>
手順の基本的な概要:
[7/9/12 10:28:08:813 CDT] 00000017 SystemOut O >>>>> CONSTRUCTOR cat.dcs.core.services.mbean.HelloNotificationImpl@7f4c7f4c
[7/9/12 10:28:08:813 CDT] 00000017 SystemOut O >>>>> INIT cat.dcs.core.services.mbean.HelloNotificationImpl@7f4c7f4c
[7/9/12 10:28:08:813 CDT] 00000017 SystemOut O >>>>> getIdentification cat.dcs.core.services.mbean.HelloNotificationImpl@7f4c7f4c
[7/9/12 10:28:08:820 CDT] 00000017 servlet I com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0242I: [TestItEAR] [/TestIt] [TUFMBeanInitializerServlet]: Initialization successful.
[7/9/12 10:28:08:824 CDT] 00000017 SystemOut O O1: [WebSphere:name=TestItEAR/TestIt.war/HelloMBean,TUFimpl=cat.dcs.core.services.mbean.HelloNotificationImpl,process=server1,TUFinterface=cat.dcs.core.services.mbean.HelloMBean,TUFtype=APPMBean,platform=dynamicproxy,node=C001460186Node02,version=7.0.0.17,type=HelloMBean,mbeanIdentifier=TestItEAR/TestIt.war/HelloMBean,cell=C001460186Node02Cell,spec=1.0]
[7/9/12 10:28:08:826 CDT] 00000017 SystemOut O >>>>> TRYING TO ADD LISTENER
[7/9/12 10:28:08:826 CDT] 00000017 SystemOut O hello, world : cat.dcs.core.services.mbean.HelloNotificationImpl@7f4c7f4c
[7/9/12 10:28:08:827 CDT] 00000017 SystemOut O >>>> CALLING METHOD WITH NOTIFICATION
[7/9/12 10:28:08:827 CDT] 00000017 SystemOut O >>>>> SET CACHE SIZE ONcat.dcs.core.services.mbean.HelloNotificationImpl@7f4c7f4c
[7/9/12 10:28:08:827 CDT] 00000017 SystemOut O Cache size now 999
[7/9/12 10:28:08:829 CDT] 00000017 SystemOut O >>>LISTENER LIST ON MBEAN: []
sendNotificationが呼び出されると、リスナーはありません。
@ニコラス:これが違いを生むかどうかわからない?
[7/9/12 14:00:48:811 CDT] 00000012 SystemOut O >>>>> AC CLASSLOADER IS:
org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@3ae03ae [7/9/12 14:00:48:812 CDT] 00000012 SystemOut O O1:[WebSphere:name = TestItEAR / TestIt.war / HelloMBean、TUFimpl=cat。 dcs.core.services.mbean.HelloNotificationImpl、process = server1、TUFinterface = cat.dcs.core.services.mbean.HelloMBean、TUFtype = APPMBean、platform = dynamicproxy、node = C001460186Node02、version = 7.0.0.17、type = HelloMBean、 mbeanIdentifier = TestItEAR / TestIt.war / HelloMBean、cell = C001460186Node02Cell、spec = 1.0] [7/9/12 14:00:48:814 CDT] 00000012 SystemOut O >>>>>以下のこのmbeanにリスナーを追加しようとしています: [7/9/12 14:00:48:814 CDT] 00000012 SystemOutこんにちは、世界:cat.dcs.core.services.mbean.HelloNotificationImpl@36c436c4 [7/9/12 14:00:48:814 CDT] 00000012 SystemOut O>>>>>私のクラスローダーはcom.ibm.ws.classloaderです。CompoundClassLoader@586a586a [war:TestItEAR / TestIt.war]ローカルクラスパス:C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ classes; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ commons-beanutils-1.7 .0.jar; C:\ワークスペース\TestIt \ WebContent \ WEB-INF \ lib \ commons-codec-1.4.jar; C:\workspace \ TestIt \ WebContent \ WEB-INF \ lib \commons-collections-3.2.1 .jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ commons-discovery-0.2.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ commons-fileupload-1.2.1.jar ; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ commons-httpclient-3.1.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ commons-io-1.4.jar; C:\ワークスペース\TestIt\ WebContent \ WEB-INF \ lib \ commons-lang-2.4.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ commons-logging-1.1.1.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ commons-logging-adapters-1.1.1.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ commons-logging-api-1.1.1.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ commons-net-1.4.1.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ jgl.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ junit-addons-1.4.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-common.jar; C:\ワークスペース\TestIt \ WebContent \ WEB-INF \ lib \ tuf-mbeans.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf -server.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-web.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-webservices.jar; C:\ワークスペース\TestIt\ WebContent親:com.ibm.ws.classloader.CompoundClassLoader@56cb56cb [app:TestItEAR]jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-common.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-mbeans.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-server.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-web.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-webservices.jar; C:\ worksheet \ TestIt \ WebContent親:com.ibm.ws.classloader.CompoundClassLoader@56cb56cb [app:TestItEAR]jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-common.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-mbeans.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-server.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-web.jar; C:\ worksheet \ TestIt \ WebContent \ WEB-INF \ lib \ tuf-webservices.jar; C:\ worksheet \ TestIt \ WebContent親:com.ibm.ws.classloader.CompoundClassLoader@56cb56cb [app:TestItEAR]
委任モード:PARENT_FIRST
mbeanのクラスローダーと管理クライアントはどこが違うのですか?:おそらく読みやすい: