Class AGConnPoolJndiFactory
- All Implemented Interfaces:
ObjectFactory
AGConnPool
.
The Commons-Pool library is required to use this package: Apache Commons Pool, commons-pool-1.5.6.jar. Note, this jar along with the agraph-java-client jar and all of its dependencies must be in the webserver's library for it to be able to load.
The properties supported for the connections are specified
by AGConnProp
.
The properties supported for the pooling are specified
by AGPoolProp
.
Note, when AutoCloseable.close()
is called
on an AGConnPool
,
connections that have not been returned will not be closed.
Also note, when a AGRepositoryConnection
from the pool is closed,
the AGRepository
and AGServer
will also be closed
since these are not shared with other AGRepositoryConnection
s.
Example Tomcat JNDI configuration, based on Tomcat HOW-TO create custom resource factories: In /WEB-INF/web.xml:
<resource-env-ref>
<description>AllegroGraph connection pool</description>
<resource-env-ref-name>connection-pool/agraph</resource-env-ref-name>
<resource-env-ref-type>com.franz.agraph.pool.AGConnPool</resource-env-ref-type>
</resource-env-ref>
Your code:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
AGConnPool pool = (AGConnPool) envCtx.lookup("connection-pool/agraph");
AGRepositoryConnection conn = pool.borrowConnection();
try {
...
conn.commit();
} finally {
conn.close();
// or equivalently
pool.returnObject(conn);
}
Tomcat's resource factory:
<Context ...>
...
<Resource name="connection-pool/agraph"
auth="Container"
type="com.franz.agraph.pool.AGConnPool"
factory="com.franz.agraph.pool.AGConnPoolJndiFactory"
username="test"
password="xyzzy"
serverUrl="http://localhost:10035"
catalog="/"
repository="my_repo"
session="TX"
testOnBorrow="true"
initialSize="5"
maxIdle="10"
maxActive="40"
maxWait="60000"/>
...
</Context>
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.
- Since:
- v4.3.3
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetObjectInstance
(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) From the objReference
, gets theRefAddr
names and values, converts to Maps and returnsAGConnPool.create(Object...)
.
-
Constructor Details
-
AGConnPoolJndiFactory
public AGConnPoolJndiFactory()
-
-
Method Details
-
getObjectInstance
From the objReference
, gets theRefAddr
names and values, converts to Maps and returnsAGConnPool.create(Object...)
.- Specified by:
getObjectInstance
in interfaceObjectFactory
-