org.osesb.objectpools
Class SAXKeyedPoolFactory

java.lang.Object
  extended by org.osesb.objectpools.KeyedObjectPoolFactory
      extended by org.osesb.objectpools.SAXKeyedPoolFactory

public class SAXKeyedPoolFactory
extends KeyedObjectPoolFactory

This class is a factory for object pools of JAXP compliant SAX Parsers, with different configurations (heterogeneous). This class is is a thread-safe singleton, so only one instance of SAXKeyedPoolFactory and its associated KeyedObjectPool instance will exist per class loader.

Pools of SAX parsers are useful in multi-threaded environments, such as MDBs, where there are multiple clients using SAX parsers. Instead of repeatedly creating SAX parsers, clients call getObject() on a pool of SAX Parsers and call returnObject() when finished parsing.

PooledParserAccessHelper is a helper class for accessing pooled SAX and DOM parsers.

This class uses org.apache.commons.pool.impl.GenericKeyedObjectPool as the pool implementation.It is a good model for creating other heterogeneous object pools, which are pools that contain different kinds of objects.

There is a known issue with validating against XML schemas using parsers from a pool implemented using the org.apache.commons.pool package. See org.osesb.objectpools.test.ThreadedPooledValidatingSAXParserTest. For now, the framework uses non-pooled SAX parsers for:

This factory uses a configuration file to load a SAX parser pool. The configuration contains a pool content model, which defines the characteristics of the pool and jaxp-sax content models, which define the properties for the pooled parsers (e.g. namespaceAware and validating).

Object pool configurations must be stand-alone configuration files with all configurations specified in-line.

Object pool configurations cannot be embedded in another configuration file and then referenced externally using XPath. In addition, all pooled object configurations must be specified in-line and cannot use the 'configFile' attribute to redirect the configuration to an external file.

This factory's getPool() method loads the configured instance of the keyed, SAX parser pool using the following plan to load the SAXKeyedPoolFactory configuration file:

  1. The configuration file given by the System property named ObjectPoolConstants.SAXKEYEDPOOLCONFIGFILE_PROPERTY.
  2. The configuration file given by the ObjectPoolConstants.SAXKEYEDPOOLCONFIGFILE_PROPERTY entry in a properties file named ObjectPoolConstants.OBJECTPOOLCONFIGURATIONS_PROPERTIES_FILE.
  3. The default configuration file given by ObjectPoolConstants.DEFAULT_KEYEDPOOLEDSAXPARSER_CONFIGFILE.

The configuration for the framework's default keyed SAX parser pool is config/keyed-pooled-sax-parser-config.xml, which looks like:

<key-pooled-sax-parsers>
          <pool-configuration>
              <!-- an optional name for the pool -->
              <poolName>osESB Keyed SAX Parser Pool</poolName>
              <!-- a heartbeatInterval for the pool in seconds-->
              <heartbeatInterval>300</heartbeatInterval>
              <!-- debugFlag -->
              <debugFlag>true</debugFlag>
              <!-- parameters that are specific to the pool implementation go here -->
              <!-- these are the config properties for jakarta-commons-pooling -->
              <!-- GenericObjectPool Config -->
              <maxIdle></maxIdle>
              <!-- No limit to the number of objects -->
              <maxActive>-1</maxActive>
              <maxWait>-1</maxWait>
              <!-- Grow the pool when a borrowobject() fails -->
              <whenExhaustedAction>2</whenExhaustedAction>
              <testOnBorrow>false</testOnBorrow>
              <testOnReturn>false</testOnReturn>
              <testWhileIdle>false</testWhileIdle>
              <!-- check for idle objects every 6 minutes (normally) -->
              <timeBetweenEvictionRunsMillis>360000</timeBetweenEvictionRunsMillis>
              <numTestsPerEvictionRun></numTestsPerEvictionRun>
              <!-- evict objects idle more than 5 minutes (normally) -->
              <minEvictableIdleTimeMillis>300000</minEvictableIdleTimeMillis>
              <!-- display pool startup message -->
              <displayStartupMessageFlag>true</displayStartupMessageFlag>
          </pool-configuration>
          <!-- non-validating, namespaceaware is false -->
          <jaxp-configuration poolKey="namespaceaware-false">
              <!-- the class that is pooled, not required for XML Parser pools -->
              <!-- The pooled class is determined by the parser implementation in the class path.-->
              <pooled-class></pooled-class>
              <!-- use parser factory defaults - ignore parser property elements -->
              <useDefaultParserConfigurationFlag>false</useDefaultParserConfigurationFlag>
              <!-- do not use parser factory defaults - set these properties excplicitly -->
              <!-- used when validating against schems -->
              <!-- namespaceAware should always be true, validating or not -->
              <namespaceAware>false</namespaceAware>
              <validating>false</validating>
              <!-- null for dtd -->
              <schemaLanguage>http://www.w3.org/2001/XMLSchema</schemaLanguage>
          </jaxp-configuration>
          <!-- non-validating, namespaceaware is true -->
          <jaxp-configuration poolKey="namespaceaware-true">
              <!-- the class that is pooled, not required for XML Parser pools -->
              <!-- The pooled class is determined by the parser implementation in the class path.-->
              <pooled-class></pooled-class>
              <!-- use parser factory defaults - ignore parser property elements -->
              <useDefaultParserConfigurationFlag>false</useDefaultParserConfigurationFlag>
              <!-- do not use parser factory defaults - set these properties excplicitly -->
              <!-- used when validating against schems -->
              <!-- namespaceAware should always be true, validating or not -->
              <namespaceAware>true</namespaceAware>
              <validating>false</validating>
              <!-- null for dtd -->
              <schemaLanguage>http://www.w3.org/2001/XMLSchema</schemaLanguage>
          </jaxp-configuration>
          <jaxp-configuration poolKey="validating">
              <!-- The class that is pooled, not required for XML Parser pools. -->
              <!-- The pooled class is determined by the parser implementation in the class path.-->
              <pooled-class></pooled-class>
              <!-- use parser factory defaults - ignore parser property elements -->
              <useDefaultParserConfigurationFlag>false</useDefaultParserConfigurationFlag>
              <!-- do not use parser factory defaults - set these properties excplicitly -->
              <!-- used when validating against schems -->
              <!-- namespaceAware should always be true, validating or not -->
              <namespaceAware>true</namespaceAware>
              <validating>true</validating>
              <!-- null for dtd -->
              <schemaLanguage>http://www.w3.org/2001/XMLSchema</schemaLanguage>
          </jaxp-configuration>
      </key-pooled-sax-parsers>
 

Since:
Version .9

Nested Class Summary
protected static class SAXKeyedPoolFactory.JAXPSAXPoolableObjectFactory
          Inner class that implements org.apache.commons.pool.KeyedPoolableObjectFactory, which is instantiated by the enclosing class and passed to GenericObjectPool's constructor.
 
Field Summary
protected static KeyedObjectPoolConfiguration keyedObjectPoolConfiguration
          The pool configuration as a whole including the ObjectPoolConfiguration and the pooled object configuration(s).
protected static SAXKeyedPoolFactory poolFactoryInstance
          Singleton pattern - thread-safe construction.
protected static KeyedObjectPool poolInstance
          The instance of the objectpool we will create.
protected static java.lang.String thisClassName
          The full name of this class
 
Fields inherited from class org.osesb.objectpools.KeyedObjectPoolFactory
log
 
Constructor Summary
protected SAXKeyedPoolFactory()
          Singleton pattern - cannot be instantiated directly.
 
Method Summary
static KeyedObjectPoolFactory getInstance()
          Singleton pattern - - returns the instance of this class.
 KeyedObjectPoolConfiguration getKeyedObjectPoolConfiguration()
          Return the pool configuration as a whole including the ObjectPoolConfiguration and the pooled object configuration(s).
 KeyedObjectPool getPool()
          Construct (if necessary) and return the single instance of the heterogeneous SAX parser pool using the following plan to load the SAXKeyedPoolFactory configuration file:

The configuration file given by the System property named ObjectPoolConstants.SAXKEYEDPOOLCONFIGFILE_PROPERTY. The configuration file given by the ObjectPoolConstants.SAXKEYEDPOOLCONFIGFILE_PROPERTY entry in a properties file named ObjectPoolConstants.OBJECTPOOLCONFIGURATIONS_PROPERTIES_FILE. The default configuration file given by ObjectPoolConstants.DEFAULT_KEYEDPOOLEDSAXPARSER_CONFIGFILE.

static void main(java.lang.String[] args)
          Main method for testing and sandboxing.
 void resetPoolInstance()
          Close the pool and reset the poolInstance.
 
Methods inherited from class org.osesb.objectpools.KeyedObjectPoolFactory
getPoolConfig
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

poolInstance

protected static KeyedObjectPool poolInstance
The instance of the objectpool we will create.


keyedObjectPoolConfiguration

protected static KeyedObjectPoolConfiguration keyedObjectPoolConfiguration
The pool configuration as a whole including the ObjectPoolConfiguration and the pooled object configuration(s).


thisClassName

protected static java.lang.String thisClassName
The full name of this class


poolFactoryInstance

protected static SAXKeyedPoolFactory poolFactoryInstance
Singleton pattern - thread-safe construction.

Constructor Detail

SAXKeyedPoolFactory

protected SAXKeyedPoolFactory()
Singleton pattern - cannot be instantiated directly.

Method Detail

getInstance

public static KeyedObjectPoolFactory getInstance()
Singleton pattern - - returns the instance of this class. Callers can then call getPool() to get the object pool.

Returns:
the singleton instance of this class.

getPool

public KeyedObjectPool getPool()
                        throws java.lang.Exception
Construct (if necessary) and return the single instance of the heterogeneous SAX parser pool using the following plan to load the SAXKeyedPoolFactory configuration file:

  1. The configuration file given by the System property named ObjectPoolConstants.SAXKEYEDPOOLCONFIGFILE_PROPERTY.
  2. The configuration file given by the ObjectPoolConstants.SAXKEYEDPOOLCONFIGFILE_PROPERTY entry in a properties file named ObjectPoolConstants.OBJECTPOOLCONFIGURATIONS_PROPERTIES_FILE.
  3. The default configuration file given by ObjectPoolConstants.DEFAULT_KEYEDPOOLEDSAXPARSER_CONFIGFILE.

Specified by:
getPool in class KeyedObjectPoolFactory
Returns:
an instance of the configured heterogeneous object pool.
Throws:
java.lang.Exception - if a fatal error is encountered while instantiating the object pool.

getKeyedObjectPoolConfiguration

public KeyedObjectPoolConfiguration getKeyedObjectPoolConfiguration()
Return the pool configuration as a whole including the ObjectPoolConfiguration and the pooled object configuration(s). Note that keyedObjectPoolConfiguration is null until getPool() is invoked on the concrete implementation of this class.

Specified by:
getKeyedObjectPoolConfiguration in class KeyedObjectPoolFactory

resetPoolInstance

public void resetPoolInstance()
Close the pool and reset the poolInstance.

Specified by:
resetPoolInstance in class KeyedObjectPoolFactory

main

public static void main(java.lang.String[] args)
Main method for testing and sandboxing.

Parameters:
args -