Franz Inc, AllegroGraph

com.franz.agraph.pool
Class AGConnPool<ObjectPoolType extends org.apache.commons.pool.ObjectPool>

java.lang.Object
  extended by com.franz.util.Closer
      extended by com.franz.agraph.pool.AGConnPool<ObjectPoolType>
Type Parameters:
ObjectPoolType -
All Implemented Interfaces:
Closeable, org.apache.commons.pool.ObjectPool

public class AGConnPool<ObjectPoolType extends org.apache.commons.pool.ObjectPool>
extends Closer
implements org.apache.commons.pool.ObjectPool, Closeable

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.initialSize, 2);
        AGRepositoryConnection conn = pool.borrowConnection();
        try {
                ...
                conn.commit();
        } finally {
                conn.close();
                // or equivalently
                pool.returnObject(conn);
        }
 

This pool delegates the pooling implementation to another pool (usually GenericObjectPool), adding borrowConnection(), which also wraps the AGRepositoryConnection so that Closeable.close() will call returnObject(Object) instead of actually closing.

Warning: Since the objects borrowed from this class are wrapped, you can not use them directly with the delegate pool. The delegate pool should only be used for its pooling implementation and configuration.

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 Closer.close() is called on a AGConnPool, connections will be closed whether they are idle (have been returned) or not. This is different from GenericObjectPool.close().

Since:
v4.3.3

Constructor Summary
AGConnPool(ObjectPoolType delegate, AGConnFactory factory, AGPoolConfig config)
           
 
Method Summary
 void addObject()
           
 AGRepositoryConnection borrowConnection()
           
 Object borrowObject()
           
 void clear()
           
static AGConnPool create(AGConnFactory fact, AGPoolConfig poolConfig)
          A GenericObjectPool is used.
static AGConnPool create(Map<AGConnProp,String> connProps, Map<AGPoolProp,String> poolProps)
          Create a pool from configuration properties.
static AGConnPool create(Object... keyValuePairs)
          Create a pool from configuration properties.
 void ensureIdle(int n)
           
 int getNumActive()
           
 int getNumIdle()
           
 void invalidateObject(Object obj)
           
 void returnObject(Object obj)
           
 void setFactory(org.apache.commons.pool.PoolableObjectFactory obj)
          Deprecated. 
 String toString()
           
 Object unwrap(Object obj)
           
 
Methods inherited from class com.franz.util.Closer
close, Close, Close, Close, Close, Close, close, Close, Close, closeAll, closeLater, remove
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.pool.ObjectPool
close
 
Methods inherited from interface com.franz.util.Closeable
close
 

Constructor Detail

AGConnPool

public AGConnPool(ObjectPoolType delegate,
                  AGConnFactory factory,
                  AGPoolConfig config)
See Also:
create(Object...)
Method Detail

create

public static AGConnPool create(AGConnFactory fact,
                                AGPoolConfig poolConfig)
A GenericObjectPool is used.


create

public static AGConnPool create(Map<AGConnProp,String> connProps,
                                Map<AGPoolProp,String> poolProps)
                         throws RepositoryException
Create a pool from configuration properties. A GenericObjectPool is used.

Parameters:
connProps - keys are AGConnProp
poolProps - keys are AGPoolProp
Throws:
RepositoryException

create

public static AGConnPool create(Object... keyValuePairs)
                         throws RepositoryException
Create a pool from configuration properties. A GenericObjectPool is used.

Parameters:
keyValuePairs - alternating key/value pairs where keys are AGConnProp and AGPoolProp
Throws:
RepositoryException

addObject

public void addObject()
               throws Exception,
                      IllegalStateException,
                      UnsupportedOperationException
Specified by:
addObject in interface org.apache.commons.pool.ObjectPool
Throws:
Exception
IllegalStateException
UnsupportedOperationException

borrowObject

public Object borrowObject()
                    throws Exception,
                           NoSuchElementException,
                           IllegalStateException
Specified by:
borrowObject in interface org.apache.commons.pool.ObjectPool
Throws:
Exception
NoSuchElementException
IllegalStateException

borrowConnection

public AGRepositoryConnection borrowConnection()
                                        throws RepositoryException
Throws:
RepositoryException

clear

public void clear()
           throws Exception,
                  UnsupportedOperationException
Specified by:
clear in interface org.apache.commons.pool.ObjectPool
Throws:
Exception
UnsupportedOperationException

getNumActive

public int getNumActive()
                 throws UnsupportedOperationException
Specified by:
getNumActive in interface org.apache.commons.pool.ObjectPool
Throws:
UnsupportedOperationException

getNumIdle

public int getNumIdle()
               throws UnsupportedOperationException
Specified by:
getNumIdle in interface org.apache.commons.pool.ObjectPool
Throws:
UnsupportedOperationException

invalidateObject

public void invalidateObject(Object obj)
                      throws Exception
Specified by:
invalidateObject in interface org.apache.commons.pool.ObjectPool
Throws:
Exception

returnObject

public void returnObject(Object obj)
                  throws Exception
Specified by:
returnObject in interface org.apache.commons.pool.ObjectPool
Throws:
Exception

unwrap

public Object unwrap(Object obj)

setFactory

@Deprecated
public void setFactory(org.apache.commons.pool.PoolableObjectFactory obj)
                throws IllegalStateException,
                       UnsupportedOperationException
Deprecated. 

Specified by:
setFactory in interface org.apache.commons.pool.ObjectPool
Throws:
IllegalStateException
UnsupportedOperationException

ensureIdle

public void ensureIdle(int n)
                throws Exception
Throws:
Exception

toString

public String toString()
Overrides:
toString in class Closer

Copyright © 2008-2011 Franz Inc.