Package org.apache.http.impl.conn.tsccm
Class RouteSpecificPool
java.lang.Object
org.apache.http.impl.conn.tsccm.RouteSpecificPool
public class RouteSpecificPool extends Object
A connection sub-pool for a specific route, used by
ConnPoolByRoute.
The methods in this class are unsynchronized. It is expected that the
containing pool takes care of synchronization.-
Field Summary
Fields Modifier and Type Field Description protected LinkedList<BasicPoolEntry>freeEntriesThe list of free entries.protected intmaxEntriesthe maximum number of entries allowed for this poolprotected intnumEntriesThe number of created entries.protected HttpRouterouteThe route this pool is for.protected Queue<WaitingThread>waitingThreadsThe list of threads waiting for this pool. -
Constructor Summary
Constructors Constructor Description RouteSpecificPool(HttpRoute route, int maxEntries)Creates a new route-specific pool. -
Method Summary
Modifier and Type Method Description BasicPoolEntryallocEntry(Object state)Obtains a free entry from this pool, if one is available.voidcreatedEntry(BasicPoolEntry entry)Indicates creation of an entry for this pool.booleandeleteEntry(BasicPoolEntry entry)Deletes an entry from this pool.voiddropEntry()Forgets about an entry from this pool.voidfreeEntry(BasicPoolEntry entry)Returns an allocated entry to this pool.intgetCapacity()Return remaining capacity of this poolintgetEntryCount()Obtains the number of entries.intgetMaxEntries()Obtains the maximum number of entries allowed for this pool.HttpRoutegetRoute()Obtains the route for which this pool is specific.booleanhasThread()Checks whether there is a waiting thread in this pool.booleanisUnused()Indicates whether this pool is unused.WaitingThreadnextThread()Returns the next thread in the queue.voidqueueThread(WaitingThread wt)Adds a waiting thread.voidremoveThread(WaitingThread wt)Removes a waiting thread, if it is queued.
-
Field Details
-
route
The route this pool is for. -
maxEntries
protected final int maxEntriesthe maximum number of entries allowed for this pool -
freeEntries
The list of free entries. This list is managed LIFO, to increase idle times and allow for closing connections that are not really needed. -
waitingThreads
The list of threads waiting for this pool. -
numEntries
protected int numEntriesThe number of created entries.
-
-
Constructor Details
-
RouteSpecificPool
Creates a new route-specific pool.- Parameters:
route- the route for which to poolmaxEntries- the maximum number of entries allowed for this pool
-
-
Method Details
-
getRoute
Obtains the route for which this pool is specific.- Returns:
- the route
-
getMaxEntries
public final int getMaxEntries()Obtains the maximum number of entries allowed for this pool.- Returns:
- the max entry number
-
isUnused
public boolean isUnused()Indicates whether this pool is unused. A pool is unused if there is neither an entry nor a waiting thread. All entries count, not only the free but also the allocated ones.- Returns:
trueif this pool is unused,falseotherwise
-
getCapacity
public int getCapacity()Return remaining capacity of this pool- Returns:
- capacity
-
getEntryCount
public final int getEntryCount()Obtains the number of entries. This includes not only the free entries, but also those that have been created and are currently issued to an application.- Returns:
- the number of entries for the route of this pool
-
allocEntry
Obtains a free entry from this pool, if one is available.- Returns:
- an available pool entry, or
nullif there is none
-
freeEntry
Returns an allocated entry to this pool.- Parameters:
entry- the entry obtained fromallocEntryor presented tocreatedEntry
-
createdEntry
Indicates creation of an entry for this pool. The entry will not be added to the list of free entries, it is only recognized as belonging to this pool now. It can then be passed tofreeEntry.- Parameters:
entry- the entry that was created for this pool
-
deleteEntry
Deletes an entry from this pool. Only entries that are currently free in this pool can be deleted. Allocated entries can not be deleted.- Parameters:
entry- the entry to delete from this pool- Returns:
trueif the entry was found and deleted, orfalseif the entry was not found
-
dropEntry
public void dropEntry()Forgets about an entry from this pool. This method is used to indicate that an entryallocatedfrom this pool has been lost and will not be returned. -
queueThread
Adds a waiting thread. This pool makes no attempt to match waiting threads with pool entries. It is the caller's responsibility to check that there is no entry before adding a waiting thread.- Parameters:
wt- the waiting thread
-
hasThread
public boolean hasThread()Checks whether there is a waiting thread in this pool.- Returns:
trueif there is a waiting thread,falseotherwise
-
nextThread
Returns the next thread in the queue.- Returns:
- a waiting thread, or
nullif there is none
-
removeThread
Removes a waiting thread, if it is queued.- Parameters:
wt- the waiting thread
-