|
Nux 1.0a5 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnux.xom.pool.XSLTransformPool
Efficient thread-safe pool/cache of XOM XSLTransform
objects,
creating and holding at most maxPoolEntries
XSLTransform
objects (each representing a compiled stylesheet). 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 XSLTransform instance, in particul for complex transforms 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):
XSLTransform trans = XSLTransformPool.GLOBAL_POOL.getTransform(new File("/tmp/test.xsl")); Document doc = BuilderPool.GLOBAL_POOL.getBuilder(false).build(new File("/tmp/test.xml")); Nodes nodes = trans.transform(doc); for (int i=0; i < nodes.size(); i++) { System.out.println("node "+i+": "+nodes.get(i).toXML()); }
Note: Internally uses extremely short-lived locks; the resulting potential lock contention is completely negligible.
Field Summary | |
static XSLTransformPool |
GLOBAL_POOL
A default pool (can be shared freely across threads without harm); global per class loader. |
Constructor Summary | |
XSLTransformPool()
Creates a new pool with default parameters. |
|
XSLTransformPool(int maxPoolEntries,
XSLTransformFactory factory)
Creates a new pool that uses the given factory on cache misses, and that can hold at most maxPoolEntries stylesheets. |
Method Summary | |
XSLTransform |
getTransform(Document stylesheet)
Returns an XSLTransform for the given stylesheet. |
XSLTransform |
getTransform(File stylesheet)
Returns an XSLTransform for the given stylesheet. |
XSLTransform |
getTransform(ResourceResolver resolver,
String resourceName,
URI baseURI)
Returns an XSLTransform for the input stream obtained from
resolving the given resourceName against the given resolver. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final XSLTransformPool GLOBAL_POOL
Constructor Detail |
public XSLTransformPool()
public XSLTransformPool(int maxPoolEntries, XSLTransformFactory factory)
maxPoolEntries
stylesheets.
maxPoolEntries
- the maximum number of stylesheets this pool can hold before
starting to evict old stylesheets. A value of zero effectively
disables pooling.factory
- the factory creating new XSLTransform instances on cache missesMethod Detail |
public XSLTransform getTransform(Document stylesheet) throws XSLException
XSLTransform
for the given stylesheet.
stylesheet
- the stylesheet to compile
XSLException
- if the XSLTransform can't be created, e.g. because of an XSL syntax error.public XSLTransform getTransform(File stylesheet) throws XSLException, ParsingException, IOException
XSLTransform
for the given stylesheet.
stylesheet
- the stylesheet to compile
IOException
- if an I/O error occurs while reading from the stream
ParsingException
- if the stylesheet is not well-formed XML
XSLException
- if the XSLTransform can't be created, e.g. because of an XSL syntax error.public XSLTransform getTransform(ResourceResolver resolver, String resourceName, URI baseURI) throws XSLException, ParsingException, IOException, MissingResourceException
XSLTransform
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 transform (may be null
)
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 the stylesheet is not well-formed XML
XSLException
- if the XSLTransform can't be created, e.g. because of an XSL syntax error.
|
Nux 1.0a5 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |