FileDocCategorySizeDatePackage
ConnectionCacheBase.javaAPI DocExample5734Tue May 29 16:57:04 BST 2007com.sun.xml.ws.transport.tcp.connectioncache.impl.transport

ConnectionCacheBase

public abstract class ConnectionCacheBase extends Object implements com.sun.xml.ws.transport.tcp.connectioncache.spi.transport.ConnectionCache

Fields Summary
private final String
cacheType
protected final Logger
logger
private final int
highWaterMark
private final int
numberToReclaim
protected com.sun.xml.ws.transport.tcp.connectioncache.spi.concurrent.ConcurrentQueue
reclaimableConnections
Constructors Summary
ConnectionCacheBase(String cacheType, int highWaterMark, int numberToReclaim, Logger logger)


	if (cacheType == null)
	    throw new IllegalArgumentException( "cacheType must not be null" ) ;

	if (highWaterMark < 0)
	    throw new IllegalArgumentException( "highWaterMark must be non-negative" ) ;

	if (numberToReclaim < 1)
	    throw new IllegalArgumentException( "numberToReclaim must be at least 1" ) ;

	if (logger == null)
	    throw new IllegalArgumentException( "logger must not be null" ) ;

	this.cacheType = cacheType ;
	this.logger = logger ;
	this.highWaterMark = highWaterMark ;
	this.numberToReclaim = numberToReclaim ;
    
Methods Summary
protected booleandebug()


       
	return logger.isLoggable( Level.FINER ) ;
    
protected final voiddprint(java.lang.String msg)

	logger.finer(thisClassName() + msg);
    
public voiddprintStatistics()

	dprint( ".stats:"
	       + " idle=" + numberOfIdleConnections() 
	       + " reclaimable=" + numberOfReclaimableConnections() 
	       + " busy=" + numberOfBusyConnections() 
	       + " total=" + numberOfConnections() 
	       + " (" 
	       + highWaterMark() + "/"
	       + numberToReclaim() 
	       + ")");
    
public final java.lang.StringgetCacheType()

	return cacheType ;
    
public final inthighWaterMark()

	return highWaterMark ;
    
public final intnumberToReclaim()

	return numberToReclaim ;
    
protected booleanreclaim()
Reclaim some idle cached connections. Will never close a connection that is busy.

	if (debug())
	    dprint( ".reclaim: starting" ) ;

	int ctr = 0 ;
	while (ctr < numberToReclaim()) {
	    C candidate = reclaimableConnections.poll() ;
	    if (candidate == null)
		// If we have closed all idle connections, we must stop 
		// reclaiming.
		break ;

	    if (debug())
		dprint( ".reclaim: closing connection " + candidate ) ;

	    try {
		close( candidate ) ;	    
	    } catch (RuntimeException exc) {
		if (debug())
		    dprint( ".reclaim: caught exception on close: " + exc ) ;
		throw exc ;
	    }

	    ctr++ ;
	}

	if (debug())
	    dprint( ".reclaim: reclaimed " + ctr + " connection(s)" ) ;

	return ctr > 0 ;
    
protected abstract java.lang.StringthisClassName()

public java.lang.StringtoString()

	return thisClassName() + "[" 
	    + getCacheType() + "]";