[weld-dev] Passivating Capabilities check.

Mark Struberg struberg at yahoo.de
Wed Feb 17 03:17:22 EST 2010


Imo EJB's @PrePassivate and @PostActivate is only needed because they have a bit different Serialization handling. Those annotations shall get called on EJB's of course, but are not necessary for CDI managed contextual instances.
If we need to serialize, we don't do this via annotations but simply with writeObject and readObject if the bean is Serializable and of a passivating Scope. 

If we e.g. have a @ApplicationScoped bean which got injected into a @ViewScoped contextual instance (used to get serialized to the client after every request), then we have a proxy which serializes the Contextual<T> by simply using it's passivating id. See:

public String PassivationCapable#getId(); 
for serialization and

public Bean<?> BeanManager#getPassivationCapableBean(String id);
for restoring it again.

All the logic is hidden in a Wrapper over Bean<T> (in OWB this is in SerializableBean<T>) resp in the proxy for those NormalScoped beans.

LieGrue,
strub


--- Sven Linstaedt <sven.linstaedt at googlemail.com> schrieb am Mi, 17.2.2010:

> Von: Sven Linstaedt <sven.linstaedt at googlemail.com>
> Betreff: Re: [weld-dev] Passivating Capabilities check.
> An: "Mark Struberg" <struberg at yahoo.de>
> CC: "Pete Muir" <pmuir at redhat.com>, weld-dev at lists.jboss.org
> Datum: Mittwoch, 17. Februar, 2010 01:13 Uhr
> Hi Mark,
> 
> so if the Logger is not serializable, but insteads gets
> reinjected (and therefore recreated?) after deserialization
> of the owning bean, what lifecycle has the Logger bean? IMHO
> it would only make sense to destroy the logger, if it is not
> serialized with the owning bean. Currently the @Dependent
> scoped bean inherits the lifespan of the owning bean.
> 
> 
> In addition... do you have any clue if there is a CDI
> counterpart for EJB's @PrePassivate and @PostActivate
> handles?
> 
> br, Sven
> 
> 
> 2010/2/16 Mark Struberg <struberg at yahoo.de>
> 
> > I think you
> must use a proxy.
> 
> 
> 
> But 'you' means the programmer of the
> application has to do this manually and not the container,
> isn't?
> 
> 
> 
> Supporting static injection would really be cool in this
> case!
> 
> Or supporting re-injection after re-activation (would be
> more difficult I guess).
> 
> 
> 
> LieGrue,
> 
> strub
> 
> 
> 
> 
> 
> --- Pete Muir <pmuir at redhat.com>
> schrieb am Di, 16.2.2010:
> 
> 
> 
> > Von: Pete Muir <pmuir at redhat.com>
> 
> > Betreff: Re: [weld-dev] Passivating Capabilities
> check.
> 
> > An: "Mark Struberg" <struberg at yahoo.de>
> 
> > CC: weld-dev at lists.jboss.org
> 
> > Datum: Dienstag, 16. Februar, 2010 12:40 Uhr
> 
> >
> 
> > On 16 Feb 2010, at 10:11, Mark Struberg wrote:
> 
> >
> 
> > > Hi!
> 
> > >
> 
> > > I'm just curious how Weld manages to inject a
> Logger
> 
> > into a @SessionScoped (passivating!) bean.
> 
> > >
> 
> > > In your example in 1.3.5 you wrote:
> 
> > >
> 
> > >> class Loggers {
> 
> > >>   @Produces Logger
> 
> > getLogger(InjectionPoint injectionPoint) {
> 
> > >>       return
> 
> >
> Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getSimpleName()
> 
> > );
> 
> > >>   }
> 
> > >> }
> 
> > >
> 
> > > and
> 
> > >> @SessionScoped
> 
> > >> public class Permissions implements
> Serializable
> 
> > {
> 
> > >>   @Inject Logger log;
> 
> > >> ...
> 
> > >
> 
> > > but the Logger I know are actually not
> Serializable
> 
> > themselfs and since it is @Dependent scoped, we also
> don't
> 
> > use a proxy for it.
> 
> >
> 
> > I think you must use a proxy.
> 
> >
> 
> > >
> 
> > > I'd expected a DeploymentException thrown at
> startup
> 
> > in this case, but Weld actually seems to only checks
> 
> > passivation stuff for NormalBeans. Anyway, once the
> session
> 
> > get's passivated, you'll see a fine
> 
> > NotSerializableException.
> 
> >
> 
> > Well, the passivation capability is checked (of
> 
> > Permissions), which includes checking whether the
> producer
> 
> > method is passivation capable (it is, even though
> Logger
> 
> > isn't serializable, it also isn't final, so
> you might return
> 
> > a serializable subclass).
> 
> >
> 
> > I would however expect Weld to throw an
> 
> > IllegalProductException - I wrote this test which
> shows it
> 
> > does :-)
> 
> >
> 
> > http://fisheye.jboss.org/browse/weld/core/trunk/tests/src/test/java/org/jboss/weld/tests/serialization/SerializationTest.java?r=5841#l45
> 
> 
> 
> 
> __________________________________________________
> 
> Do You Yahoo!?
> 
> Sie sind Spam leid? Yahoo! Mail verfügt über einen
> herausragenden Schutz gegen Massenmails.
> 
> http://mail.yahoo.com
> 
> 
> 
> _______________________________________________
> 
> weld-dev mailing
> list
> 
> weld-dev at lists.jboss.org
> 
> https://lists.jboss.org/mailman/listinfo/weld-dev
> 
> 
> 
> 

__________________________________________________
Do You Yahoo!?
Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails. 
http://mail.yahoo.com 



More information about the weld-dev mailing list