com.sun.grizzly.connectioncache.impl.transport
Class OutboundConnectionCacheBlockingImpl<C extends Closeable>

java.lang.Object
  extended by com.sun.grizzly.connectioncache.impl.transport.ConnectionCacheBase<C>
      extended by com.sun.grizzly.connectioncache.impl.transport.OutboundConnectionCacheBlockingImpl<C>
All Implemented Interfaces:
ConnectionCache<C>, OutboundConnectionCache<C>

public final class OutboundConnectionCacheBlockingImpl<C extends Closeable>
extends ConnectionCacheBase<C>
implements OutboundConnectionCache<C>


Field Summary
protected  int totalBusy
           
protected  int totalIdle
           
 
Fields inherited from class com.sun.grizzly.connectioncache.impl.transport.ConnectionCacheBase
logger, reclaimableConnections
 
Constructor Summary
OutboundConnectionCacheBlockingImpl(String cacheType, int highWaterMark, int numberToReclaim, int maxParallelConnections, Logger logger)
           
 
Method Summary
 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, 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.
 com.sun.grizzly.connectioncache.impl.transport.OutboundConnectionCacheBlockingImpl.ConnectionState<C> getConnectionState(ContactInfo<C> cinfo, com.sun.grizzly.connectioncache.impl.transport.OutboundConnectionCacheBlockingImpl.CacheEntry<C> entry, C conn)
           
 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()
           
 
Methods inherited from class com.sun.grizzly.connectioncache.impl.transport.ConnectionCacheBase
debug, dprint, dprintStatistics, 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.grizzly.connectioncache.spi.transport.ConnectionCache
getCacheType, highWaterMark, numberOfBusyConnections, numberOfConnections, numberOfIdleConnections, numberOfReclaimableConnections, numberToReclaim
 

Field Detail

totalBusy

protected int totalBusy

totalIdle

protected int totalIdle
Constructor Detail

OutboundConnectionCacheBlockingImpl

public OutboundConnectionCacheBlockingImpl(String cacheType,
                                           int highWaterMark,
                                           int numberToReclaim,
                                           int maxParallelConnections,
                                           Logger logger)
Method Detail

maxParallelConnections

public int maxParallelConnections()
Description copied from interface: OutboundConnectionCache
Configured maximum number of connections supported per ContactInfo.

Specified by:
maxParallelConnections in interface OutboundConnectionCache<C extends Closeable>
Returns:
maximum number of connections supported per ContactInfo

thisClassName

protected String thisClassName()
Specified by:
thisClassName in class ConnectionCacheBase<C extends Closeable>

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 interface OutboundConnectionCache<C extends Closeable>
Parameters:
cinfo - a ContactInfo
Returns:
true if new connection could be created by ConnectionCache, otherwise false.

get

public C get(ContactInfo<C> cinfo)
                        throws IOException
Description copied from interface: OutboundConnectionCache
Behaves the same as get( ContactInfo, ConnectionFinder ) except that no connection finder is provided, so that step is ignored.

Specified by:
get in interface OutboundConnectionCache<C extends Closeable>
Parameters:
cinfo - a ContactInfo
Returns:
a connection
Throws:
IOException

getConnectionState

public com.sun.grizzly.connectioncache.impl.transport.OutboundConnectionCacheBlockingImpl.ConnectionState<C> getConnectionState(ContactInfo<C> cinfo,
                                                                                                                                com.sun.grizzly.connectioncache.impl.transport.OutboundConnectionCacheBlockingImpl.CacheEntry<C> entry,
                                                                                                                                C conn)

get

public C get(ContactInfo<C> cinfo,
             ConnectionFinder<C> finder)
                        throws IOException
Description copied from interface: OutboundConnectionCache
Return a Connection corresponding to the given ContactInfo. This works as follows: Note that creating a new connection requires EITHER: We will always return a Connection for a get call UNLESS we have no existing connection and an attempt to create a new connection fails. In this case, the IOException thrown by ContactInfo.create is propagated out of this method.

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 interface OutboundConnectionCache<C extends Closeable>
Parameters:
cinfo - a ContactInfo
finder - a ConnectionFinder
Returns:
a connection
Throws:
IOException

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 interface OutboundConnectionCache<C extends Closeable>
Parameters:
conn - a connection
numResponsesExpected - number of connections in which a response is 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 interface OutboundConnectionCache<C extends Closeable>
Parameters:
conn - a connection

close

public void close(C conn)
Close a connection, regardless of whether the connection is busy or not.

Specified by:
close in interface ConnectionCache<C extends Closeable>
Parameters:
conn - a connection

numberOfConnections

public long numberOfConnections()
Description copied from interface: ConnectionCache
Total number of connections currently managed by the cache.

Returns:
number of connections currently managed by the cache

numberOfIdleConnections

public long numberOfIdleConnections()
Description copied from interface: ConnectionCache
Number of idle connections; that is, connections for which the number of get/release or responseReceived/responseProcessed calls are equal.

Returns:
number of idle connections

numberOfBusyConnections

public long numberOfBusyConnections()
Description copied from interface: ConnectionCache
Number of non-idle connections. Normally, busy+idle==total, but this may not be strictly true due to concurrent updates to the connection cache.

Returns:
number of busy connections

numberOfReclaimableConnections

public long numberOfReclaimableConnections()
Description copied from interface: ConnectionCache
Number of idle connections that are reclaimable. Such connections are not in use, and are not waiting to handle any responses.

Returns:
number of idle connections that are reclaimable


Copyright © 2010 SUN Microsystems. All Rights Reserved.