EMF Resource load from InputStream taking too long [message #1634807] |
Wed, 25 February 2015 08:13  |
Eclipse User |
|
|
|
Hi,
I am trying to load an EMF resource from an InputStream in Java as stated in the topic and here is how the code looks:
DataPackage.eINSTANCE.eClass();
String nsURI = DataPackage.eINSTANCE.getNsURI();
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("*", new XMIResourceFactoryImpl());
ResourceSet resSet = new ResourceSetImpl();
resSet.getPackageRegistry().put(nsURI, DataPackage.eINSTANCE);
//Get URL contents
URL mashupUrl = new URL(url);
URLConnection connection = mashupUrl.openConnection();
connection.setConnectTimeout(15000);
connection.setReadTimeout(600000);
bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((inputLine = bufferedReader.readLine()) != null)
{
content.append(inputLine);
}
bufferedReader.close();
connection.getInputStream().close();
//Get URL contents
Resource res = resSet.createResource(URI.createURI(url));
if(res == null) {
throw new MashupConnectionException("Could not create emf resource", url);
}
final long start = System.currentTimeMillis();
//Load resource
try {
System.out.println("Resource load start: " + new Date());
res.load(new URIConverter.ReadableInputStream(content.toString(), StandardCharsets.UTF_8.name()), null);
System.out.println("Resource load end: " + new Date() + " Seconds elapsed: " + (System.currentTimeMillis() - start)/1000.0);
} catch (IOException e) {
...
}
As you can see above, "content" contains the XML data retrieved from a URL: muc2014.communitymashup.net/x3/mashup
My main question: The same code used to load the resource in < 2 minutes in my previous project (which somehow got corrupted and I had no backup unfortunately). I have now reproduced this from memory, it works, but the resource loading time has increased ten folds and I am totally unable to recall what I was doing differently in my previous version of the project.
If any other resources are required, please let me know! I would really appreciate your help.
Thank you!
[Updated on: Wed, 25 February 2015 09:44] by Moderator
|
|
|
Re: EMF Resource load from InputStream taking too long [message #1636380 is a reply to message #1634807] |
Thu, 26 February 2015 01:55   |
Eclipse User |
|
|
|
Syed,
Comments below.
On 25.02.2015 15:12, Syed Rizvi wrote:
> Hi,
> I am trying to load an EMF resource from an InputStream in Java as
> stated in the topic and here is how the code looks:
>
> DataPackage.eINSTANCE.eClass();
> String nsURI = DataPackage.eINSTANCE.getNsURI();
> Resource.Factory.Registry reg =
> Resource.Factory.Registry.INSTANCE;
> Map<String, Object> m = reg.getExtensionToFactoryMap();
> m.put("*", new XMIResourceFactoryImpl());
Is this a stand alone application rather than something running in an
Eclipse IDE?
>
> ResourceSet resSet = new ResourceSetImpl();
> resSet.getPackageRegistry().put(nsURI, DataPackage.eINSTANCE);
>
> //Get URL contents
> URL mashupUrl = new URL(url);
> URLConnection connection = mashupUrl.openConnection();
> connection.setConnectTimeout(15000);
> connection.setReadTimeout(600000);
>
> bufferedReader = new BufferedReader(new
> InputStreamReader(connection.getInputStream()));
>
> while ((inputLine = bufferedReader.readLine()) != null)
> {
> content.append(inputLine);
> }
>
> bufferedReader.close();
> //Get URL contents
>
> Resource res = resSet.createResource(URI.createURI(url));
>
> if(res == null) {
> throw new MashupConnectionException("Could not create
> emf resource", url);
> }
>
> final long start = System.currentTimeMillis();
>
> //Load resource
> try {
>
> System.out.println("Resource load start: " + new Date());
> res.load(new
> URIConverter.ReadableInputStream(content.toString(),
> StandardCharsets.UTF_8.name()), null);
> System.out.println("Resource load end: " + new Date() +
> " Seconds elapsed: " + (System.currentTimeMillis() - start)/1000.0);
>
> } catch (IOException e) {
> ...
> }
>
>
> As you can see above, "content" contains the XML data retrieved from a
> URL: muc2014.communitymashup.net/x3/mashup
Why is this all so complicated? I.e., why not pass an input stream
direction to load? Then it would properly respect the encoding of the
XML/XMI?
> My main question: The same code used to load the resource in < 2 minutes
> in my previous project (which somehow got corrupted and I had no backup
> unfortunately). I have now reproduced this from memory, it works, but
> the resource loading time has increased ten folds and I am totally
> unable to recall what I was doing differently in my previous version of
> the project.
There are often questions about which options can be used to affect the
performance of loading. You could look for such answers. Often simple
things like deferring ID resolution have a huge impact.
>
> If any other resources are required, please let me know! I would really
> appreciate your help.
>
> Thank you!
>
|
|
|
|
|
|
Re: EMF Resource load from InputStream taking too long [message #1647633 is a reply to message #1647559] |
Tue, 03 March 2015 09:33  |
Eclipse User |
|
|
|
Syed,
It's hard to speculate...
On 03/03/2015 2:48 PM, Syed Rizvi wrote:
> Thanks Ed, using the options improved the resource loading by 200
> seconds, bringing it down to about 900 seconds instead of 1100. Though
> my one question remains unaswered and that is: Why does my laptop
> complete it in such a long time when it used to do it in < 2 minutes
> previously. There is no way I can bring it down. I've noticed when the
> exact same project is run on my friend's machine with only difference
> of 8 vs 16 Gigs of RAM, the resource load completed in 20 seconds. It
> is unbelievable!
|
|
|
Powered by
FUDForum. Page generated in 0.04844 seconds