-
1. Re: @Management in JBoss 6: don't works ?
vandfr Apr 1, 2011 11:45 AM (in response to vandfr)The workaround I found -> programmaticaly register an MBean in the JBoss MBean server
package com.sample;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.jboss.mx.util.MBeanServerLocator;
@Singleton
@Startup
public class HelloWorld implements HelloWorldMBean {
@PostConstruct
public void start() {
System.out.println(">>> HelloWorld bean starts <<<");
MBeanServer server = MBeanServerLocator.locateJBoss();
try {
ObjectName name = new ObjectName("HelloWorld:agent=MyHelloWorldBean");
server.registerMBean(this, name);
} catch (Exception e) {
e.printStackTrace();
}
}
public String displayHelloWorld() {
return "HelloWorld";
}
}
---------------------------------
package com.sample;
public interface HelloWorldMBean {
String displayHelloWorld();
}
And then it works(around):
-
2. @Management in JBoss 6: don't works ?
jaikiran Apr 4, 2011 2:59 AM (in response to vandfr)JBoss specific @Management is not supported with Java EE6 specified @Singleton.
-
3. @Management in JBoss 6: don't works ?
vandfr Apr 4, 2011 4:35 AM (in response to jaikiran)OK.
That's what I feared.
So how can I suppress the JBoss specific "@Service" by the new standard annotation "@Singleton",
if I lose the benefit of the JBoss specific @Management annotation.
Don't you that it can be reported as a bug in JBoss 6.0 ?
-
4. @Management in JBoss 6: don't work ?
jaikiran Apr 4, 2011 4:46 AM (in response to vandfr)Laurent Vandwalle wrote:
So how can I suppress the JBoss specific "@Service" by the new standard annotation "@Singleton",
if I lose the benefit of the JBoss specific @Management annotation.
Currently there's no inbuilt way of doing this. As you found, you can do it yourself via some code.
Laurent Vandwalle wrote:
Don't you that it can be reported as a bug in JBoss 6.0 ?
@Management for @Singleton was never a planned feature. So it isn't a bug. If you want some similar functionality then that might be considered for the upcoming JBoss AS7 release. You'll have to file a feature request JIRA for the same.
-
5. @Management in JBoss 6: don't work ?
vandfr Apr 4, 2011 5:13 AM (in response to vandfr)OK Sorry.
I just found the new standard annotation "@ManagedBean" that seems to replace the JBoss specific annotation "@Management".
Thanks for your help.
-
6. @Management in JBoss 6: don't work ?
jaikiran Apr 5, 2011 2:53 AM (in response to vandfr)Laurent Vandwalle wrote:
I just found the new standard annotation "@ManagedBean" that seems to replace the JBoss specific annotation "@Management".
Actually @ManagedBean is not a replacement for JBoss specific @Management. Those are 2 completely different annotations with different semantics.
-
7. Re: @Management in JBoss 6: don't work ?
vandfr Apr 5, 2011 4:01 AM (in response to jaikiran)Actually @ManagedBean is not a replacement for JBoss specific @Management. Those are 2 completely different annotations with different semantics.
Yes, indeed.
@ManagedBean has nothing to do with JMX Management.
According to the JSR 316, it is for beans managed by the container.
So I will try another strategy: I will test if the "old" association of annotations "@Service + @Management" is still working under JBoss 6...
If not, I will use my workaround.
-
8. Re: @Management in JBoss 6: don't work ?
vandfr Apr 8, 2011 11:48 AM (in response to vandfr)Finally, I choose to keep the @Service annotation when used in association with @Management.
And I replaced @Service by @Singleton when it was possible (ie: when there was no @Management annotation).
Even if it is a workaround, it works well.
I have created a bug on JBoss 6.0 Final in order to signal that @Singleton + @Management don't work -> https://issues.jboss.org/browse/JBAS-9276
-
9. @Management in JBoss 6: don't work ?
javacoryd Apr 11, 2011 9:34 AM (in response to vandfr)Does this work in JBoss 6 Final? I've tried this and my @PostConstruct method never gets called on startup of the server.
Thanks,
Cory.
-
10. @Management in JBoss 6: don't work ?
vandfr Apr 11, 2011 9:57 AM (in response to javacoryd)Does this work in JBoss 6 Final? I've tried this and my @PostConstruct method never gets called on startup of the server.
What I have experienced with JBoss 6 Final:
- @Singleton bean (and his @PostConstruct and @PreDestroy methods) -> works (you can have look on the boot.log file in the first post of this discussion thread and see the log "[STDOUT] >>> HelloWorld bean starts <<<")
- @Service bean with @Management annotation -> works
- @Singleton bean with @Management annotation -> don't work (the JMX Management don't work but the behaviour of the @Singleton annotation is OK)
-
11. Re: @Management in JBoss 6: don't work ?
legae Jul 5, 2011 5:36 AM (in response to vandfr)In jboss 6.1 I have @Startup @Singleton class that need to be managable through jmx-console. So I did as it is suggested to register bean by hand. Registration is ok, but when I want to invoke method through jmx-console exception is thrown
package com.test.service; import java.util.Timer; import java.util.TimerTask; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.ejb.EJB; import javax.management.InstanceAlreadyExistsException; import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import org.jboss.mx.util.MBeanServerLocator; import com.test.bean.TestLocal; import com.test.util.StackTrace; @javax.ejb.Startup @javax.ejb.Singleton public class DependsService implements DependsServiceMBean { @EJB TestLocal tl; private Timer timer = null; private static final int delay = 10000; @PostConstruct public void create() { StackTrace.info(this, "create: ", tl); try { ObjectName name = new ObjectName("logic:service=DependsService"); try { MBeanServer server = MBeanServerLocator.locateJBoss(); server.registerMBean(this, name); }catch (InstanceAlreadyExistsException e) { StackTrace.debug(this, "instance alreay registered"); } catch (Exception e) { StackTrace.error(this, "locateJboss: ", e); } } catch (MalformedObjectNameException e) { StackTrace.error(this, "ObjectName: ", e); } start(); } public void start(){ timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { doIt(); } catch (Exception e) { StackTrace.error(e); } } }, 1000, DependsService.delay); } private void doIt() { tl.doSth(); } public void stop(){ StackTrace.info(this, "stop: ", tl); timer.cancel(); tl.doSth2(); } @PreDestroy public void destroy() { timer.cancel(); } }
package com.test.service; public interface DependsServiceMBean { public void start(); public void stop(); }
doSth() and doSth2() methods just print a message. When this service starts everything is ok. I see in jmx-console domain "logic" and both start and stop methods can be invoked. When I invoke "stop" method this is what I see in jboss logs
2011-07-05 11:05:56,331 INFO [com.test.service.DependsService] 37:DependsService#stop():stop: Proxy to jboss.j2ee:ear=SimpleTests.ear,jar=SimpleTests.jar,name=TestBean,service=EJB3 implementing [interface com.test.bean.TestLocal]
11:05:56,331 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/jmx-console].[HtmlAdaptor]] Servlet.service() for servlet HtmlAda
ptor threw exception: java.lang.ClassNotFoundException: com.test.bean.TestLocal
at java.net.URLClassLoader$1.run(URLClassLoader.java:202) [:1.6.0_21]
at java.security.AccessController.doPrivileged(Native Method) [:1.6.0_21]
at java.net.URLClassLoader.findClass(URLClassLoader.java:190) [:1.6.0_21]
at java.lang.ClassLoader.loadClass(ClassLoader.java:307) [:1.6.0_21]
at java.lang.ClassLoader.loadClass(ClassLoader.java:248) [:1.6.0_21]
at java.lang.Class.forName0(Native Method) [:1.6.0_21]
at java.lang.Class.forName(Class.java:247) [:1.6.0_21]
at org.jboss.ejb3.common.classloader.util.PrimitiveClassLoadingUtil.loadClass(PrimitiveClassLoadingUtil.java:99) [:]
at org.jboss.ejb3.common.lang.SerializableMethod.getClassFromName(SerializableMethod.java:307) [:1.0.2]
at org.jboss.ejb3.common.lang.SerializableMethod.getClassType(SerializableMethod.java:282) [:1.0.2]
at org.jboss.ejb3.common.lang.SerializableMethod.toMethod(SerializableMethod.java:233) [:1.0.2]
at org.jboss.ejb3.common.lang.SerializableMethod.toMethod(SerializableMethod.java:220) [:1.0.2]
at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:178) [:]
at $Proxy183.doSth2(Unknown Source) at com.test.service.DependsService.stop(DependsService.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_21]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_21]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_21]
at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_21]
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157) [:6.0.0.GA]
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96) [:6.0.0.GA]
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88) [:6.0.0.GA]
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:271) [:6.0.0.GA]
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:670) [:6.0.0.GA]
at org.jboss.jmx.adaptor.control.Server.invokeOpByName(Server.java:258) [:]
at org.jboss.jmx.adaptor.control.Server.invokeOp(Server.java:223) [:]
at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet$3.run(HtmlAdaptorServlet.java:380) [:]
at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet$3.run(HtmlAdaptorServlet.java:377) [:]
at java.security.AccessController.doPrivileged(Native Method) [:1.6.0_21]
at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.invokeOp(HtmlAdaptorServlet.java:376) [:]
at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.invokeOp(HtmlAdaptorServlet.java:287) [:]
at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.processRequest(HtmlAdaptorServlet.java:104) [:]
at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.doPost(HtmlAdaptorServlet.java:86) [:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:]
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0-SNAPSHOT]
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0-SNAPSHOT]
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0-SNAPSHOT]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:]
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0-SNAPSHOT]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:]
at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0-SNAPSHOT]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:]
at java.lang.Thread.run(Thread.java:619) [:1.6.0_21]
What is the reason of this ClassNotFoundException? Is there different class loading/classpath for jmx invoked methods? How can I fix my problem
-
12. Re: @Management in JBoss 6: don't work ?
ion_mayank May 30, 2016 4:13 AM (in response to legae)Hi Legae,
I am facing the same problem of ClassNotFoundException for EJB invocation from JMX. Did you got the solution for your problem?