An MBean invoke another MBean
nusa May 12, 2004 7:43 AMHi all,
I'm using JBOSS3.2.4RC2.
I have an MBean A which depends on MBean B and MBean C, as defined in my jboss-service.xml :
...
<!--
| A depend on B and C
-->
<depends optional-attribute-name="BManager">nusa:service=B
<depends optional-attribute-name="CManager">nusa:service=C
<!--
| BMBean
-->
false
<!--
| CBMBean
-->
false
...
A, B, and C has the usual getter/setter method.
If a method within A calls a method in B, as shown below :
...
public ObjectName getBManager() {
return this.bManager;
}
public void setBManager(ObjectName obj) {
this.bManager = obj;
}
...
public void methodA1() {
try {
log.info("=== A.methodA1() invoke methodB1() ");
server.invoke(bManager ,"methodB1" ,null ,null);
} catch ( Exception e) {
log.debug( "=== Exception in A.methodA1 : " + e);
}
}
public void methodA2(String s) {
try {
log.info("=== A.methodA2() invoke methodB2() ");
Object[] params = new Object[] { s };
String[] signature = new String[] { "java.lang.String" };
server.invoke ( bManager, "methodB2", params, signature );
} catch ( Exception e) {
log.debug( "=== Exception in A.methodA2 : " + e);
}
}
...
and the methods in B are :
...
public void methodB1() {
log.info("=== B.methodB1()");
}
public void methodB2(String s) {
log.info("=== B.methodB2() : " + s);
}
...
I got this error :
...
10:26:36,849 INFO [example.jmx.A] === A.startService()
10:26:36,849 INFO [example.jmx.A] === A.methodA1()
10:26:36,849 DEBUG [example.jmx.A] === Exception in A.methodA1 : ReflectionException: null
Cause: java.lang.IllegalArgumentException: Unable to find operation methodB1()
10:26:36,849 INFO [example.jmx.A] === A.methodA2()
10:26:36,849 DEBUG [example.jmx.A] === Exception in A.methodA2 : ReflectionException: null
Cause: java.lang.IllegalArgumentException: Unable to find operation methodB2(java.lang.String)
...
How to use invoke ? What's wrong with the syntax above ?
The C class has a method which return an instance of C :
...
public Object getInstance() {
return this;
}
...
If a method within A calls a method in C, as shown below :
...
public ObjectName getCManager() {
return this.cManager;
}
public void setCManager(ObjectName obj) {
this.cManager = obj;
}
...
public void methodA1() {
try {
log.info("=== A.methodA1() invoke methodC1() ");
C obj = (C)server.getAttribute(cManager ,"Instance");
obj.methodC1();
} catch ( Exception e) {
log.debug( "=== Exception in A.methodA1 : " + e);
}
}
public void methodA2(String s) {
try {
log.info("=== A.methodA2() invoke methodC2() ");
C obj = (C)server.getAttribute(cManager ,"Instance");
obj.methodC2(s);
} catch ( Exception e) {
log.debug( "=== Exception in A.methodA2 : " + e);
}
}
...
I got this error :
...
12:08:28,634 INFO [example.jmx.A] === A.startService()
12:08:28,634 INFO [example.jmx.A] === A.methodA1() invoke methodC1()
12:08:28,634 DEBUG [example.jmx.A] === Exception in A.methodA1 : javax.management.AttributeNotFoundException: not found: Instance
12:08:28,634 INFO [example.jmx.A] === A.methodA2() invoke methodC2()
12:08:28,634 DEBUG [example.jmx.A] === Exception in A.methodA2 : javax.management.AttributeNotFoundException: not found: Instance
...
Any idea why the getInstance() in C is not recognize ?
Thanks for any help/suggestion.