org.trippi.impl.base
Class ConfigurableSessionPool

java.lang.Object
  extended by java.lang.Thread
      extended by org.trippi.impl.base.ConfigurableSessionPool
All Implemented Interfaces:
java.lang.Runnable, TriplestoreSessionPool

public class ConfigurableSessionPool
extends java.lang.Thread
implements TriplestoreSessionPool

A configurable TriplestoreSessionPool that proactively increases pool size.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ConfigurableSessionPool(TriplestoreSessionFactory factory, int initialSize, int maxGrowth, int spareSessions)
          Initialize the pool and grow it to its initial size.
 
Method Summary
 void close()
          Close all sessions.
 void finalize()
          Call close() at garbage collection time in case it hasn't been called yet.
 TriplestoreSession get()
          Get a connection from the pool.
 int getFreeCount()
          Get the number of sessions not currently in use.
 int getInUseCount()
          Get the number of sessions currently in use.
 java.lang.String[] listTripleLanguages()
           
 java.lang.String[] listTupleLanguages()
           
 void release(TriplestoreSession session)
          Release a connection back to the pool.
 void run()
          Maintain the pool size.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConfigurableSessionPool

public ConfigurableSessionPool(TriplestoreSessionFactory factory,
                               int initialSize,
                               int maxGrowth,
                               int spareSessions)
                        throws TrippiException
Initialize the pool and grow it to its initial size. This also starts a background thread that maintains the pool's size.

Parameters:
initialSize - number of sessions to start with.
maxGrowth - max additional sessions to add. If -1, no limit will be placed on the size.
spareSessions - number of unused sessions to keep available. Zero means new sessions will only be created on demand. Note if maxGrowth is 0, the value of this parameter is inconsequential.
Throws:
TrippiException
Method Detail

listTripleLanguages

public java.lang.String[] listTripleLanguages()
Specified by:
listTripleLanguages in interface TriplestoreSessionPool

listTupleLanguages

public java.lang.String[] listTupleLanguages()
Specified by:
listTupleLanguages in interface TriplestoreSessionPool

get

public TriplestoreSession get()
                       throws TrippiException
Get a connection from the pool.

Specified by:
get in interface TriplestoreSessionPool
Returns:
a session, or null if none are available and growth isnt allowed.
Throws:
TrippiException - if there were no spare sessions and an attempt to create one on-demand failed.

release

public void release(TriplestoreSession session)
Release a connection back to the pool.

Specified by:
release in interface TriplestoreSessionPool

getInUseCount

public int getInUseCount()
Get the number of sessions currently in use.

Specified by:
getInUseCount in interface TriplestoreSessionPool

getFreeCount

public int getFreeCount()
Get the number of sessions not currently in use.

Specified by:
getFreeCount in interface TriplestoreSessionPool

run

public void run()
Maintain the pool size. This just ensures that pool growth occurs when necessary, checking every 1/4 of a second.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

close

public void close()
           throws TrippiException
Close all sessions. This also stops the pool maintenance thread. It should only be called when finished with the session pool.

Specified by:
close in interface TriplestoreSessionPool
Throws:
TrippiException

finalize

public void finalize()
              throws TrippiException
Call close() at garbage collection time in case it hasn't been called yet.

Overrides:
finalize in class java.lang.Object
Throws:
TrippiException