deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Porter <lightguard...@gmail.com>
Subject Re: problem trying to use DeltaSpike JMX annotations in a standalone main application
Date Fri, 26 Sep 2014 17:19:00 GMT
The problem is probably (as I understand your explanation) is that your
beans are registered as @RequestScope and they're also JMX beans. Accessing
a JMX bean through Jconsole will not activate an http request (which in a
container starts the scope) in a container. Now doing this within a main
method and manually starting the scopes will probably work, however, once
the request is finished, CDI should be destroying all beans in that scope,
which would destroy your JMX bean.

Is your JMX bean annotated @RequestScoped or @ApplicationScoped and you're
just injecting something that's request scoped?

On Fri, Sep 26, 2014 at 11:10 AM, Pablo Pita <pablo.pita@gmail.com> wrote:

> My original idea was to emulate a normal Java application with a main
> method using Weld version for Java SE as CDI container. There, I would
> bootstrap the CDI container, and voila, the CDI JMX beans should be
> registered by DeltaSpike infrastructure.
>
> Running unit tests with the @RunWith(CdiTestRunner.class) works (no
> deployment to JBoss, or Arquillian, just Weld SE in the test class path).
> As well, the JMX registration works OK when deploying the application to
> JBoss. I can work with the JMX Console with the JMX beans.
>
> So the code for a normal main method bootstraping the CDI Container is not
> that simple, is it?
>
> Pablo
>
>
>
> On Fri, Sep 26, 2014 at 6:43 PM, Jason Porter <lightguard.jp@gmail.com>
> wrote:
>
> > Pablo,
> >
> > Does your code, looks like it's a test, start and register the MBean? Are
> > you accessing the MBeam from a running JBoss AS7 instance or something? I
> > feel like I'm missing some information.
> >
> > The cause is that the Request scope isn't active when you're accessing
> the
> > MBean.
> >
> > On Fri, Sep 26, 2014 at 3:46 AM, Pablo Pita <pablo.pita@gmail.com>
> wrote:
> >
> > > Hello all,
> > >
> > > I am having a problem trying to use DeltaSpike JMX annotations in a
> > > standalone main application.
> > >
> > > For my tests, I have taken MyMBean from DS sources. When looking into
> the
> > > JMX console JConsole, I see that MyMBean is registered but when trying
> to
> > > access the counter attribute, this exception comes:
> > >
> > > 26.09.2014 11:18:20
> > > org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper
> > > getAttribute
> > > SCHWERWIEGEND: can't get counter value
> > > java.lang.reflect.InvocationTargetException
> > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > >     at
> > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > >     at
> > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > >     at
> > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.AttributeAccessor.get(AttributeAccessor.java:46)
> > >     at
> > >
> > >
> >
> org.apache.deltaspike.core.impl.jmx.DynamicMBeanWrapper.getAttribute(DynamicMBeanWrapper.java:249)
> > >     at
> > >
> > >
> >
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:666)
> > >     at
> > >
> > >
> >
> com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1431)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
> > >     at
> > >
> > >
> >
> javax.management.remote.rmi.RMIConnectionImpl.getAttribute(RMIConnectionImpl.java:630)
> > >     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > >     at
> > >
> > >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > >     at
> > >
> > >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > >     at java.lang.reflect.Method.invoke(Method.java:597)
> > >     at
> > sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
> > >     at sun.rmi.transport.Transport$1.run(Transport.java:159)
> > >     at java.security.AccessController.doPrivileged(Native Method)
> > >     at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
> > >     at
> > >
> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
> > >     at
> > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
> > >     at
> > >
> > >
> >
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
> > >     at
> > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
> > >     at
> > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
> > >     at java.lang.Thread.run(Thread.java:662)
> > > Caused by: org.jboss.weld.context.ContextNotActiveException:
> WELD-001303
> > No
> > > active contexts for scope type javax.enterprise.context.RequestScoped
> > >     at
> > >
> >
> org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:608)
> > >     at
> > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
> > >     at
> > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104)
> > >     at
> > >
> > >
> >
> org.jboss.weld.proxies.DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.getMock(DynamicMockManager$-427240798$Proxy$_$$_WeldClientProxy.java)
> > >     at
> > >
> > >
> >
> org.apache.deltaspike.testcontrol.impl.mock.MockAwareInjectionTargetWrapper.produce(MockAwareInjectionTargetWrapper.java:59)
> > >     at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:296)
> > >     at
> > org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
> > >     at
> > >
> > >
> >
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90)
> > >     at
> > >
> > >
> >
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
> > >     at
> > >
> > >
> >
> com.jmx.ds.MyMBean$Proxy$_$$_WeldClientProxy.getCounter(MyMBean$Proxy$_$$_WeldClientProxy.java)
> > >     ... 27 more
> > >
> > > I wonder if there is something I am missing to properly setup this
> case.
> > I
> > > am on Windows running JDK 6 and Weld 1.1.18.
> > >
> > >
> > > The main program I am using is as follows:
> > >
> > >     public static void main(String[] args) throws Exception {
> > >
> > >         CdiContainer cdiContainer =
> CdiContainerLoader.getCdiContainer();
> > >         cdiContainer.boot();
> > >
> > >         // Starting the application-context and request-context allows
> to
> > > use
> > >         // @ApplicationScoped and @RequestScoped beans
> > >         ContextControl contextControl =
> cdiContainer.getContextControl();
> > >         contextControl.startContext(ApplicationScoped.class);
> > >         contextControl.startContext(RequestScoped.class);
> > >
> > >         // we can use CDI here
> > >          while (running) {
> > >             int i = 0;
> > >             i = i + 1;
> > >             Thread.sleep(50);
> > >         }
> > >         cdiContainer.shutdown();
> > >     }
> > >
> > > Thanks for any feedback,
> > > --
> > > Pablo Pita Leira
> > >
> >
> >
> >
> > --
> > Jason Porter
> > http://en.gravatar.com/lightguardjp
> >
>
>
>
> --
> Pablo Pita Leira
>



-- 
Jason Porter
http://en.gravatar.com/lightguardjp

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message