Class AGConnPool

java.lang.Object
com.franz.agraph.pool.AGConnPool
All Implemented Interfaces:
Closeable, AutoCloseable, ObjectPool<AGRepositoryConnection>

public class AGConnPool extends Object implements ObjectPool<AGRepositoryConnection>, AutoCloseable
Pooling for 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.

In addition to standard commons-pool parameters this class supports some other features:
  • 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 to true 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 and warmupIncludeStrings can be set to false to exclude specific structures from the warmup operation.
Since:
v4.3.3