Home » Modeling » EMF » Sending and receiving XMIResources over network
Sending and receiving XMIResources over network [message #1398682] |
Fri, 11 July 2014 12:22 |
Tassilo Horn 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 #1398714 is a reply to message #1398682] |
Fri, 11 July 2014 13:19 |
Ed Merks Messages: 33140 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | |
Re: Sending and receiving XMIResources over network [message #1398902 is a reply to message #1398802] |
Fri, 11 July 2014 19:24 |
Tassilo Horn 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 |
Felix Dorner 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 |
Tassilo Horn 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 |
Ed Merks Messages: 33140 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Wed Apr 24 18:41:32 GMT 2024
Powered by FUDForum. Page generated in 0.03514 seconds
|