Class AGConnPool
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ObjectPool<AGRepositoryConnection>
AGRepositoryConnection
s.
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.
-
initialSize
can be used to pre-create a set number of connections. By default the pool only opens connections if needed. -
warmup
can be set totrue
to 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.warmupIncludeStrings
andwarmupIncludeStrings
can be set to false to exclude specific structures from the warmup operation.
- Since:
- v4.3.3
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Deprecated.void
clear()
void
close()
static AGConnPool
Create a pool from configuration properties.static AGConnPool
create
(Map<AGConnProp, String> connProps, Map<AGPoolProp, String> poolProps) Create a pool from configuration properties.static AGConnPool
create
(PooledObjectFactory<AGRepositoryConnection> factory, AGPoolConfig poolConfig) Creates a pool using a custom connection factory.void
ensureIdle
(int n) int
int
void
void
toString()
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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 RepositoryExceptionString> poolProps) Create a pool from configuration properties.- Parameters:
connProps
- keys areAGConnProp
poolProps
- keys areAGPoolProp
- Returns:
- AGConnPool the connection pool object
- Throws:
RepositoryException
- if an error occurs during pool creation
-
create
Create a pool from configuration properties.- Parameters:
keyValuePairs
- alternating key/value pairs where keys areAGConnProp
andAGPoolProp
- Returns:
AGConnPool
the connection pool object- Throws:
RepositoryException
- if an error occurs during pool creation
-
addObject
- Specified by:
addObject
in interfaceObjectPool<AGRepositoryConnection>
- Throws:
Exception
-
borrowObject
- Specified by:
borrowObject
in interfaceObjectPool<AGRepositoryConnection>
- Throws:
RepositoryException
-
borrowConnection
Deprecated.UseborrowObject()
instead.Same asborrowObject()
.- Returns:
- A connection.
-
clear
- Specified by:
clear
in interfaceObjectPool<AGRepositoryConnection>
- Throws:
Exception
-
getNumActive
- Specified by:
getNumActive
in interfaceObjectPool<AGRepositoryConnection>
- Throws:
UnsupportedOperationException
-
getNumIdle
- Specified by:
getNumIdle
in interfaceObjectPool<AGRepositoryConnection>
- Throws:
UnsupportedOperationException
-
invalidateObject
- Specified by:
invalidateObject
in interfaceObjectPool<AGRepositoryConnection>
- Throws:
Exception
-
returnObject
- Specified by:
returnObject
in interfaceObjectPool<AGRepositoryConnection>
- Throws:
Exception
-
ensureIdle
- Throws:
Exception
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceObjectPool<AGRepositoryConnection>
-
toString
-
borrowObject()
instead.