groovyx.gpars.util
Class FQMessageQueue

java.lang.Object
  extended by groovyx.gpars.util.FQMessageQueue
All Implemented Interfaces:
MessageQueue

public final class FQMessageQueue
extends java.lang.Object
implements MessageQueue

An implementation of the message queue for actor and agent messaging using functional queues. It leverages the fact that in any moment there's only one reading thread accessing the queue and that potential read thread swap at the actor or agent thread pool synchronizes thread memory.

We also count on writers not to call the isEmpty() method

Author:
Vaclav Pech

Nested Class Summary
(package private) static class FQMessageQueue.EmptyNode
           
(package private) static class FQMessageQueue.Node
           
 
Field Summary
private  FQMessageQueue.Node inside
           
private  FQMessageQueue.Node outside
           
private  java.util.concurrent.atomic.AtomicReferenceFieldUpdater outsideUpdater
           
 
Constructor Summary
FQMessageQueue()
           
 
Method Summary
 void add(java.lang.Object element)
           
 boolean isEmpty()
           
 java.lang.Object poll()
           
private  java.lang.Object pollFromInside()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

outside

private volatile FQMessageQueue.Node outside

inside

private FQMessageQueue.Node inside

outsideUpdater

private final java.util.concurrent.atomic.AtomicReferenceFieldUpdater outsideUpdater
Constructor Detail

FQMessageQueue

public FQMessageQueue()
Method Detail

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface MessageQueue

poll

public java.lang.Object poll()
Specified by:
poll in interface MessageQueue

pollFromInside

private java.lang.Object pollFromInside()

add

public void add(java.lang.Object element)
Specified by:
add in interface MessageQueue

Copyright © 2008–2010 Václav Pech. All Rights Reserved.