You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openwebbeans.apache.org by Mark Struberg <st...@yahoo.de> on 2009/04/02 17:56:04 UTC

inventing a scope metric

Hi!

I'd like to write down a general idea about scopes and their interaction which (after a talk with Pete) I think is 'implicitely' defined in the JSR-299 spec.

1) If I inject a bean of a 'shorter' ranged scope into a bean with a 'longer' ranged scope, then we have to use a proxy object.

An example: We do need a proxy if an @SessionScoped bean has an @RequestScoped bean as a member, because for every request, the @RequestScoped bean member is different to the one from the previous request.

We do _not_ need to use a proxy if the scope of the injected member bean is 'equal' or 'longer' as the bean where it's a member of.

2.) Since the spec requires SessionScoped and ConversationScoped beans to be Serializable, those 2 have to be injected via proxies only.

Since JSR-299 gives anyone the possibility to write own Scopes, a simple hardcoded scope comparison matrix is not sufficient.
To work around this, we may introduce a simple list of metrics in our configuration, 1 for each known scope. Where a higher number means a longer lifetime of beans of a scope.

e.g.
scope.metric.RequestScoped=1
scope.metric.ConversationScoped=2
scope.metric.ApplicationScoped=3

If someone e.g. likes to introduce a WorkflowScoped (which typically is even longer than applications since they may be persisted into a database and last for years (kafkaesk indeed but possible)) it would get a metric of 4.
Another example: JSF has a 'FlashScoped' which would fit between RequestScoped and ConversationScoped ...

Open questions: 
a.) can there be 2 scopes which are 'equally' ?
b.) is a simple ordered (comma separated) list sufficient? 

WDYT? May we get this plugable enough?

LieGrue,
strub



      

Re: inventing a scope metric

Posted by Gurkan Erdogdu <gu...@yahoo.com>.
For the time being , proxy may be enough.

Sorry, I am so busy nowadays :)

Gurkan




________________________________
From: James Carman <jc...@carmanconsulting.com>
To: openwebbeans-dev@incubator.apache.org
Sent: Thursday, April 2, 2009 7:24:01 PM
Subject: Re: inventing a scope metric

I would suggest keeping proxies regardless of scope incompatibilities.
In Wicket, we use proxies for injected references because of
serialization issues (the pages/components are serialized out to
disk).  Most things that you're injecting aren't truly serializable
(like DAOs and stuff).  Now, we could re-inject dependencies upon
deserialization, but that doesn't solve the problem either.  Suppose a
component passes its directly-injected, non-proxied reference to some
other object that maintains that reference (a reference to a DAO for
instance).  Now, that object can't be serialized.


On Thu, Apr 2, 2009 at 11:56 AM, Mark Struberg <st...@yahoo.de> wrote:
>
> Hi!
>
> I'd like to write down a general idea about scopes and their interaction which (after a talk with Pete) I think is 'implicitely' defined in the JSR-299 spec.
>
> 1) If I inject a bean of a 'shorter' ranged scope into a bean with a 'longer' ranged scope, then we have to use a proxy object.
>
> An example: We do need a proxy if an @SessionScoped bean has an @RequestScoped bean as a member, because for every request, the @RequestScoped bean member is different to the one from the previous request.
>
> We do _not_ need to use a proxy if the scope of the injected member bean is 'equal' or 'longer' as the bean where it's a member of.
>
> 2.) Since the spec requires SessionScoped and ConversationScoped beans to be Serializable, those 2 have to be injected via proxies only.
>
> Since JSR-299 gives anyone the possibility to write own Scopes, a simple hardcoded scope comparison matrix is not sufficient.
> To work around this, we may introduce a simple list of metrics in our configuration, 1 for each known scope. Where a higher number means a longer lifetime of beans of a scope.
>
> e.g.
> scope.metric.RequestScoped=1
> scope.metric.ConversationScoped=2
> scope.metric.ApplicationScoped=3
>
> If someone e.g. likes to introduce a WorkflowScoped (which typically is even longer than applications since they may be persisted into a database and last for years (kafkaesk indeed but possible)) it would get a metric of 4.
> Another example: JSF has a 'FlashScoped' which would fit between RequestScoped and ConversationScoped ...
>
> Open questions:
> a.) can there be 2 scopes which are 'equally' ?
> b.) is a simple ordered (comma separated) list sufficient?
>
> WDYT? May we get this plugable enough?
>
> LieGrue,
> strub
>
>
>
>
>



      

Re: inventing a scope metric

Posted by James Carman <jc...@carmanconsulting.com>.
I would suggest keeping proxies regardless of scope incompatibilities.
 In Wicket, we use proxies for injected references because of
serialization issues (the pages/components are serialized out to
disk).  Most things that you're injecting aren't truly serializable
(like DAOs and stuff).  Now, we could re-inject dependencies upon
deserialization, but that doesn't solve the problem either.  Suppose a
component passes its directly-injected, non-proxied reference to some
other object that maintains that reference (a reference to a DAO for
instance).  Now, that object can't be serialized.


On Thu, Apr 2, 2009 at 11:56 AM, Mark Struberg <st...@yahoo.de> wrote:
>
> Hi!
>
> I'd like to write down a general idea about scopes and their interaction which (after a talk with Pete) I think is 'implicitely' defined in the JSR-299 spec.
>
> 1) If I inject a bean of a 'shorter' ranged scope into a bean with a 'longer' ranged scope, then we have to use a proxy object.
>
> An example: We do need a proxy if an @SessionScoped bean has an @RequestScoped bean as a member, because for every request, the @RequestScoped bean member is different to the one from the previous request.
>
> We do _not_ need to use a proxy if the scope of the injected member bean is 'equal' or 'longer' as the bean where it's a member of.
>
> 2.) Since the spec requires SessionScoped and ConversationScoped beans to be Serializable, those 2 have to be injected via proxies only.
>
> Since JSR-299 gives anyone the possibility to write own Scopes, a simple hardcoded scope comparison matrix is not sufficient.
> To work around this, we may introduce a simple list of metrics in our configuration, 1 for each known scope. Where a higher number means a longer lifetime of beans of a scope.
>
> e.g.
> scope.metric.RequestScoped=1
> scope.metric.ConversationScoped=2
> scope.metric.ApplicationScoped=3
>
> If someone e.g. likes to introduce a WorkflowScoped (which typically is even longer than applications since they may be persisted into a database and last for years (kafkaesk indeed but possible)) it would get a metric of 4.
> Another example: JSF has a 'FlashScoped' which would fit between RequestScoped and ConversationScoped ...
>
> Open questions:
> a.) can there be 2 scopes which are 'equally' ?
> b.) is a simple ordered (comma separated) list sufficient?
>
> WDYT? May we get this plugable enough?
>
> LieGrue,
> strub
>
>
>
>
>