You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by Blue Diamond <gv...@gmail.com> on 2010/02/25 06:49:16 UTC

object reference to a service

Hi,

I have a @scope(composite) annotated component (service). This is a
singleton for me (correct me if I am wrong) and no matter how many clients
call the service operations, its the same service instance that's going to
handle them.

SCA API provides a way to obtain service reference to this component through
say SCANode.getServiceReference().

But is there a way I can obtain the object reference to this instantiated
service instance? I understand that SCA has boundaries, but is there any way
by which this can be done?

SCA creates a component, I want to obtain its object reference (I want to
inject some other non-SCA created object into it). Is this doable?

Thanks,
Anil

Re: object reference to a service

Posted by Simon Nash <na...@apache.org>.
Blue Diamond wrote:
> Hi,
> 
> I have a @scope(composite) annotated component (service). This is a 
> singleton for me (correct me if I am wrong) and no matter how many 
> clients call the service operations, its the same service instance 
> that's going to handle them.
> 
> SCA API provides a way to obtain service reference to this component 
> through say SCANode.getServiceReference().
> 
> But is there a way I can obtain the object reference to this 
> instantiated service instance? I understand that SCA has boundaries, but 
> is there any way by which this can be done? 
> 
> SCA creates a component, I want to obtain its object reference (I want 
> to inject some other non-SCA created object into it). Is this doable?
> 
> Thanks,
> Anil
 >
The component implementation could define a service with a local interface
which provides a setter method for the non-SCA created object.  After the
singleton instance has been created, you could call this setter method to
inject the non-SCA created object.

   Simon


Re: object reference to a service

Posted by Simon Nash <na...@apache.org>.
Blue Diamond wrote:
> Thanks Guys!. My requirement is to inject a non-SCA object into a 
> singleton SCA service composite. So, as Simon explained, if a 
> setMyObject(my_non_sca_object) works on an SCA service reference, then 
> that does my job!
> 
It should work as local as the interface containing setMyObject() is
a local interface (i.e., does't have the @Remotable annotation).
This restricts the methods of the interface to being called from
within the same JVM, which is exactly what you need.

   Simon

> Thanks & Regards,
> Anil
> 
> On Thu, Feb 25, 2010 at 11:38 AM, Raymond Feng <enjoyjava@gmail.com 
> <ma...@gmail.com>> wrote:
> 
>     Hi,
>      
>     Are you trying to get a self reference to this composite-scoped
>     service? If so, you can do the following:
>      
>     @Scope("COMPOSITE")
>     @Service(MySevice.class)
>     public class MyServiceImpl {
>      
>     @Context
>     protected ComponentContext componentContext;
>      
>     ...
>      
>     ServiceReference<MyService> ref =
>     componentContext.createSelfReference(MyService.class);
>      
>     To get the service reference in another component, you can do:
>      
>     @Reference
>     protected ServiceReference<MyService> myService; // It will be
>     injected by Tuscany if it's wired to MyService component.
>      
>     Thanks,
>     Raymond
> 
>     *From:* Blue Diamond <ma...@gmail.com>
>     *Sent:* Wednesday, February 24, 2010 9:49 PM
>     *To:* user@tuscany.apache.org <ma...@tuscany.apache.org>
>     *Subject:* object reference to a service
> 
>     Hi,
> 
>     I have a @scope(composite) annotated component (service). This is a
>     singleton for me (correct me if I am wrong) and no matter how many
>     clients call the service operations, its the same service instance
>     that's going to handle them.
> 
>     SCA API provides a way to obtain service reference to this component
>     through say SCANode.getServiceReference().
> 
>     But is there a way I can obtain the object reference to this
>     instantiated service instance? I understand that SCA has boundaries,
>     but is there any way by which this can be done? 
> 
>     SCA creates a component, I want to obtain its object reference (I
>     want to inject some other non-SCA created object into it). Is this
>     doable?
> 
>     Thanks,
>     Anil
> 
> 


Re: object reference to a service

Posted by Blue Diamond <gv...@gmail.com>.
Thanks Guys!. My requirement is to inject a non-SCA object into a singleton
SCA service composite. So, as Simon explained, if a
setMyObject(my_non_sca_object) works on an SCA service reference, then that
does my job!

Thanks & Regards,
Anil

On Thu, Feb 25, 2010 at 11:38 AM, Raymond Feng <en...@gmail.com> wrote:

>  Hi,
>
> Are you trying to get a self reference to this composite-scoped service? If
> so, you can do the following:
>
> @Scope("COMPOSITE")
> @Service(MySevice.class)
> public class MyServiceImpl {
>
> @Context
> protected ComponentContext componentContext;
>
> ...
>
> ServiceReference<MyService> ref =
> componentContext.createSelfReference(MyService.class);
>
> To get the service reference in another component, you can do:
>
> @Reference
> protected ServiceReference<MyService> myService; // It will be injected by
> Tuscany if it's wired to MyService component.
>
> Thanks,
> Raymond
>
>  *From:* Blue Diamond <gv...@gmail.com>
> *Sent:* Wednesday, February 24, 2010 9:49 PM
> *To:* user@tuscany.apache.org
> *Subject:* object reference to a service
>
> Hi,
>
> I have a @scope(composite) annotated component (service). This is a
> singleton for me (correct me if I am wrong) and no matter how many clients
> call the service operations, its the same service instance that's going to
> handle them.
>
> SCA API provides a way to obtain service reference to this component
> through say SCANode.getServiceReference().
>
> But is there a way I can obtain the object reference to this instantiated
> service instance? I understand that SCA has boundaries, but is there any way
> by which this can be done?
>
> SCA creates a component, I want to obtain its object reference (I want to
> inject some other non-SCA created object into it). Is this doable?
>
> Thanks,
> Anil
>

Re: object reference to a service

Posted by Raymond Feng <en...@gmail.com>.
Hi,

Are you trying to get a self reference to this composite-scoped service? If so, you can do the following:

@Scope("COMPOSITE")
@Service(MySevice.class)
public class MyServiceImpl {

@Context
protected ComponentContext componentContext;

...

ServiceReference<MyService> ref = componentContext.createSelfReference(MyService.class);

To get the service reference in another component, you can do:

@Reference
protected ServiceReference<MyService> myService; // It will be injected by Tuscany if it's wired to MyService component.

Thanks,
Raymond


From: Blue Diamond 
Sent: Wednesday, February 24, 2010 9:49 PM
To: user@tuscany.apache.org 
Subject: object reference to a service


Hi, 


I have a @scope(composite) annotated component (service). This is a singleton for me (correct me if I am wrong) and no matter how many clients call the service operations, its the same service instance that's going to handle them.


SCA API provides a way to obtain service reference to this component through say SCANode.getServiceReference().


But is there a way I can obtain the object reference to this instantiated service instance? I understand that SCA has boundaries, but is there any way by which this can be done? 


SCA creates a component, I want to obtain its object reference (I want to inject some other non-SCA created object into it). Is this doable?


Thanks,
Anil