org.logicalcobwebs.proxool
Class Prototyper

java.lang.Object
  extended by org.logicalcobwebs.proxool.Prototyper

public class Prototyper
extends java.lang.Object

Responsible for prototyping connections for all pools

Since:
Proxool 0.8
Version:
$Revision: 1.12 $, $Date: 2006/01/16 23:10:41 $
Author:
bill, $Author: billhorsman $ (current maintainer)

Field Summary
private  boolean cancel
          Calling cancel will set this to true and stop all current prototyping immediately
private  ConnectionBuilderIF connectionBuilder
          The builder that will create *real* connections for us.
private  long connectionCount
           
private  ConnectionPool connectionPool
           
private  int connectionsBeingMade
          The number of connections currently being made (actually in progress)
private  java.lang.Object lock
           
private  Log log
           
private  long nextConnectionId
          This allows us to have a unique ID for each connection
private  boolean sweepNeeded
           
 
Constructor Summary
Prototyper(ConnectionPool connectionPool)
           
 
Method Summary
protected  ProxyConnection buildConnection(int status, java.lang.String creator)
          Build a new connection
 void cancel()
          Cancel all current prototyping
protected  void checkSimultaneousBuildThrottle()
          Checks whether we are currently already building too many connections
protected  void connectionRemoved()
          This needs to be called _everytime_ a connection is removed.
 java.lang.String getAlias()
          The alias of the pool we are prototyping for
 long getConnectionCount()
          The total number of connections, including those being built right now
private  ConnectionPoolDefinitionIF getDefinition()
          Utility method
protected  boolean isSweepNeeded()
           
 boolean quickRefuse()
          Give a quick answer to whether we should attempt to build a connection.
protected  boolean sweep()
          Trigger prototyping immediately
protected  void triggerSweep()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connectionPool

private ConnectionPool connectionPool

log

private Log log

connectionCount

private long connectionCount

lock

private final java.lang.Object lock

sweepNeeded

private boolean sweepNeeded

nextConnectionId

private long nextConnectionId
This allows us to have a unique ID for each connection


cancel

private boolean cancel
Calling cancel will set this to true and stop all current prototyping immediately


connectionsBeingMade

private int connectionsBeingMade
The number of connections currently being made (actually in progress)


connectionBuilder

private ConnectionBuilderIF connectionBuilder
The builder that will create *real* connections for us. Currently initialized to the default implementation until we fully support pluggable ConnectionBuilders

Constructor Detail

Prototyper

public Prototyper(ConnectionPool connectionPool)
Method Detail

isSweepNeeded

protected boolean isSweepNeeded()

triggerSweep

protected void triggerSweep()

sweep

protected boolean sweep()
Trigger prototyping immediately

Returns:
true if something was prototyped

buildConnection

protected ProxyConnection buildConnection(int status,
                                          java.lang.String creator)
                                   throws java.sql.SQLException,
                                          ProxoolException
Build a new connection

Parameters:
status - the initial status it will be created as (this allows us to create it as ACTIVE and avoid another thread grabbing it before we can)
creator - for log audit
Returns:
the new connection
Throws:
java.sql.SQLException
ProxoolException

connectionRemoved

protected void connectionRemoved()
This needs to be called _everytime_ a connection is removed.


checkSimultaneousBuildThrottle

protected void checkSimultaneousBuildThrottle()
                                       throws java.sql.SQLException
Checks whether we are currently already building too many connections

Throws:
java.sql.SQLException - if the throttle has been reached

getConnectionCount

public long getConnectionCount()
The total number of connections, including those being built right now

Returns:
connectionCount;

getDefinition

private ConnectionPoolDefinitionIF getDefinition()
Utility method

Returns:
definition

cancel

public void cancel()
Cancel all current prototyping


getAlias

public java.lang.String getAlias()
The alias of the pool we are prototyping for

Returns:
alias

quickRefuse

public boolean quickRefuse()
Give a quick answer to whether we should attempt to build a connection. This can be quicker if we are massively overloaded rather than cycling through each connection in the pool to see if it's free

Returns:
true if it's okay to attempt to get a connection, false if we should give up now. Just because this method returns true it doesn't guarantee that one will be available. There is a slight risk that we might tell the client to give up when a connection could become available in the next few milliseconds but our policy is to refuse connections quickly when overloaded.