Caching Metadata
It may be that rather than downloading Metadata everytime, for speeds sake your application may want to cache the Metadata to the local file system and load it from there.
Saving The Metadata
// Get the metadata from the server
MetadataSystem system = session.getMetadata();
// Create the output stream for the metadata
OutputStream out = new FileOutputStream(metadataFile);
// Get a standard xml transformer
MetadataTransformer transformer =
MetadataTransformerFactory.newTransformer(
MetadataFormat.STANDARD_XML);
// Write the complete metadata to file
transformer.transform(
system, MetadataType.SYSTEM,
new String[] {"*"}, true, out);
out.close();
out = null;
Loading The Metadata
// To read the metadata from a file create // an input file stream InputStream in = new FileInputStream(metadataFile); // Create a metadata source XmlMetadataSource source = new XmlMetadataSource(in); // Build the metadata. This returns a list of systems // This list should contain 1 item. Listsystems = source.build(); MetadataSystem system = systems.get(0); // Close the input stream in.close();
Memory Considerations
The Metadata in-memory model may consume a reasonable amount of memory depending on the size of the metadata. If you get OutOfMemoryException exceptions increase the JVM memory allocation using the -Xms and -Xmx Java virtual machine arguments.
For example to start the JVM with 128MB of memory and allowing it to expand to a maximum of 256MB, the parameters would be -Xms128m and -Xmx256m respectively.
java -Xms128m -Xmx256 -cp %MY_CLASSPATH% MyApplication