org.apache.manifoldcf.crawler.connectors.webcrawler
Class ThrottledFetcher.ConnectionBin

java.lang.Object
  extended by org.apache.manifoldcf.crawler.connectors.webcrawler.ThrottledFetcher.ConnectionBin
Enclosing class:
ThrottledFetcher

protected static class ThrottledFetcher.ConnectionBin
extends java.lang.Object

Connection pool for a bin. An instance of this class tracks the connections that are pooled and that are in use for a specific bin.


Field Summary
protected  java.lang.String binName
          This is the bin name which this connection pool belongs to
protected  java.lang.Integer connectionWait
          This object is what we synchronize on when we are waiting on a connection to free up for this bin.
protected  java.util.HashMap freePool
          This map contains ThrottledConnection objects that are in the pool, and are not in use.
protected  int inUseConnections
          This is the number of connections in this bin that are signed out and presumably in use
protected  long lastFetchTime
          This is the last time a fetch was done on this bin
 
Constructor Summary
ThrottledFetcher.ConnectionBin(java.lang.String binName)
          Constructor.
 
Method Summary
 void addToPool(ThrottledFetcher.ThrottledConnection tc)
          Put a connection into the pool.
 int countConnections()
          Count connections that are in use.
protected  boolean existsInPool(ThrottledFetcher.ThrottledConnection tc)
          Check if a connection exists in the pool already.
 ThrottledFetcher.ThrottledConnection findConnection(int maxConnections, ThrottledFetcher.ConnectionBin[] binNames, java.lang.String protocol, java.lang.String server, int port, PageCredentials authentication, java.lang.String trustStoreString)
          This method is called only when there is no existing connection yet identified that can be used for contacting the server and port specified.
 boolean flushIdleConnections(long idleTimeout)
          Flush any idle connections.
 java.lang.String getBinName()
          Get the bin name.
 long getLastFetchTime()
          Get the last fetch time.
protected  ThrottledFetcher.ThrottledConnection getPoolConnection()
          Grab a connection from the current pool.
 void insureWithinLimits(int maxConnections, ThrottledFetcher.ThrottledConnection existingConnection)
          Verify that this bin is within limits.
 void noteConnectionCreation()
          Note the creation of an active connection that belongs to this bin.
 void noteConnectionDestruction()
          Note the destruction of an active connection that belongs to this bin.
 void sanityCheck()
           
 void setLastFetchTime(long currentTime)
          Note a new time for connection fetch for this pool.
 void takeFromPool(ThrottledFetcher.ThrottledConnection tc)
          Activate a connection that should be in the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

binName

protected java.lang.String binName
This is the bin name which this connection pool belongs to


inUseConnections

protected int inUseConnections
This is the number of connections in this bin that are signed out and presumably in use


lastFetchTime

protected long lastFetchTime
This is the last time a fetch was done on this bin


connectionWait

protected java.lang.Integer connectionWait
This object is what we synchronize on when we are waiting on a connection to free up for this bin. This is a separate object, because we also want to protect the integrity of the ConnectionBin object itself, for which we'll use the ConnectionBin's synchronizer.


freePool

protected java.util.HashMap freePool
This map contains ThrottledConnection objects that are in the pool, and are not in use.

Constructor Detail

ThrottledFetcher.ConnectionBin

public ThrottledFetcher.ConnectionBin(java.lang.String binName)
Constructor.

Method Detail

getBinName

public java.lang.String getBinName()
Get the bin name.


noteConnectionCreation

public void noteConnectionCreation()
Note the creation of an active connection that belongs to this bin. The slots all must have been reserved prior to the connection being created.


noteConnectionDestruction

public void noteConnectionDestruction()
Note the destruction of an active connection that belongs to this bin.


takeFromPool

public void takeFromPool(ThrottledFetcher.ThrottledConnection tc)
Activate a connection that should be in the pool. Removes the connection from the pool.


addToPool

public void addToPool(ThrottledFetcher.ThrottledConnection tc)
Put a connection into the pool.


insureWithinLimits

public void insureWithinLimits(int maxConnections,
                               ThrottledFetcher.ThrottledConnection existingConnection)
                        throws ThrottledFetcher.PoolException
Verify that this bin is within limits.

Throws:
ThrottledFetcher.PoolException

findConnection

public ThrottledFetcher.ThrottledConnection findConnection(int maxConnections,
                                                           ThrottledFetcher.ConnectionBin[] binNames,
                                                           java.lang.String protocol,
                                                           java.lang.String server,
                                                           int port,
                                                           PageCredentials authentication,
                                                           java.lang.String trustStoreString)
                                                    throws ThrottledFetcher.PoolException
This method is called only when there is no existing connection yet identified that can be used for contacting the server and port specified. This method returns a connection if a matching one can be found; otherwise it returns null. If a matching connection is found, it is activated before it is returned. That removes the connection from all pools in which it lives.

Throws:
ThrottledFetcher.PoolException

setLastFetchTime

public void setLastFetchTime(long currentTime)
Note a new time for connection fetch for this pool.

Parameters:
currentTime - is the time the fetch was started.

getLastFetchTime

public long getLastFetchTime()
Get the last fetch time.

Returns:
the time.

countConnections

public int countConnections()
Count connections that are in use.

Returns:
connections that are in use.

flushIdleConnections

public boolean flushIdleConnections(long idleTimeout)
Flush any idle connections.

Returns:
true if the connection bin is now, in fact, empty.

getPoolConnection

protected ThrottledFetcher.ThrottledConnection getPoolConnection()
Grab a connection from the current pool. This does not remove the connection from the pool; it just sets it up so that later methods can do that.


existsInPool

protected boolean existsInPool(ThrottledFetcher.ThrottledConnection tc)
Check if a connection exists in the pool already.


sanityCheck

public void sanityCheck()