You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by Zoran Jeremic <je...@yahoo.com> on 2010/07/26 20:28:10 UTC

Java instance accessed through Tuscany

Hi,

I've created Tuscany Web service that returns an instance of Java class. Then I 
work locally on this class and change it's properties. However, when I access 
the same instance from web service, there is no change on it's properties. As 
I'm new with tuscany I'm wondering if this java instance I get through tuscany 
behaves as the same instance or as another instance? Do I have to pass and 
change the old instance with the updated one?

Thanks



      

Re: Java instance accessed through Tuscany

Posted by Mike Edwards <mi...@gmail.com>.
Zoran Jeremic wrote:
> Hi,
> 
> I've created Tuscany Web service that returns an instance of Java class. 
> Then I work locally on this class and change it's properties. However, 
> when I access the same instance from web service, there is no change on 
> it's properties. As I'm new with tuscany I'm wondering if this java 
> instance I get through tuscany behaves as the same instance or as 
> another instance? Do I have to pass and change the old instance with the 
> updated one?
> 
> Thanks
> 
Zoran,

I think that Simon explains things very well.

Services are not like simple Java classes - the idea is that the service and the client are 
independent and are only connected through the contract defined by the service interface - and 
separation of the client and the service provider is a key goal of the services model.

So, if you want a service operation which returns some Java object/data structure from the service 
provider to the client - and then allow the client to modify that Java object and pass back the 
changed object to the service, then you should design a service interface that has a second 
operation that passes back the modified object to the service.

Something like:

public interface ServiceFoo {
	
	public Foo getAFoo( );

         public void returnUpdatedFoo( Foo updatedFoo );

}

Note that this potentially allows for the service to have many clients simultaneously and for the 
service to deal with independent updates.  Handing out a single Java object from the service would 
be a recipe for disaster if there are multiple clients.


Yours,  Mike.

Re: Java instance accessed through Tuscany

Posted by Zoran Jeremic <je...@yahoo.com>.
Hi Simon,

>To change the object in the service you'll have to arrange to
>send the changes back to the service. You'll need to devise a service
>interface to allow this to happen.

In the meantime I have implemented another service that accept changed object 
and change the old one with updated version, and this works for me, but it was 
very important for me to know how the thinks work with tuscany and I couldn't 
find the explanation of this on Google or I couldn't formulate appropriate 
question.
Thank you so much for your thorough explanation. That's exactly what I needed.

Zoran




________________________________
From: Simon Laws <si...@googlemail.com>
To: user@tuscany.apache.org
Sent: Tue, July 27, 2010 10:42:45 AM
Subject: Re: Java instance accessed through Tuscany

On Mon, Jul 26, 2010 at 7:28 PM, Zoran Jeremic <je...@yahoo.com> wrote:
> Hi,
>
> I've created Tuscany Web service that returns an instance of Java class.
> Then I work locally on this class and change it's properties. However, when
> I access the same instance from web service, there is no change on it's
> properties. As I'm new with tuscany I'm wondering if this java instance I
> get through tuscany behaves as the same instance or as another instance? Do
> I have to pass and change the old instance with the updated one?
>
> Thanks
>
>

Hi

The short answer is yes you are working with a copy of the original object.

When you communicate with a service using Web Services you are using a
remote interface. In SCA terms the service's Java interface must be
marked as @Remotable (there are other ways that it can be marked as
remotable but I'm skipping over those for the purpose of this
explanantion).

A remote interface allows you to communicate with services regardless
of where they are running. For example, the service could be running
on a completely separate machine from component that's calling it.
Hence the use of the term remote.

To make this work, remote interfaces always exploit pass by value
semantics. By this we mean that when an object is passed into the
remote service or when the remote service returns an object a copy
(the value) of the object is passed rather than a reference to the
original object. This must be the case because, when using protocols
such as SOAP/HTTP, the object will be serialized out to XML to be
sent. When the XML is received it is converted back into the right
sort of object. As you can imagine you can't do this sort of thing
while maintaining an reference to the original object.

Hence when you make changes to the object that has been returned to
you in the client component the original object in the service is not
changed. To change the object in the service you'll have to arrange to
send the changes back to the service. You'll need to devise a service
interface to allow this to happen.

Hope that helps

Simon


-- 
Apache Tuscany committer: tuscany.apache.org
Co-author of a book about Tuscany and SCA: tuscanyinaction.com



      

Re: Java instance accessed through Tuscany

Posted by Simon Laws <si...@googlemail.com>.
On Mon, Jul 26, 2010 at 7:28 PM, Zoran Jeremic <je...@yahoo.com> wrote:
> Hi,
>
> I've created Tuscany Web service that returns an instance of Java class.
> Then I work locally on this class and change it's properties. However, when
> I access the same instance from web service, there is no change on it's
> properties. As I'm new with tuscany I'm wondering if this java instance I
> get through tuscany behaves as the same instance or as another instance? Do
> I have to pass and change the old instance with the updated one?
>
> Thanks
>
>

Hi

The short answer is yes you are working with a copy of the original object.

When you communicate with a service using Web Services you are using a
remote interface. In SCA terms the service's Java interface must be
marked as @Remotable (there are other ways that it can be marked as
remotable but I'm skipping over those for the purpose of this
explanantion).

A remote interface allows you to communicate with services regardless
of where they are running. For example, the service could be running
on a completely separate machine from component that's calling it.
Hence the use of the term remote.

To make this work, remote interfaces always exploit pass by value
semantics. By this we mean that when an object is passed into the
remote service or when the remote service returns an object a copy
(the value) of the object is passed rather than a reference to the
original object. This must be the case because, when using protocols
such as SOAP/HTTP, the object will be serialized out to XML to be
sent. When the XML is received it is converted back into the right
sort of object. As you can imagine you can't do this sort of thing
while maintaining an reference to the original object.

Hence when you make changes to the object that has been returned to
you in the client component the original object in the service is not
changed. To change the object in the service you'll have to arrange to
send the changes back to the service. You'll need to devise a service
interface to allow this to happen.

Hope that helps

Simon


-- 
Apache Tuscany committer: tuscany.apache.org
Co-author of a book about Tuscany and SCA: tuscanyinaction.com