FileDocCategorySizeDatePackage
ConcurrentQueueNonBlockingImpl.javaAPI DocExample5879Tue May 29 16:57:04 BST 2007com.sun.xml.ws.transport.tcp.connectioncache.impl.concurrent

ConcurrentQueueNonBlockingImpl

public class ConcurrentQueueNonBlockingImpl extends Object implements com.sun.xml.ws.transport.tcp.connectioncache.spi.concurrent.ConcurrentQueue

Fields Summary
final Entry
head
final Object
lock
int
count
Constructors Summary
Methods Summary
public Handleoffer(V arg)
Add a new element to the tail of the queue. Returns a handle for the element in the queue.

	if (arg == null)
	    throw new IllegalArgumentException( "Argument cannot be null" ) ;

	Entry<V> entry = new Entry<V>( arg ) ;
	
	synchronized (lock) {
	    entry.next = head ;
	    entry.prev = head.prev ;
	    head.prev.next = entry ;
	    head.prev = entry ;
	    count++ ;
	}

	return entry.handle() ;
    
public Vpoll()
Return an element from the head of the queue. The element is removed from the queue.

	Entry<V> first = null ;

	synchronized (lock) {
	    first = head.next ;
	    if (first == head)
		return null ;
	    else {
		// assert that the following expression returns true!
		first.handle().remove() ;
	    }
	}

	// Once first is removed from the queue, it is invisible to other threads,
	// so we don't need to synchronize here.
	first.next = null ;
	first.prev = null ;
	V value = first.handle().value() ;
	return value ;
    
public intsize()

	synchronized (lock) {
	    return count ;
	}