public class ConnectionBin
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected static class |
ConnectionBin.SumClass |
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
binName
This is the bin name which this connection pool belongs to
|
static int |
CONNECTION_DESTROY |
static int |
CONNECTION_POOLEMPTY |
static int |
CONNECTION_WITHINBOUNDS |
protected int |
inUseConnections
This is the number of connections in this bin that are connected; immaterial whether they are
in use or in a pool somewhere.
|
protected boolean |
isAlive
True if this bin is alive still
|
protected int |
localMax
This is the local maximum number of active connections allowed for this bin
|
protected int |
maxActiveConnections
This is the maximum number of active connections allowed for this bin
|
protected static java.util.Random |
randomNumberGenerator
Random number
|
protected int |
referencingPools
This is the number of active referring connection pools.
|
protected int |
reservedConnections
This is the number of connections in this bin that have been reserved - that is, they
are promised to various callers, but those callers have not yet committed to obtaining them.
|
protected java.lang.String |
serviceName
The (anonymous) service name
|
protected java.lang.String |
serviceTypeName
Service type name
|
protected static java.lang.String |
serviceTypePrefix
The service type prefix for connection bins
|
protected java.lang.String |
targetCalcLockName
The target calculation lock name
|
protected static java.lang.String |
targetCalcLockPrefix
The target calculation lock prefix
|
Constructor and Description |
---|
ConnectionBin(IThreadContext threadContext,
java.lang.String throttlingGroupName,
java.lang.String binName)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected static java.lang.String |
buildServiceTypeName(java.lang.String throttlingGroupName,
java.lang.String binName) |
protected static java.lang.String |
buildTargetCalcLockName(java.lang.String throttlingGroupName,
java.lang.String binName) |
java.lang.String |
getBinName()
Get the bin name.
|
boolean |
hasPooledConnection(java.util.concurrent.atomic.AtomicInteger poolCount)
Check only if there's a pooled connection, and make moves to take it from the pool.
|
void |
noteConnectionCreation()
Note the creation of an active connection that belongs to this bin.
|
void |
noteConnectionDestroyed()
Note the destruction of an active connection that belongs to this bin.
|
void |
noteConnectionReturnedToPool(java.util.concurrent.atomic.AtomicInteger poolCount)
Note a connection returned to the pool.
|
protected static byte[] |
pack(int target,
int inUse) |
void |
poll(IThreadContext threadContext)
Poll this bin
|
int |
shouldPooledConnectionBeDestroyed(java.util.concurrent.atomic.AtomicInteger poolCount)
Figure out whether we are currently over target or not for this bin, and whether a
connection should be pulled from the pool and destroyed.
|
boolean |
shouldReturnedConnectionBeDestroyed()
Figure out whether we are currently over target or not for this bin.
|
void |
shutDown(IThreadContext threadContext)
Shut down the bin, and release everything that is waiting on it.
|
void |
undoPooledConnectionDecision(java.util.concurrent.atomic.AtomicInteger poolCount)
Undo the decision to destroy a pooled connection.
|
void |
undoReservation(int recommendation,
java.util.concurrent.atomic.AtomicInteger poolCount)
Undo what we had decided to do before.
|
protected static int |
unpackInUse(byte[] data) |
protected static int |
unpackTarget(byte[] data) |
void |
updateMaxActiveConnections(int maxActiveConnections)
Update the maximum number of active connections.
|
int |
waitConnectionAvailable(java.util.concurrent.atomic.AtomicInteger poolCount,
IBreakCheck breakCheck)
Wait for a connection to become available, in the context of an existing connection pool.
|
protected boolean isAlive
protected final java.lang.String binName
protected final java.lang.String serviceTypeName
protected final java.lang.String serviceName
protected final java.lang.String targetCalcLockName
protected int maxActiveConnections
protected int localMax
protected int reservedConnections
protected int inUseConnections
protected int referencingPools
protected static final java.lang.String serviceTypePrefix
protected static final java.lang.String targetCalcLockPrefix
protected static final java.util.Random randomNumberGenerator
public static final int CONNECTION_DESTROY
public static final int CONNECTION_POOLEMPTY
public static final int CONNECTION_WITHINBOUNDS
public ConnectionBin(IThreadContext threadContext, java.lang.String throttlingGroupName, java.lang.String binName) throws ManifoldCFException
ManifoldCFException
protected static java.lang.String buildServiceTypeName(java.lang.String throttlingGroupName, java.lang.String binName)
protected static java.lang.String buildTargetCalcLockName(java.lang.String throttlingGroupName, java.lang.String binName)
public java.lang.String getBinName()
public void updateMaxActiveConnections(int maxActiveConnections)
public int waitConnectionAvailable(java.util.concurrent.atomic.AtomicInteger poolCount, IBreakCheck breakCheck) throws java.lang.InterruptedException, BreakException
poolCount
- is the number of connections in the pool times the number of bins per connection.
This parameter is only ever changed in this class!!java.lang.InterruptedException
BreakException
public void undoReservation(int recommendation, java.util.concurrent.atomic.AtomicInteger poolCount)
recommendation
- is the decision returned by waitForConnection() above.public void noteConnectionCreation()
public boolean shouldReturnedConnectionBeDestroyed()
public int shouldPooledConnectionBeDestroyed(java.util.concurrent.atomic.AtomicInteger poolCount)
public boolean hasPooledConnection(java.util.concurrent.atomic.AtomicInteger poolCount)
public void undoPooledConnectionDecision(java.util.concurrent.atomic.AtomicInteger poolCount)
public void noteConnectionReturnedToPool(java.util.concurrent.atomic.AtomicInteger poolCount)
public void noteConnectionDestroyed()
public void poll(IThreadContext threadContext) throws ManifoldCFException
ManifoldCFException
public void shutDown(IThreadContext threadContext) throws ManifoldCFException
ManifoldCFException
protected static int unpackTarget(byte[] data)
protected static int unpackInUse(byte[] data)
protected static byte[] pack(int target, int inUse)