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

InboundConnectionCacheBlockingImpl

public final class InboundConnectionCacheBlockingImpl extends ConnectionCacheBlockingBase implements com.sun.xml.ws.transport.tcp.connectioncache.spi.transport.InboundConnectionCache
Manage connections that are initiated from another VM.
author
Ken Cavanaugh

Fields Summary
private final Map
connectionMap
Constructors Summary
public InboundConnectionCacheBlockingImpl(String cacheType, int highWaterMark, int numberToReclaim, Logger logger)


	super( cacheType, highWaterMark, numberToReclaim, logger ) ;

	this.connectionMap = new HashMap<C,ConnectionState<C>>() ;

	if (debug()) {
	    dprint(".constructor completed: " + getCacheType() );
	}
    
Methods Summary
public synchronized voidclose(C conn)
Close a connection, regardless of whether the connection is busy or not.

	if (debug()) 
	    dprint( "->close: " + conn ) ;
	
	try {
	    final ConnectionState<C> cs = connectionMap.remove( conn ) ;
	    int count = cs.busyCount ;
	    if (debug())
		dprint( ".close: " + conn + " count = " + count ) ;

	    if (count == 0)
		totalIdle-- ;
	    else
		totalBusy-- ;

	    final ConcurrentQueue.Handle rh = cs.reclaimableHandle ;
	    if (rh != null) {
		if (debug())
		    dprint( ".close: " + conn + " connection was reclaimable" ) ;

		rh.remove() ;
	    }

	    try {
		conn.close() ;
	    } catch (IOException exc) {
		if (debug())
		    dprint( ".close: " + conn + " close threw "  + exc ) ;
	    }
	} finally {
	    if (debug())
		dprint( "<-close: " + conn ) ;
	}
    
private com.sun.xml.ws.transport.tcp.connectioncache.impl.transport.InboundConnectionCacheBlockingImpl$ConnectionStategetConnectionState(C conn)

	// This should be the only place a CacheEntry is constructed.
	if (debug())
	    dprint( "->getConnectionState: " + conn ) ;

	try {
	    ConnectionState<C> result = connectionMap.get( conn ) ;
	    if (result == null) {
		if (debug())
		    dprint( ".getConnectionState: " + conn + 
			" creating new ConnectionState instance" ) ;
		result = new ConnectionState<C>( conn ) ;
		connectionMap.put( conn, result ) ;
		totalIdle++ ;
	    }
	    
	    return result ;
	} finally {
	    if (debug())
		dprint( "<-getConnectionState: " + conn ) ;
	}
    
public synchronized voidrequestProcessed(C conn, int numResponsesExpected)


	if (debug())
	    dprint( "->requestProcessed: connection " + conn 
		+ " expecting " + numResponsesExpected + " responses" ) ;

	try {
	    final ConnectionState<C> cs = connectionMap.get( conn ) ;

	    if (cs == null) {
		if (debug())
		    dprint( ".release: connection " + conn + " was closed" ) ;

		return ; 
	    } else {
		cs.expectedResponseCount += numResponsesExpected ;
		int numResp = cs.expectedResponseCount ;
		int numBusy = --cs.busyCount ;

		if (debug()) {
		    dprint( ".release: " + numResp + " responses expected" ) ;
		    dprint( ".release: " + numBusy + 
			" busy count for connection" ) ;
		}

		if (numBusy == 0) {
		    totalBusy-- ;
		    totalIdle++ ;

		    if (numResp == 0) {
			if (debug())
			    dprint( ".release: "
				+ "queuing reclaimable connection "
				+ conn ) ;

			if ((totalBusy+totalIdle) > highWaterMark()) {
			    close( conn ) ;
			} else {
			    cs.reclaimableHandle = 
				reclaimableConnections.offer( conn ) ;
			}
		    }
		}
	    }
	} finally {
	    if (debug())
		dprint( "<-requestProcessed" ) ;
	}
    
public synchronized voidrequestReceived(C conn)

	if (debug())
	    dprint( "->requestReceived: connection " + conn ) ;

	try {
	    ConnectionState<C> cs = getConnectionState( conn ) ;

	    final int totalConnections = totalBusy + totalIdle ;
	    if (totalConnections > highWaterMark())
		reclaim() ;

	    ConcurrentQueue.Handle<C> reclaimHandle = cs.reclaimableHandle ;
	    if (reclaimHandle != null) {
		if (debug())
		    dprint( ".requestReceived: " + conn 
			+ " removed from reclaimableQueue" ) ;
		reclaimHandle.remove() ;
	    }

	    int count = cs.busyCount++ ;
	    if (count == 0) {
		if (debug())
		    dprint( ".requestReceived: " + conn 
			+ " transition from idle to busy" ) ;

		totalIdle-- ;
		totalBusy++ ;
	    }
	} finally {
	    if (debug())
		dprint( "<-requestReceived: connection " + conn ) ;
	}
    
public synchronized voidresponseSent(C conn)
Decrement the number of expected responses. When a connection is idle and has no expected responses, it can be reclaimed.

	if (debug())
	    dprint( "->responseSent: " + conn ) ;

	try {
	    final ConnectionState<C> cs = connectionMap.get( conn ) ;
	    final int waitCount = --cs.expectedResponseCount ;
	    if (waitCount == 0) {
		if (debug())
		    dprint( ".responseSent: " + conn + " is now reclaimable" ) ;

		if ((totalBusy+totalIdle) > highWaterMark()) {
		    if (debug()) {
			dprint( ".responseSent: " + conn 
			    + " closing connection" ) ; 
		    }

		    close( conn ) ;
		} else {
		    cs.reclaimableHandle = 
			reclaimableConnections.offer( conn ) ;

		    if (debug()) {
			dprint( ".responseSent: " + conn 
			    + " is now reclaimable" ) ; 
		    }
		}
	    } else {
		if (debug()) {
		    dprint( ".responseSent: " + conn + " waitCount=" 
			+ waitCount ) ;
		}
	    }
	} finally {
	    if (debug()) {
		dprint( "<-responseSent: " + conn ) ;
	    }
	}
    
protected java.lang.StringthisClassName()

	return "InboundConnectionCacheBlockingImpl" ;