|
Nux 1.0a5 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnux.xom.pool.XQueryPool
Efficient thread-safe pool/cache of XQuery
objects, creating and
holding at most maxPoolEntries
XQuery objects (each
representing a compiled query). On cache miss, a new object
is created via a factory, cached for future reuse, and then returned.
Pool eviction is based on a LRU (least recently used) policy.
This class helps to avoid the large overhead involved in constructing (i.e. compiling) an XQuery instance, in particul for complex queries over small input 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):
XQuery xquery = XQueryPool.GLOBAL_POOL.getXQuery(new File("/tmp/test.xq")); //XQuery xquery = XQueryPool.GLOBAL_POOL.getXQuery("for $i in /* return $i/headline_text", null); Document doc = BuilderPool.GLOBAL_POOL.getBuilder(false).build(new File("/tmp/test.xml")); Nodes results = xquery.execute(doc).toNodes(); for (int i=0; i < results.size(); i++) { System.out.println("node "+i+": "+results.get(i).toXML()); }
Note: Internally uses extremely short-lived locks; the resulting potential lock contention is completely negligible.
Field Summary | |
static XQueryPool |
GLOBAL_POOL
A default pool (can be shared freely across threads without harm); global per class loader. |
Constructor Summary | |
XQueryPool()
Creates a new pool with default parameters. |
|
XQueryPool(int maxPoolEntries,
XQueryFactory factory)
Creates a new pool that uses the given factory on cache misses, and that can hold at most maxPoolEntries queries. |
Method Summary | |
XQuery |
getXQuery(File query)
Returns an XQuery for the given input query. |
XQuery |
getXQuery(ResourceResolver resolver,
String resourceName,
URI baseURI)
Returns an XQuery for the input stream obtained from
resolving the given resourceName against the given resolver. |
XQuery |
getXQuery(String query,
URI baseURI)
Returns an XQuery for the given input query, using the
given base URI. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final XQueryPool GLOBAL_POOL
Constructor Detail |
public XQueryPool()
public XQueryPool(int maxPoolEntries, XQueryFactory factory)
maxPoolEntries
queries.
maxPoolEntries
- the maximum number of queries this pool can hold before
starting to evict old queries. A value of zero effectively
disables pooling.factory
- the factory creating new XQuery instances on cache missesMethod Detail |
public XQuery getXQuery(File query) throws XQueryException, IOException
XQuery
for the given input query.
query
- the query to compile
IOException
- if an I/O error occured while reading the query.
XQueryException
- if the query cannot be compiled, e.g. due too a syntax error.public XQuery getXQuery(String query, URI baseURI) throws XQueryException
XQuery
for the given input query, using the
given base URI.
query
- the query to compilebaseURI
- the base URI of the query (may be null
)
XQueryException
- if the query cannot be compiled, e.g. due too a syntax error.public XQuery getXQuery(ResourceResolver resolver, String resourceName, URI baseURI) throws XQueryException, IOException, MissingResourceException
XQuery
for the input stream obtained from
resolving the given resourceName against the given resolver.
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 query (may be null
)
MissingResourceException
- if the resolver could not find the resource (unchecked exception)
IOException
- if an I/O error occured while reading the query from the stream
XQueryException
- if the query cannot be compiled, e.g. due too a syntax error
|
Nux 1.0a5 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |