myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pieter Martin <pieter.mar...@gmail.com>
Subject Re: @Disposes and webapp shutdown and @Singleton/@ApplicationScope
Date Fri, 08 Jul 2011 07:33:50 GMT
@ApplicationScoped hence forth it is.
Thanks
Pieter

On 08/07/2011 09:31, Gerhard Petracek wrote:
> hi pieter,
>
> in the end you have to shutdown one of both scopes first. if you change the
> behaviour, you would have a problem the other way round.
> please always use @ApplicationScoped instead of @Singleton (in terms of cdi
> @Singleton isn't specified very clearly - it's part of jsr 330 which doesn't
> say a lot about it).
>
> regards,
> gerhard
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
>
>
> 2011/7/8 Pieter Martin<pieter.martin@gmail.com>
>
>> Hi,
>>
>> I have an application scoped producer method together with a disposer which
>> sits in a @javax.inject.Singleton scoped class.
>>
>> @Singleton
>> public class DbProducer implements Serializable {
>>     @ApplicationScopedDb
>>     @Produces
>>     @ApplicationScoped
>>     public NakedGraph getApplicationScopedNakedGraph**() {
>>         logger.info("produce Application scoped db");
>>         NakedGraph db = createNakedGraph();
>>         return db;
>>     }
>>
>>     public void closeApplicationScoped(@**Disposes @ApplicationScopedDb
>> NakedGraph db) {
>>         logger.info("shutdown Application scoped db");
>>         if (db != null) {
>>             db.shutdown();
>>         }
>>     }
>> }
>>
>> On shutting down jetty I get the following exception.
>>
>> SEVERE: Exception thrown while destroying bean instance :
>> [Name:null,WebBeans Type:PRODUCERMETHOD,API Types:[com.tinkerpop.**
>> blueprints.pgm.Graph,java.io.**Serializable,org.nakeduml.**
>> tinker.runtime.NakedGraph,com.**tinkerpop.blueprints.pgm.**
>> IndexableGraph,java.lang.**Object,com.tinkerpop.**blueprints.pgm.**
>> TransactionalGraph],**Qualifiers:[javax.enterprise.**
>> inject.Any,org.nakeduml.**tinker.runtime.**ApplicationScopedDb]]
>> java.lang.NullPointerException
>>     at org.apache.webbeans.component.**ProducerMethodBean.**disposeDefault(
>> **ProducerMethodBean.java:346)
>>     at org.apache.webbeans.component.**ProducerMethodBean.dispose(**
>> ProducerMethodBean.java:306)
>>     at org.apache.webbeans.component.**ProducerMethodBean.**
>> destroyInstance(**ProducerMethodBean.java:298)
>>     at org.apache.webbeans.component.**AbstractOwbBean.**
>> destroyCreatedInstance(**AbstractOwbBean.java:277)
>>     at org.apache.webbeans.portable.**creation.AbstractProducer.**
>> dispose(AbstractProducer.java:**91)
>>     at org.apache.webbeans.component.**InjectionTargetWrapper.**dispose(**
>> InjectionTargetWrapper.java:**116)
>>     at org.apache.webbeans.component.**AbstractOwbBean.destroy(**
>> AbstractOwbBean.java:242)
>>     at org.apache.webbeans.context.**AbstractContext.**destroyInstance(**
>> AbstractContext.java:257)
>>     at org.apache.webbeans.context.**AbstractContext.destroy(**
>> AbstractContext.java:279)
>>     at org.apache.webbeans.web.**context.WebContextsService.**
>> destroyApplicationContext(**WebContextsService.java:485)
>>     at org.apache.webbeans.web.**context.WebContextsService.**
>> endContext(WebContextsService.**java:200)
>>     at org.apache.webbeans.web.**context.WebContextsService.**
>> destroy(WebContextsService.**java:155)
>>     at org.apache.webbeans.lifecycle.**AbstractLifeCycle.**stopApplication(
>> **AbstractLifeCycle.java:149)
>>     at org.apache.webbeans.web.**lifecycle.**WebContainerLifecycle.**
>> stopApplication(**WebContainerLifecycle.java:87)
>>     at org.apache.webbeans.servlet.**WebBeansConfigurationListener.**
>> contextDestroyed(**WebBeansConfigurationListener.**java:96)
>>     at org.eclipse.jetty.server.**handler.ContextHandler.doStop(**
>> ContextHandler.java:679)
>>     at org.eclipse.jetty.servlet.**ServletContextHandler.doStop(**
>> ServletContextHandler.java:**143)
>>     at org.eclipse.jetty.webapp.**WebAppContext.doStop(**
>> WebAppContext.java:473)
>>     at org.eclipse.jetty.util.**component.AbstractLifeCycle.**
>> stop(AbstractLifeCycle.java:**83)
>>     at org.eclipse.jetty.server.**handler.HandlerCollection.**
>> doStop(HandlerCollection.java:**245)
>>     at org.eclipse.jetty.util.**component.AbstractLifeCycle.**
>> stop(AbstractLifeCycle.java:**83)
>>     at org.eclipse.jetty.server.**handler.HandlerWrapper.doStop(**
>> HandlerWrapper.java:101)
>>     at org.eclipse.jetty.server.**Server.doStop(Server.java:319)
>>     at org.eclipse.jetty.util.**component.AbstractLifeCycle.**
>> stop(AbstractLifeCycle.java:**83)
>>     at org.nakeduml.jetty.StartJetty$**MonitorThread.run(StartJetty.**
>> java:92)
>>
>>
>> Some investigation shows that the base exception is a
>>
>> "new ContextNotActiveException("**WebBeans context with scope type
>> annotation @" + scopeType.getSimpleName() + " does not exist within current
>> thread");"
>>
>> This exception however gets swallowed by the above exception that is thrown
>> in the finally part of ProducerMethodBean.**disposeDefault.
>> The scope that is not active is javax.inject.Singleton
>>
>> I subsequently replaced @Singleton with @ApplicationScope and then
>> everything works.
>>
>> Should @Singleton also have worked and when should one use which
>> annotation?
>>
>> Thanks
>> Pieter
>>


Mime
View raw message