Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Sending and receiving XMIResources over network
Sending and receiving XMIResources over network [message #1398682] Fri, 11 July 2014 12:22 Go to next message
Tassilo Horn is currently offline Tassilo HornFriend
Messages: 93
Registered: July 2009
Member
Hi all,

I'm currently implementing a server that needs to send models to clients and receive models from clients. We can assume that both server and clients have the corresponding Ecore models available. The models need to be transferred only, and the receiver won't change them. So there's no need for synchronization, etc.

The protocol between server is very simple. Just some strings for registration, and then only models need to be sent. Is there something readily available to send XMIResources via OutputStreams and to read them from an InputStream?

Right now, it seems the sender needs to persist the model to be sent in an XMI file, and then I can read that with a FileInputStream and write it to the socket's output stream. Isn't there a way to at least get rid of the requirement to save it in a file, e.g., write an XMIResource to a string, and read an XMIResoure from a string?

Thanks,
Tassilo
Re: Sending and receiving XMIResources over network [message #1398691 is a reply to message #1398682] Fri, 11 July 2014 12:40 Go to previous messageGo to next message
Tassilo Horn is currently offline Tassilo HornFriend
Messages: 93
Registered: July 2009
Member
Ups, I've just discovered that XMIResource has load() and save() methods for Input/OutputStreams. That's most probably what I've been looking for.
Re: Sending and receiving XMIResources over network [message #1398714 is a reply to message #1398682] Fri, 11 July 2014 13:19 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30553
Registered: July 2009
Senior Member
Tassilo,

Note that EMF supports reading resources directly from an http URI and
even supports writes if the server itself allows PUT, see
org.eclipse.emf.ecore.resource.impl.URIHandlerImpl.createOutputStream(URI,
Map<?, ?>). In any case, you should be able to hook up your
communication mechanism via a URIHandler rather than needing to
specialize how the resource itself saves and loads...



On 11/07/2014 2:22 PM, Tassilo Horn wrote:
> Hi all,
>
> I'm currently implementing a server that needs to send models to
> clients and receive models from clients. We can assume that both
> server and clients have the corresponding Ecore models available. The
> models need to be transferred only, and the receiver won't change
> them. So there's no need for synchronization, etc.
>
> The protocol between server is very simple. Just some strings for
> registration, and then only models need to be sent. Is there
> something readily available to send XMIResources via OutputStreams and
> to read them from an InputStream?
>
> Right now, it seems the sender needs to persist the model to be sent
> in an XMI file, and then I can read that with a FileInputStream and
> write it to the socket's output stream. Isn't there a way to at least
> get rid of the requirement to save it in a file, e.g., write an
> XMIResource to a string, and read an XMIResoure from a string?
>
> Thanks,
> Tassilo
Re: Sending and receiving XMIResources over network [message #1398801 is a reply to message #1398714] Fri, 11 July 2014 16:11 Go to previous messageGo to next message
Tassilo Horn is currently offline Tassilo HornFriend
Messages: 93
Registered: July 2009
Member
Hi Ed,

I'm communicating over plain sockets, so there are no URIs involved.

It seems that on my server

myResourceOnServer.save(socketOfClient.getOutputStream(), myResourceOnServer.getDefaultSaveOptions());

does the right thing. At least if I put System.out as first parameter, the complete XMI representation of the resource is printed.

But the corresponding operation

myResourceOnClient.load(socketOfServer.getInputStream(), myResourceOnClient.getDefaultLoadOptions());

blocks indefinitely, and I have no clue why. I made sure that the output stream on the server gets flushed, but that didn't help.

Bye,
Tassilo
Re: Sending and receiving XMIResources over network [message #1398802 is a reply to message #1398801] Fri, 11 July 2014 16:14 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
Yo,

On 11/07/2014 18:11, Tassilo Horn wrote:
>
> But the corresponding operation
>
> myResourceOnClient.load(socketOfServer.getInputStream(),
> myResourceOnClient.getDefaultLoadOptions());
>
> blocks indefinitely, and I have no clue why. I made sure that the
> output stream on the server gets flushed, but that didn't help.

Flushed only? If you don't also close it it will hang, and if you close
it, it will be flushed automatically.
Re: Sending and receiving XMIResources over network [message #1398902 is a reply to message #1398802] Fri, 11 July 2014 19:24 Go to previous messageGo to next message
Tassilo Horn is currently offline Tassilo HornFriend
Messages: 93
Registered: July 2009
Member
Felix Dorner wrote on Fri, 11 July 2014 12:14

> But the corresponding operation
>
> myResourceOnClient.load(socketOfServer.getInputStream(),
> myResourceOnClient.getDefaultLoadOptions());
>
> blocks indefinitely, and I have no clue why. I made sure that the
> output stream on the server gets flushed, but that didn't help.

Flushed only? If you don't also close it it will hang, and if you close
it, it will be flushed automatically.


I can't close it as there needs to be more communication later on. But now I think I understand the problem: an XMIResource might contain multiple top-level XMI/XML elements, so load() cannot know that the resource is complete after reading and parsing the first top-level element. Does that sound reasonable?

And if so, is there some trick/option that allows load() to finish after reading the first top-level element?

Bye,
Tassilo
Re: Sending and receiving XMIResources over network [message #1399280 is a reply to message #1398902] Sat, 12 July 2014 09:55 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 11/07/2014 21:24, Tassilo Horn wrote:
> Felix Dorner wrote on Fri, 11 July 2014 12:14
>> > But the corresponding operation
>> >
>> > myResourceOnClient.load(socketOfServer.getInputStream(),
>> > myResourceOnClient.getDefaultLoadOptions());
>> >
>> > blocks indefinitely, and I have no clue why. I made sure that the
>> > output stream on the server gets flushed, but that didn't help.
>>
>> Flushed only? If you don't also close it it will hang, and if you
>> close it, it will be flushed automatically.
>
>
> I can't close it as there needs to be more communication later on.

Maybe you can use a multiplexer or several channels?

> now I think I understand the problem: an XMIResource might contain
> multiple top-level XMI/XML elements, so load() cannot know that the
> resource is complete after reading and parsing the first top-level
> element. Does that sound reasonable?

Only one root element, but that there may be Comments, Processing
Instructions Whitespace after the root.

Felix
Re: Sending and receiving XMIResources over network [message #1400389 is a reply to message #1399280] Mon, 14 July 2014 06:08 Go to previous messageGo to next message
Tassilo Horn is currently offline Tassilo HornFriend
Messages: 93
Registered: July 2009
Member
Felix Dorner wrote on Sat, 12 July 2014 05:55

> I can't close it as there needs to be more communication later on.

Maybe you can use a multiplexer or several channels?

> now I think I understand the problem: an XMIResource might contain
> multiple top-level XMI/XML elements, so load() cannot know that the
> resource is complete after reading and parsing the first top-level
> element. Does that sound reasonable?

Only one root element, but that there may be Comments, Processing
Instructions Whitespace after the root.


Yes, I understand. Now I'm using my own BEGIN/END_RESOURCE markers, save the resource to a StringWriter, then send that string, and the client reads into a StringBuilder which is then put into a ByteArrayInputStream from which the resource is loaded. That works fine, because load() now knows when the end of input is reached.

Thanks,
Tassilo
Re: Sending and receiving XMIResources over network [message #1400451 is a reply to message #1400389] Mon, 14 July 2014 08:04 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30553
Registered: July 2009
Senior Member
Tassilo,

Note that if you are parsing directly from a String, you can use
org.eclipse.emf.ecore.resource.URIConverter.ReadableInputStream.ReadableInputStream(String)
to create an input stream which will bypass the String -> byte[] ->
String transformation that happens with your current approach.


On 14/07/2014 8:08 AM, Tassilo Horn wrote:
> Felix Dorner wrote on Sat, 12 July 2014 05:55
>> > I can't close it as there needs to be more communication later on.
>>
>> Maybe you can use a multiplexer or several channels?
>>
>> > now I think I understand the problem: an XMIResource might contain
>> > multiple top-level XMI/XML elements, so load() cannot know that the
>> > resource is complete after reading and parsing the first top-level
>> > element. Does that sound reasonable?
>>
>> Only one root element, but that there may be Comments, Processing
>> Instructions Whitespace after the root.
>
>
> Yes, I understand. Now I'm using my own BEGIN/END_RESOURCE markers,
> save the resource to a StringWriter, then send that string, and the
> client reads into a StringBuilder which is then put into a
> ByteArrayInputStream from which the resource is loaded. That works
> fine, because load() now knows when the end of input is reached.
>
> Thanks,
> Tassilo
Previous Topic:null text generated in editor plugin.xml
Next Topic:migration: EString attribute to ERference
Goto Forum:
  


Current Time: Tue Oct 22 14:57:22 GMT 2019

Powered by FUDForum. Page generated in 0.03530 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top