Error creating MBeanProxy when using @Depends
mbarker Jun 12, 2007 1:11 PMI used a Trailblazer tutorial as the basis for my example.
http://trailblazer.demo.jboss.com/EJB3Trail/serviceobjects/jmx/index.html
The managment interfaces are Calculator and InvestmentAdvisor. The MBeans are CalculatorMBean and InvestmentAdvisorMBean. I want to inject Calculator into my other MBean, InvestmentAdvisorMBean. I receive an MBeanProxy error when deploying on JBoss 4.2.0.GA.
[EJBContainer] STARTED EJB: com.csg.mpg.service.CalculatorMBean ejbName: CalculatorMBean
[STDOUT] Calculator - Creating
[JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.service.ServiceContainer
[JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=mpg-ejbs-1.0.0-SNAPSHOT.jar,name=InvestmentAdvisorMBean,service=EJB3 with dependencies:
[JmxKernelAbstraction] trail:service=calculator
[EJBContainer] STARTED EJB: com.csg.mpg.service.InvestmentAdvisorMBean ejbName: InvestmentAdvisorMBean
[STDERR] java.lang.RuntimeException: Error creating MBeanProxy: trail:service=calculator
[STDERR] at org.jboss.mx.util.MBeanProxyExt.init(MBeanProxyExt.java:415)
[STDERR] at org.jboss.mx.util.MBeanProxyExt.(MBeanProxyExt.java:99)
[STDERR] at org.jboss.mx.util.MBeanProxyExt.create(MBeanProxyExt.java:394)
[STDERR] at org.jboss.mx.util.MBeanProxyExt.create(MBeanProxyExt.java:349)
I'd prefer to stick with the following because I can call calculator.calculate
directly.
@Depends ("trail:service=calculator")
public void setCalculator (Calculator calculator) {
this.calculator = calculator;
}
but I discovered that the following works
@Depends ("trail:service=calculator")
private ObjectName calculatorName;
It is clumsy since I have to loop through the various mbean servers (I have
two for some reason) in order get the mbean and then call invoke.
Any thoughts on what I am missing?
Here are my classes
public interface Calculator { // Attribute public void setGrowthrate(double g); public double getGrowthrate(); // The management method public double calculate(int start, int end, double saving); // Life cycle method public void create() throws Exception; public void destroy() throws Exception; }
@Service(objectName = "trail:service=calculator") @Management(Calculator.class) public class CalculatorMBean implements Calculator { double growthrate; public void setGrowthrate(double growthrate) { this.growthrate = growthrate; } public double getGrowthrate() { return growthrate; } public double calculate(int start, int end, double saving) { double tmp = Math.pow(1. + growthrate / 12., 12. * (end - start) + 1); return saving * 12. * (tmp - 1) / growthrate; } // Lifecycle methods public void create() throws Exception { growthrate = 0.08; System.out.println("Calculator - Creating"); } public void destroy() { System.out.println("Calculator - Destroying"); } }
public interface InvestmentAdvisor { // The management method public void advise(); // Life cycle method public void create() throws Exception; public void destroy() throws Exception; }
@Service (objectName="trail:service=investmentAdvisor") @Management(InvestmentAdvisor.class) public class InvestmentAdvisorMBean implements InvestmentAdvisor { private Calculator calculator; @Depends ("trail:service=calculator") public void setCalculator (Calculator calculator) { this.calculator = calculator; } public void create() throws Exception { System.out.println("InvestmentAdvisorMBean created"); } public void destroy() throws Exception { System.out.println("InvestmentAdvisorMBean destroyed"); } public void advise() { System.out.println("InvestmentAdvisorMBean advising"); calculator.calculate(25, 65, 300); } }