Interface OutboundConnectionCache<C extends Connection>
- All Superinterfaces:
ConnectionCache<C>
- All Known Implementing Classes:
OutboundConnectionCacheBlockingImpl
,OutboundConnectionCacheImpl
This cache places minimal requirements on the Connections that it contains:
- A Connection must implement a close() method. This is called when idle connections are reclaimed.
- A Connection must be usable as a HashMap key.
- There must be a ContactInfo class that is used to create Connection instances. The ContactInfo class must support a create() method that returns a Connection.
- The ContactInfo must be usable as a HashMap key.
- All instances created from a ContactInfo are equal; that is, any request sent to a particular ContactInfo can used an instance created from that ContactInfo. For example, in the CORBA case, IP host and port is not always sufficient: we may also need the Codeset type that indicates how Strings are encoded. Basically, protocols (like GIOP) that bind session state to a Connection may need more than transport information in the ContactInfo.
Some simple methods are provided for monitoring the state of the cache: numbers of busy and idle connections, and the total number of connections in the cache.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canCreateNewConnection
(ContactInfo<C> cinfo) Determine whether a new connection could be created by the ConnectionCache or not.get
(ContactInfo<C> cinfo) Behaves the same asget(ContactInfo, ConnectionFinder)
except that no connection finder is provided, so that step is ignored.get
(ContactInfo<C> cinfo, ConnectionFinder<C> finder) Return a Connection corresponding to the given ContactInfo.int
Configured maximum number of connections supported per ContactInfo.void
Release a Connection previously obtained from get.void
responseReceived
(C conn) Inform the cache that a response has been received on a particular connection.Methods inherited from interface com.sun.corba.ee.spi.transport.connection.ConnectionCache
close, getCacheType, highWaterMark, numberOfBusyConnections, numberOfConnections, numberOfIdleConnections, numberOfReclaimableConnections, numberToReclaim
-
Method Details
-
maxParallelConnections
int maxParallelConnections()Configured maximum number of connections supported per ContactInfo.- Returns:
- maximum number of connections
-
canCreateNewConnection
Determine whether a new connection could be created by the ConnectionCache or not.- Parameters:
cinfo
- info to use forConnection
- Returns:
- if a new connection can be created
-
get
Return a Connection corresponding to the given ContactInfo. This works as follows:- Call the finder. If it returns non-null, use that connection; (Note that this may be a new connection, created in the finder). The finder SHOULD NOT create a new connection if canCreateNewConnection returns false, but this is advisory.
- otherwise, Use an idle connection, if one is available;
- otherwise, create a new connection, if not too many connections are open;
- otherwise, use a busy connection.
- there is no existing connection for the ContactInfo
- OR the total number of connections in the cache is less than the HighWaterMark and the number of connections for this ContactInfo is less than MaxParallelConnections.
It 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.
- Parameters:
cinfo
- info on Connection to getfinder
- Finder to use to search for Connection- Returns:
Connection
corresponding to the ContactInfo- Throws:
IOException
- if an error occurred
-
get
Behaves the same asget(ContactInfo, ConnectionFinder)
except that no connection finder is provided, so that step is ignored.- Parameters:
cinfo
- info on Connection to get- Returns:
Connection
corresponding to the ContactInfo- Throws:
IOException
- if an error occurred
-
release
Release a Connection previously obtained from get. Connections that have been released as many times as they have been returned by get are idle; otherwise a Connection is busy. Some number of responses (usually 0 or 1) may be expected ON THE SAME CONNECTION even for an idle connection. We maintain a count of the number of outstanding responses we expect for protocols that return the response on the same connection on which the request was received. This is necessary to prevent reclamation of a Connection that is idle, but still needed to send responses to old requests.- Parameters:
conn
- connection to releasenumResponseExpected
- number of responses expected
-
responseReceived
Inform the cache that a response has been received on a particular connection. This must also be called in the event that no response is received, but the client times out waiting for a response, and decides to abandon the request.When a Connection is idle, and has no pending responses, it is eligible for reclamation.
- Parameters:
conn
- Connection that has received a response
-