|
Nux 1.6 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object nux.xom.pool.DocumentPool
public class DocumentPool
Efficient compact thread-safe pool/cache of XOM XML Document
objects,
storing documents in a DocumentMap
. On cache miss, a new document is
created via a factory, cached for future reuse, and then returned. On cache
hit a document is returned almost instantly.
Pool eviction is delegated to the DocumentMap/PoolConfig store.
By default returns a copy of a cached document on each invocation of
methods getDocument(...)
.
This ensures that documents contained inside the cache cannot be modified by clients,
which would be unsafe in the presense of multiple threads and application modules
using a shared DocumentPool instance (a shared instance reduces overall memory
consumption).
This class helps to avoid the large overhead involved in parsing XML documents. Most useful in high throughput server container environments (e.g. large-scale Peer-to-Peer messaging network infrastructures over high-bandwidth networks, scalable MOMs, etc).
Example usage (in any arbitrary thread and any arbitrary object):
// parse file with non-validating parser Document doc = DocumentPool.GLOBAL_POOL.getDocument(new File("samples/data/periodic.xml")); // pool with custom document factory for W3C XML Schema validation DocumentFactory factory = new DocumentFactory() { protected Builder newBuilder() { return BuilderPool.GLOBAL_POOL.getW3CBuilder(someW3CXMLSchema); // return new Builder(); } }; DocumentPool pool = new DocumentPool(new DocumentMap(new PoolConfig()), factory); Document doc = pool.getDocument(new File("samples/data/periodic.xml")); // pool reading binary xml documents DocumentPool pool = new DocumentPool(new DocumentMap(new PoolConfig()), new DocumentFactory().getBinaryXMLFactory()); Document doc = pool.getDocument(new File("samples/data/periodic.xml.bnux"));
Field Summary | |
---|---|
static DocumentPool |
GLOBAL_POOL
A default pool (can be shared freely across threads without harm); global per class loader. |
Constructor Summary | |
---|---|
DocumentPool()
Creates a new pool with default parameters. |
|
DocumentPool(DocumentMap entries,
DocumentFactory factory)
Creates a new pool that uses the given document cache data structure and factory. |
Method Summary | |
---|---|
Document |
getDocument(File input)
Returns a document for the given input file. |
Document |
getDocument(ResourceResolver resolver,
String resourceName,
URI baseURI)
Returns a document for the input stream obtained from resolving the given resourceName against the given resolver. |
Document |
getDocument(URI systemID)
Returns a document for the given URL. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final DocumentPool GLOBAL_POOL
Constructor Detail |
---|
public DocumentPool()
public DocumentPool(DocumentMap entries, DocumentFactory factory)
entries
- an empty document cache data structurefactory
- the factory creating new Document instances on cache missesMethod Detail |
---|
public Document getDocument(File input) throws ParsingException, IOException
input
- the file to read from
IOException
- if an I/O error occurs while reading from the stream
ParsingException
- if an XML parsing error occurspublic Document getDocument(URI systemID) throws ParsingException, IOException
systemID
- the URL of the document
IOException
- if an I/O error occurs while reading from the stream
ParsingException
- if an XML parsing error occurspublic Document getDocument(ResourceResolver resolver, String resourceName, URI baseURI) throws ParsingException, IOException, MissingResourceException
resolver
- an object that can produce an input stream for a given
resource name.resourceName
- the resource name (e.g. a path or URL)baseURI
- the base URI of the document (may be null
)
Need not be the actual URI of the resolver's stream.
MissingResourceException
- if the resolver could not find the resource (unchecked
exception)
IOException
- if an I/O error occurs while reading from the stream
ParsingException
- if an XML parsing error occurs
|
Nux 1.6 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |