public final class OutboundConnectionCacheImpl<C extends Connection> extends ConnectionCacheBase<C> implements OutboundConnectionCache<C>
A connection is obtained through the get method, and released back to the cache through the release method. Note that a connection that is released may still be expecting a response, in which case the connection is NOT eligible for reclamation. If a connection is released to the cache while expecting a response, the connection must me made available for reclamation by calling responseReceived. XXX Should a get/release cycle expect at most one response? Should it support more than one response? Are there cases where we don't know in advance how many responses are expected?
A connection basically represents some sort of communication channel, but few requirements are placed on the connection. Basically the ability to close a connection is required in order for reclamation to work.
Also we need the ContactInfo as a factory for the Connection.
| Modifier and Type | Field and Description |
|---|---|
protected AtomicInteger |
totalBusy |
protected AtomicInteger |
totalIdle |
reclaimableConnections| Constructor and Description |
|---|
OutboundConnectionCacheImpl(String cacheType,
int highWaterMark,
int numberToReclaim,
int maxParallelConnections,
long ttl) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canCreateNewConnection(ContactInfo<C> cinfo)
Determine whether a new connection could be created by the
ConnectionCache or not.
|
void |
close(C conn)
Close a connection, regardless of whether the connection is busy
or not.
|
C |
get(ContactInfo<C> cinfo)
Behaves the same as get( ContactInfo
|
C |
get(ContactInfo<C> cinfo,
ConnectionFinder<C> finder)
Return a Connection corresponding to the given ContactInfo.
|
int |
maxParallelConnections()
Configured maximum number of connections supported per ContactInfo.
|
long |
numberOfBusyConnections()
Number of non-idle connections.
|
long |
numberOfConnections()
Total number of connections currently managed by the cache.
|
long |
numberOfIdleConnections()
Number of idle connections; that is, connections for which the number of
get/release or responseReceived/responseProcessed calls are equal.
|
long |
numberOfReclaimableConnections()
Number of idle connections that are reclaimable.
|
void |
release(C conn,
int numResponsesExpected)
Release a Connection previously obtained from get.
|
void |
responseReceived(C conn)
Decrement the number of expected responses.
|
protected String |
thisClassName() |
getCacheType, highWaterMark, numberToReclaim, reclaim, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetCacheType, highWaterMark, numberOfBusyConnections, numberOfConnections, numberOfIdleConnections, numberOfReclaimableConnections, numberToReclaimprotected final AtomicInteger totalBusy
protected final AtomicInteger totalIdle
public OutboundConnectionCacheImpl(String cacheType, int highWaterMark, int numberToReclaim, int maxParallelConnections, long ttl)
public int maxParallelConnections()
OutboundConnectionCachemaxParallelConnections in interface OutboundConnectionCache<C extends Connection>protected String thisClassName()
thisClassName in class ConnectionCacheBase<C extends Connection>public C get(ContactInfo<C> cinfo, ConnectionFinder<C> finder) throws IOException
OutboundConnectionCacheIt is possible that the cache contains connections that no longer connect to their destination. In this case, it is the responsibility of the client of the cache to close the broken connection as they are detected. Connection reclamation may also handle the cleanup, but note that a broken connection with pending responses will never be reclaimed.
Note that the idle and busy connection collections that are passed to the finder are unmodifiable collections. They have iterators that return connections in LRU order, with the least recently used connection first. This is done to aid a finder that wishes to consider load balancing in its determination of an appropriate connection.
get in interface OutboundConnectionCache<C extends Connection>IOExceptionpublic C get(ContactInfo<C> cinfo) throws IOException
OutboundConnectionCacheget in interface OutboundConnectionCache<C extends Connection>IOExceptionpublic void release(C conn, int numResponsesExpected)
OutboundConnectionCacherelease in interface OutboundConnectionCache<C extends Connection>public void responseReceived(C conn)
responseReceived in interface OutboundConnectionCache<C extends Connection>public void close(C conn)
close in interface ConnectionCache<C extends Connection>public boolean canCreateNewConnection(ContactInfo<C> cinfo)
OutboundConnectionCachecanCreateNewConnection in interface OutboundConnectionCache<C extends Connection>public long numberOfConnections()
ConnectionCachepublic long numberOfIdleConnections()
ConnectionCachepublic long numberOfBusyConnections()
ConnectionCachepublic long numberOfReclaimableConnections()
ConnectionCacheCopyright © 2017–2019 Eclipse Foundation. All rights reserved.