You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Jeremy Boynes <jb...@apache.org> on 2006/08/02 00:51:57 UTC

Scope factory initialization: svn commit: r427726 [1/2] ...

Ken,

I think the factories should wait until their init method is called  
otherwise they are registering before they have finished being  
initialized. This also allows a "this" reference to leak before the  
object has finished being constructed (i.e. it could be invoked  
before it is fully instantiated). This problem is in all the recent  
scope factory changes.

Will this fix the issue Ant mentioned yesterday where leaving off  
@Scope("MODULE") gave a NPE?

--
Jeremy

  public class ModuleScopeObjectFactory implements  
ObjectFactory<ModuleScopeContainer> {
+
+    public ModuleScopeObjectFactory(@Autowire ScopeRegistry registry) {
+        registry.registerFactory(Scope.MODULE, this);
+    }
+
+    @Init(eager = true)
+    public void init() {
+    }



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: Scope factory initialization: svn commit: r427726 [1/2] ...

Posted by Jeremy Boynes <jb...@apache.org>.
On Aug 1, 2006, at 5:29 PM, Ken Tam wrote:

> I was seeing a ScopeNotFoundException rather than an NPE I think, but
> yeah, it happened when a component defaulted to STATELESS scope (in
> the absence of an @Scope("MODULE")).  I talked with Jim and we came to
> this fix together.

OK - thanks for fixing this.

> Just so's I understand what you're saying -- the problems you're
> describing are theoretical at this point, right?  Because the current
> scope factories are trivial in their "construction" (ie, the ctors
> don't do anything, nor do the init methods), any races between
> ctor/init completion & other code calling into the factory aren't
> actually a problem (given the super class's ctor will always be
> completed).

I don't think so - once you call register, another thread could call  
the registry which may invoke you before the constructor had  
completed. There were some changes to how object construction worked  
in the 1.5 memory model so this may not be an issue any more.

>
> That said, agree the code should always do the right thing :)   My
> understanding of component instantiation is ctor followed by init
> method -- so we could store the injected ScopeFactory in the ctor and
> do the register call in the init, and then clear the injected
> ScopeFactory reference (avoiding circular references).   Is that what
> you're suggesting by "waiting until their init method is called" ?

Yes.

> Jim & I also discussed a more complex solution involving making the
> scope registry "watch" for newly created scope factories and register
> them, but given the seriousness of the problem, having some solution
> checked in seemed expedient.

Agreed. Jim, Sebastien and I had discussed mapped multiplicity  
references before as well. The application here would be the registry  
having a multiplicity reference of type Map whose members would be  
automatically managed by the fabric. As eligible services came online  
(based on rules associated with the reference) their key would be  
extracted and they would be inserted in the Map.

>
> BTW, does @Init work with inheritance?  Ie, if my super-class has a
> method marked @Init, will that method get called before my @Init
> method?

I believe there can only be one method marked @Init across the  
implementation and its superclasses. Normal Java method overriding is  
followed (so if you override it your declared method will be called  
and it is your responsibility to call the superclass method that you  
override).

--
Jeremy



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: Scope factory initialization: svn commit: r427726 [1/2] ...

Posted by Jim Marino <jm...@myromatours.com>.
On Aug 1, 2006, at 5:29 PM, Ken Tam wrote:

> I was seeing a ScopeNotFoundException rather than an NPE I think, but
> yeah, it happened when a component defaulted to STATELESS scope (in
> the absence of an @Scope("MODULE")).  I talked with Jim and we came to
> this fix together.
>
> Just so's I understand what you're saying -- the problems you're
> describing are theoretical at this point, right?  Because the current
> scope factories are trivial in their "construction" (ie, the ctors
> don't do anything, nor do the init methods), any races between
> ctor/init completion & other code calling into the factory aren't
> actually a problem (given the super class's ctor will always be
> completed).
>
> That said, agree the code should always do the right thing :)   My
> understanding of component instantiation is ctor followed by init
> method -- so we could store the injected ScopeFactory in the ctor and
> do the register call in the init, and then clear the injected
> ScopeFactory reference (avoiding circular references).   Is that what
> you're suggesting by "waiting until their init method is called" ?
> Jim & I also discussed a more complex solution involving making the
> scope registry "watch" for newly created scope factories and register
> them, but given the seriousness of the problem, having some solution
> checked in seemed expedient.
>
> BTW, does @Init work with inheritance?  Ie, if my super-class has a
> method marked @Init, will that method get called before my @Init
> method?
>
Yea I think having the registration done in init() is better due to  
an escaping this reference. @Init will be called after the ctor is  
and all injection performed so it's safe to do that.

Jim

>
> On 8/1/06, Jeremy Boynes <jb...@apache.org> wrote:
>> Ken,
>>
>> I think the factories should wait until their init method is called
>> otherwise they are registering before they have finished being
>> initialized. This also allows a "this" reference to leak before the
>> object has finished being constructed (i.e. it could be invoked
>> before it is fully instantiated). This problem is in all the recent
>> scope factory changes.
>>
>> Will this fix the issue Ant mentioned yesterday where leaving off
>> @Scope("MODULE") gave a NPE?
>>
>> --
>> Jeremy
>>
>>   public class ModuleScopeObjectFactory implements
>> ObjectFactory<ModuleScopeContainer> {
>> +
>> +    public ModuleScopeObjectFactory(@Autowire ScopeRegistry  
>> registry) {
>> +        registry.registerFactory(Scope.MODULE, this);
>> +    }
>> +
>> +    @Init(eager = true)
>> +    public void init() {
>> +    }
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
>> For additional commands, e-mail: tuscany-dev-help@ws.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-dev-help@ws.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: Scope factory initialization: svn commit: r427726 [1/2] ...

Posted by Ken Tam <ke...@gmail.com>.
I was seeing a ScopeNotFoundException rather than an NPE I think, but
yeah, it happened when a component defaulted to STATELESS scope (in
the absence of an @Scope("MODULE")).  I talked with Jim and we came to
this fix together.

Just so's I understand what you're saying -- the problems you're
describing are theoretical at this point, right?  Because the current
scope factories are trivial in their "construction" (ie, the ctors
don't do anything, nor do the init methods), any races between
ctor/init completion & other code calling into the factory aren't
actually a problem (given the super class's ctor will always be
completed).

That said, agree the code should always do the right thing :)   My
understanding of component instantiation is ctor followed by init
method -- so we could store the injected ScopeFactory in the ctor and
do the register call in the init, and then clear the injected
ScopeFactory reference (avoiding circular references).   Is that what
you're suggesting by "waiting until their init method is called" ?
Jim & I also discussed a more complex solution involving making the
scope registry "watch" for newly created scope factories and register
them, but given the seriousness of the problem, having some solution
checked in seemed expedient.

BTW, does @Init work with inheritance?  Ie, if my super-class has a
method marked @Init, will that method get called before my @Init
method?


On 8/1/06, Jeremy Boynes <jb...@apache.org> wrote:
> Ken,
>
> I think the factories should wait until their init method is called
> otherwise they are registering before they have finished being
> initialized. This also allows a "this" reference to leak before the
> object has finished being constructed (i.e. it could be invoked
> before it is fully instantiated). This problem is in all the recent
> scope factory changes.
>
> Will this fix the issue Ant mentioned yesterday where leaving off
> @Scope("MODULE") gave a NPE?
>
> --
> Jeremy
>
>   public class ModuleScopeObjectFactory implements
> ObjectFactory<ModuleScopeContainer> {
> +
> +    public ModuleScopeObjectFactory(@Autowire ScopeRegistry registry) {
> +        registry.registerFactory(Scope.MODULE, this);
> +    }
> +
> +    @Init(eager = true)
> +    public void init() {
> +    }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-dev-help@ws.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org