Class AGConnPool
- All Implemented Interfaces:
Closeable,AutoCloseable,ObjectPool<AGRepositoryConnection>
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,
AGPoolProp.warmup, true,
AGPoolPool.warmupIncludeStrings, true,
AGConnPool.warmupIncludeTriples, false);
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 ObjectPool.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 that have not been returned to the pool
will *not* be closed. Such connections will be closed immediately when
returned to the pool.
-
initialSizecan be used to pre-create a set number of connections. By default the pool only opens connections if needed. -
warmupcan be set totrueto force the server to read internal structures of the repository into memory, thus speeding up future requests. If requested, this will happen at pool creation time.warmupIncludeStringsandwarmupIncludeStringscan be set to false to exclude specific structures from the warmup operation.
- Since:
- v4.3.3
-
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated.voidclear()voidclose()static AGConnPoolCreate a pool from configuration properties.static AGConnPoolcreate(Map<AGConnProp, String> connProps, Map<AGPoolProp, String> poolProps) Create a pool from configuration properties.static AGConnPoolcreate(PooledObjectFactory<AGRepositoryConnection> factory, AGPoolConfig poolConfig) Creates a pool using a custom connection factory.voidensureIdle(int n) intintvoidvoidtoString()Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.pool2.ObjectPool
addObjects, invalidateObject
-
Method Details
-
create
public static AGConnPool create(PooledObjectFactory<AGRepositoryConnection> factory, AGPoolConfig poolConfig) Creates a pool using a custom connection factory.- Parameters:
factory- a connection factory.poolConfig- anAGPoolConfig- Returns:
- AGConnPool the connection pool object
-
create
public static AGConnPool create(Map<AGConnProp, String> connProps, Map<AGPoolProp, throws org.eclipse.rdf4j.repository.RepositoryExceptionString> poolProps) Create a pool from configuration properties.- Parameters:
connProps- keys areAGConnProppoolProps- keys areAGPoolProp- Returns:
- AGConnPool the connection pool object
- Throws:
org.eclipse.rdf4j.repository.RepositoryException- if an error occurs during pool creation
-
create
public static AGConnPool create(Object... keyValuePairs) throws org.eclipse.rdf4j.repository.RepositoryException Create a pool from configuration properties.- Parameters:
keyValuePairs- alternating key/value pairs where keys areAGConnPropandAGPoolProp- Returns:
AGConnPoolthe connection pool object- Throws:
org.eclipse.rdf4j.repository.RepositoryException- if an error occurs during pool creation
-
addObject
- Specified by:
addObjectin interfaceObjectPool<AGRepositoryConnection>- Throws:
Exception
-
borrowObject
public AGRepositoryConnection borrowObject() throws org.eclipse.rdf4j.repository.RepositoryException- Specified by:
borrowObjectin interfaceObjectPool<AGRepositoryConnection>- Throws:
org.eclipse.rdf4j.repository.RepositoryException
-
borrowConnection
Deprecated.UseborrowObject()instead.Same asborrowObject().- Returns:
- A connection.
-
clear
- Specified by:
clearin interfaceObjectPool<AGRepositoryConnection>- Throws:
Exception
-
getNumActive
- Specified by:
getNumActivein interfaceObjectPool<AGRepositoryConnection>- Throws:
UnsupportedOperationException
-
getNumIdle
- Specified by:
getNumIdlein interfaceObjectPool<AGRepositoryConnection>- Throws:
UnsupportedOperationException
-
invalidateObject
- Specified by:
invalidateObjectin interfaceObjectPool<AGRepositoryConnection>- Throws:
Exception
-
returnObject
- Specified by:
returnObjectin interfaceObjectPool<AGRepositoryConnection>- Throws:
Exception
-
ensureIdle
- Throws:
Exception
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceObjectPool<AGRepositoryConnection>
-
toString
-
borrowObject()instead.