Synergex.util.SWPManager

java.lang.Object
   Synergex.util.SWPManager
public class SWPManager extends Object

The SWPManager class is used to create, shut down, and otherwise manage pools of connections to xfServerPlus. This class uses a singleton pattern: only one instance of the class will be created in your application. For details on using Java connection pooling, see Understanding Java pooling and Implementing Java pooling.

Methods

static synchronized public SWPManager getInstance() throws xfPoolException

Instantiates a pool of connections to xfServerPlus or gets an instance of an already instantiated pool. The first time this method is called, a connection pool is created using the settings in the default pooling properties file (xfPool.properties). If there are multiple pools defined, all are started. Once the pool has been created, subsequent calls to getInstance() get an instance of the pool.

static synchronized public SWPManager getInstance(String propFile) throws xfPoolException 

Instantiates a pool of connections to xfServerPlus or gets an instance of an already instantiated pool. Use this method to specify a non‑default pooling properties file using a path and filename. The first time this method is called, a connection pool is created using the settings in the pooling properties file specified with propFile. If there are multiple pools defined, all are started. Once the pool has been created, subsequent calls to getInstance() get an instance of the pool.

propFile – the full path and filename of the pooling properties file

static synchronized public SWPManager getInstance(Properties poolProp) throws xfPoolException 

Instantiates a pool of connections to xfServerPlus or gets an instance of an already instantiated pool. Use this method to specify a non‑default pooling properties file using a Properties object. The first time this method is called, a connection pool is created using the settings in the pooling properties file specified with poolProp. (You must first create the Properties object and load it.) If there are multiple pools defined, all are started. Once the pool has been created, subsequent calls to getInstance() get an instance of the pool.

poolProp – a java.util.Properties object that represents the pooling properties file

public void resetPoolProperties(String poolID) throws xfPoolException

Rereads settings in the pooling properties file that are associated with the specified pool ID. Settings in the xfNetLink Java properties file used by that pool will also be reread. Use this method when you need to update the pooling properties file or the xfNetLink Java properties file and don’t want to completely shut down and restart the application.

This method closes down all of the free connections in the specified pool, and then restarts the pool with the minimum number of connections, using the new settings. Connections that are in use when resetPoolProperties() is called will be discarded when they are released (even if poolReturn is set to “true”), so that all connections will use the new settings.

poolID – the ID of the pool for which properties need to be reset

public void returnToMinimum(String poolID)

Returns the size of the pool to the minimum specified in the pooling properties file by discarding unused connections. Use this method only when poolReturn is set to “true” in the pooling properties file; it has no effect when poolReturn is set to “false”.

poolID – the ID of the pool that should be reset to the minimum number of connections

public synchronized void shutdown()

Closes all free connections and all in‑use connections in all pools defined in the pooling properties file, and then destroys the pools. The next call to getInstance() will restart the pools.

public synchronized void shutdown(String poolID)

Closes all free connections in the specified pool and all in‑use connections in that pool, and then destroys the pool. The next call to getInstance() will restart the pool.

poolID – the ID of the pool to be shut down

public synchronized void shutdownInPool()

Closes all free connections in all pools defined in the pooling properties file, and then destroys the pools. Connections that are in use when shutdownInPool() is called are terminated when they are released. The next call to getInstance() will restart the pools.

public synchronized void shutdownInPool(String poolID)

Closes all free connections in the specified pool, and then destroys the pool. Connections that are in use when shutdownInPool() is called are terminated when they are released. The next call to getInstance() will restart the pool.

poolID – the ID of the pool to be shut down

public SWPConnect getConnection(String poolID)

Returns a connection from the specified pool. If no connections are available and connectWaitTimeout is not set, a null is returned immediately; else, if no connections are available and connectWaitTimout is set, null and an exception are returned. This method is called by the Java code that is generated when you create Java class wrappers; do not call this method directly. (See Specifying time‑out values for details on connectWaitTimeout.)

poolID – the ID of the pool from which to get a connection

public void freeConnection(String poolID, SWPConnect connection)

Frees the specified connection from the specified pool. This method is called by the Java code that is generated when you create Java class wrappers; do not call this method directly.

poolID – the ID of the pool

connection – the instance of the connection returned with getConnection()

public int getPoolCount(String poolID)

Returns the number of free connections in the specified pool.

poolID – the ID of the pool

public int getPoolInUseCount(String poolID)

Returns the number of connections in the specified pool that are currently in use.

poolID – the ID of the pool

public int getPoolTotalCount(String poolID)

Returns the number of free connections plus the number of connections currently in use in the specified pool.

poolID – the ID of the pool

Usage

The getInstance() method of the SWPManager class instantiates the pool the first time it is called, then gets an instance of the pool on subsequent calls. If there are multiple pools defined in the pooling properties file, they are all created on the first call to getInstance().

To use the default pooling properties file (which is named xfPool.properties and located either in the Java application directory or in the directory required by your web server and servlet container) call the getInstance() method that passes no parameters.

To specify a non‑default pooling properties file, use either of the other two getInstance() methods.

For example, to specify the full path and filename of the pooling properties file as a String,

SWPManager poolMgr = SWPManager.getInstance("c:\\files\\myPool.properties");

Or, to use a Properties object to specify the pooling properties file,

Properties poolProps = new Properties();
FileReader fr = new FileReader("c:\\files\\myPool.properties");
poolProps.load(fr);
SWPManager poolMgr = SWPManager.getInstance(poolProps);           

See also Using your JAR file with connection pooling for sample code that uses some of the methods in the SWPManager class.