Class OutboundConnectionCacheBlockingImpl<C extends Connection>
- java.lang.Object
-
- com.sun.corba.ee.impl.transport.connection.ConnectionCacheBase<C>
-
- com.sun.corba.ee.impl.transport.connection.ConnectionCacheBlockingBase<C>
-
- com.sun.corba.ee.impl.transport.connection.OutboundConnectionCacheBlockingImpl<C>
-
- All Implemented Interfaces:
ConnectionCache<C>
,OutboundConnectionCache<C>
@ManagedObject @Description("Outbound connection cache for connections opened by the client") public final class OutboundConnectionCacheBlockingImpl<C extends Connection> extends ConnectionCacheBlockingBase<C> implements OutboundConnectionCache<C>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<C,OutboundConnectionState<C>>
connectionMap
private java.util.Map<ContactInfo<C>,OutboundCacheEntry<C>>
entryMap
private java.util.concurrent.locks.ReentrantLock
lock
private int
maxParallelConnections
-
Fields inherited from class com.sun.corba.ee.impl.transport.connection.ConnectionCacheBlockingBase
totalBusy, totalIdle
-
Fields inherited from class com.sun.corba.ee.impl.transport.connection.ConnectionCacheBase
reclaimableConnections
-
-
Constructor Summary
Constructors Constructor Description OutboundConnectionCacheBlockingImpl(java.lang.String cacheType, int highWaterMark, int numberToReclaim, int maxParallelConnections, long ttl)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.private java.util.Map<C,OutboundConnectionState<C>>
connectionMap()
private void
decrementTotalBusy()
private void
decrementTotalIdle()
private void
display(java.lang.String m, java.lang.Object value)
private java.util.Map<ContactInfo<C>,OutboundCacheEntry<C>>
entryMap()
C
get(ContactInfo<C> cinfo)
Behaves the same asOutboundConnectionCache.get(ContactInfo, ConnectionFinder)
except that no connection finder is provided, so that step is ignored.C
get(ContactInfo<C> cinfo, ConnectionFinder<C> finder)
Return a Connection corresponding to the given ContactInfo.private OutboundConnectionState<C>
getConnectionState(ContactInfo<C> cinfo, OutboundCacheEntry<C> entry, C conn)
private OutboundCacheEntry<C>
getEntry(ContactInfo<C> cinfo)
private boolean
internalCanCreateNewConnection(OutboundCacheEntry<C> entry)
int
maxParallelConnections()
Configured maximum number of connections supported per ContactInfo.private void
msg(java.lang.String m)
private boolean
reclaimOrClose(OutboundConnectionState<C> cs, C conn)
void
release(C conn, int numResponsesExpected)
Release a Connection previously obtained from get.void
responseReceived(C conn)
Decrement the number of expected responses.protected java.lang.String
thisClassName()
private C
tryNewConnection(OutboundCacheEntry<C> entry, ContactInfo<C> cinfo)
-
Methods inherited from class com.sun.corba.ee.impl.transport.connection.ConnectionCacheBlockingBase
numberOfBusyConnections, numberOfConnections, numberOfIdleConnections, numberOfReclaimableConnections
-
Methods inherited from class com.sun.corba.ee.impl.transport.connection.ConnectionCacheBase
getCacheType, highWaterMark, numberToReclaim, reclaim, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.sun.corba.ee.spi.transport.connection.ConnectionCache
getCacheType, highWaterMark, numberOfBusyConnections, numberOfConnections, numberOfIdleConnections, numberOfReclaimableConnections, numberToReclaim
-
-
-
-
Field Detail
-
lock
private java.util.concurrent.locks.ReentrantLock lock
-
maxParallelConnections
private final int maxParallelConnections
-
entryMap
private java.util.Map<ContactInfo<C extends Connection>,OutboundCacheEntry<C extends Connection>> entryMap
-
connectionMap
private java.util.Map<C extends Connection,OutboundConnectionState<C extends Connection>> connectionMap
-
-
Method Detail
-
maxParallelConnections
@ManagedAttribute public int maxParallelConnections()
Description copied from interface:OutboundConnectionCache
Configured maximum number of connections supported per ContactInfo.- Specified by:
maxParallelConnections
in interfaceOutboundConnectionCache<C extends Connection>
- Returns:
- maximum number of connections
-
entryMap
@ManagedAttribute(id="cacheEntries") private java.util.Map<ContactInfo<C>,OutboundCacheEntry<C>> entryMap()
-
connectionMap
@ManagedAttribute(id="connections") private java.util.Map<C,OutboundConnectionState<C>> connectionMap()
-
thisClassName
protected java.lang.String thisClassName()
- Specified by:
thisClassName
in classConnectionCacheBase<C extends Connection>
-
canCreateNewConnection
public boolean canCreateNewConnection(ContactInfo<C> cinfo)
Description copied from interface:OutboundConnectionCache
Determine whether a new connection could be created by the ConnectionCache or not.- Specified by:
canCreateNewConnection
in interfaceOutboundConnectionCache<C extends Connection>
- Parameters:
cinfo
- info to use forConnection
- Returns:
- if a new connection can be created
-
internalCanCreateNewConnection
private boolean internalCanCreateNewConnection(OutboundCacheEntry<C> entry)
-
get
public C get(ContactInfo<C> cinfo) throws java.io.IOException
Description copied from interface:OutboundConnectionCache
Behaves the same asOutboundConnectionCache.get(ContactInfo, ConnectionFinder)
except that no connection finder is provided, so that step is ignored.- Specified by:
get
in interfaceOutboundConnectionCache<C extends Connection>
- Parameters:
cinfo
- info on Connection to get- Returns:
Connection
corresponding to the ContactInfo- Throws:
java.io.IOException
- if an error occurred
-
msg
@InfoMethod private void msg(java.lang.String m)
-
display
@InfoMethod private void display(java.lang.String m, java.lang.Object value)
-
get
public C get(ContactInfo<C> cinfo, ConnectionFinder<C> finder) throws java.io.IOException
Description copied from interface:OutboundConnectionCache
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.
- Specified by:
get
in interfaceOutboundConnectionCache<C extends Connection>
- Parameters:
cinfo
- info on Connection to getfinder
- Finder to use to search for Connection- Returns:
Connection
corresponding to the ContactInfo- Throws:
java.io.IOException
- if an error occurred
-
getEntry
private OutboundCacheEntry<C> getEntry(ContactInfo<C> cinfo) throws java.io.IOException
- Throws:
java.io.IOException
-
tryNewConnection
private C tryNewConnection(OutboundCacheEntry<C> entry, ContactInfo<C> cinfo) throws java.io.IOException
- Throws:
java.io.IOException
-
getConnectionState
private OutboundConnectionState<C> getConnectionState(ContactInfo<C> cinfo, OutboundCacheEntry<C> entry, C conn)
-
release
public void release(C conn, int numResponsesExpected)
Description copied from interface:OutboundConnectionCache
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.- Specified by:
release
in interfaceOutboundConnectionCache<C extends Connection>
- Parameters:
conn
- connection to releasenumResponsesExpected
- number of responses expected
-
responseReceived
public void responseReceived(C conn)
Decrement the number of expected responses. When a connection is idle and has no expected responses, it can be reclaimed.- Specified by:
responseReceived
in interfaceOutboundConnectionCache<C extends Connection>
- Parameters:
conn
- Connection that has received a response
-
reclaimOrClose
private boolean reclaimOrClose(OutboundConnectionState<C> cs, C conn)
-
close
public void close(C conn)
Close a connection, regardless of whether the connection is busy or not.- Specified by:
close
in interfaceConnectionCache<C extends Connection>
- Parameters:
conn
- connection to close
-
decrementTotalIdle
private void decrementTotalIdle()
-
decrementTotalBusy
private void decrementTotalBusy()
-
-