|
Franz Inc, AllegroGraph | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.franz.agraph.pool.AGConnPoolJndiFactory
public class AGConnPoolJndiFactory
JNDI factory for 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 Closeable.close()
is called
on an AGConnPool
,
connections will be closed whether they are
idle (have been returned) or not.
This is different from GenericObjectPool.close()
.
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:
Your code:
<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>
Tomcat's resource factory:
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);
}
<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.
Constructor Summary | |
---|---|
AGConnPoolJndiFactory()
|
Method Summary | |
---|---|
Object |
getObjectInstance(Object obj,
Name name,
Context nameCtx,
Hashtable<?,?> environment)
From the obj Reference , gets the RefAddr
names and values, converts to Maps and
returns AGConnPool.create(Object...) . |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AGConnPoolJndiFactory()
Method Detail |
---|
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment) throws Exception
Reference
, gets the RefAddr
names and values, converts to Maps and
returns AGConnPool.create(Object...)
.
getObjectInstance
in interface ObjectFactory
Exception
|
Copyright © 2008-2012 Franz Inc. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |