groovyx.gpars.util
Class DefaultMessageQueue

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

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

An implementation of the message queue for actor and agent messaging. 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

Field Summary
private  boolean empty
           
private  java.util.LinkedList<java.lang.Object> inside
           
private  java.util.LinkedList<java.lang.Object> outside
           
 
Constructor Summary
DefaultMessageQueue()
           
 
Method Summary
 void add(java.lang.Object element)
           
 boolean isEmpty()
           
 java.lang.Object poll()
           
private  void swap(java.util.LinkedList<java.lang.Object> localQueue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

outside

private java.util.LinkedList<java.lang.Object> outside

inside

private java.util.LinkedList<java.lang.Object> inside

empty

private volatile boolean empty
Constructor Detail

DefaultMessageQueue

public DefaultMessageQueue()
Method Detail

isEmpty

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

poll

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

swap

private void swap(java.util.LinkedList<java.lang.Object> localQueue)

add

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

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