public class AGConnPool extends Closer implements org.apache.commons.pool.ObjectPool, AutoCloseable
AGRepositoryConnections.
The recommended way to create a pool is by create(Object...)
or by configuring a AGConnPoolJndiFactory with your appserver.
AGConnPool pool = AGConnPool.create(
AGConnProp.serverUrl, "http://localhost:10035",
AGConnProp.username, "test",
AGConnProp.password, "xyzzy",
AGConnProp.catalog, "/",
AGConnProp.repository, "my_repo",
AGConnProp.session, AGConnProp.Session.DEDICATED,
AGPoolProp.shutdownHook, true,
AGPoolProp.maxActive, 10,
AGPoolProp.initialSize, 2);
AGRepositoryConnection conn = pool.borrowConnection();
try {
...
conn.commit();
} finally {
conn.close();
// or equivalently
pool.returnObject(conn);
}
This pool delegates the pooling implementation to another
pool (a GenericObjectPool).
When Connections are borrowed,
they are wrapped so that AutoCloseable.close()
will call returnObject(Object) instead of actually closing.
Closing the connection pool is important because server sessions will
stay active until AGConnProp.sessionLifetime.
The option to use a Runtime shutdownHook is built-in with AGPoolProp.shutdownHook.
Another option is to use ServletContextListener - this is appropriate if the
agraph jar is deployed within your webapp and not with the webserver.
With tomcat, a Lifecycle Listener can be configured, but the implementation to do this
is not included in this library.
Note, when close() is called
on a AGConnPool,
connections will be closed whether they are
idle (have been returned) or not.
This is different from GenericObjectPool.close().
| Modifier and Type | Method and Description |
|---|---|
void |
addObject() |
AGRepositoryConnection |
borrowConnection() |
Object |
borrowObject() |
void |
clear() |
void |
close()
Closes all resources registered with
Closer.closeLater(AutoCloseable). |
static AGConnPool |
create(AGConnFactory factory,
AGPoolConfig poolConfig)
A
GenericObjectPool is used. |
static AGConnPool |
create(Map<AGConnProp,String> connProps,
Map<AGPoolProp,String> poolProps)
Create a pool from configuration properties.
|
static AGConnPool |
create(Object... keyValuePairs)
Create a pool from configuration properties.
|
void |
ensureIdle(int n) |
int |
getNumActive() |
int |
getNumIdle() |
void |
invalidateObject(Object obj) |
void |
returnObject(Object obj) |
void |
setFactory(org.apache.commons.pool.PoolableObjectFactory obj)
Deprecated.
|
String |
toString() |
static Object |
unwrap(Object obj) |
close, close, closeLater, removepublic static AGConnPool create(AGConnFactory factory, AGPoolConfig poolConfig)
GenericObjectPool is used.factory - an AGConnFactorypoolConfig - an AGPoolConfigpublic static AGConnPool create(Map<AGConnProp,String> connProps, Map<AGPoolProp,String> poolProps) throws RepositoryException
connProps - keys are AGConnProppoolProps - keys are AGPoolPropRepositoryException - if an error occurs during pool creationpublic static AGConnPool create(Object... keyValuePairs) throws RepositoryException
keyValuePairs - alternating key/value pairs where keys are AGConnProp and AGPoolPropAGConnPool the connection pool objectRepositoryException - if an error occurs during pool creationpublic void addObject()
throws Exception,
IllegalStateException,
UnsupportedOperationException
addObject in interface org.apache.commons.pool.ObjectPoolExceptionIllegalStateExceptionUnsupportedOperationExceptionpublic Object borrowObject() throws Exception, NoSuchElementException, IllegalStateException
borrowObject in interface org.apache.commons.pool.ObjectPoolExceptionNoSuchElementExceptionIllegalStateExceptionpublic AGRepositoryConnection borrowConnection() throws RepositoryException
RepositoryExceptionpublic void clear()
throws Exception,
UnsupportedOperationException
clear in interface org.apache.commons.pool.ObjectPoolExceptionUnsupportedOperationExceptionpublic int getNumActive()
throws UnsupportedOperationException
getNumActive in interface org.apache.commons.pool.ObjectPoolUnsupportedOperationExceptionpublic int getNumIdle()
throws UnsupportedOperationException
getNumIdle in interface org.apache.commons.pool.ObjectPoolUnsupportedOperationExceptionpublic void invalidateObject(Object obj) throws Exception
invalidateObject in interface org.apache.commons.pool.ObjectPoolExceptionpublic void returnObject(Object obj) throws Exception
returnObject in interface org.apache.commons.pool.ObjectPoolException@Deprecated public void setFactory(org.apache.commons.pool.PoolableObjectFactory obj) throws IllegalStateException, UnsupportedOperationException
setFactory in interface org.apache.commons.pool.ObjectPoolIllegalStateExceptionUnsupportedOperationExceptionpublic void close()
CloserCloser.closeLater(AutoCloseable).close in interface AutoCloseableclose in interface org.apache.commons.pool.ObjectPoolclose in class CloserCopyright © 2017 Franz Inc.. All rights reserved.