akka.contrib.pattern
Class WorkList<T>

java.lang.Object
  extended by akka.contrib.pattern.WorkList<T>

public class WorkList<T>
extends java.lang.Object

Fast, small, and dirty implementation of a linked list that removes transient work entries once they are processed. The list is not thread safe! However it is expected to be reentrant. This means a processing function can add/remove entries from the list while processing. Most important, a processing function can remove its own entry from the list. The first remove must return true and any subsequent removes must return false.


Nested Class Summary
static class WorkList.Entry<T>
          Singly linked list entry implementation for WorkList.
 
Constructor Summary
WorkList()
           
 
Method Summary
 WorkList<T> add(T ref, boolean permanent)
          Appends an entry to the work list.
 WorkList<T> addAll(WorkList<T> other)
          Appends another WorkList to this WorkList.
static
<T> WorkList<T>
empty()
           
 WorkList.Entry<T> head()
           
 boolean process(scala.Function1<T,java.lang.Object> processFn)
          Tries to process each entry using the processing function.
 boolean remove(T ref)
          Removes an entry from the work list
 boolean removeAll()
          Removes all entries from this WorkList
 WorkList.Entry<T> tail()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkList

public WorkList()
Method Detail

empty

public static <T> WorkList<T> empty()

head

public WorkList.Entry<T> head()

tail

public WorkList.Entry<T> tail()

add

public WorkList<T> add(T ref,
                       boolean permanent)
Appends an entry to the work list.

Parameters:
ref - The entry.
permanent - (undocumented)
Returns:
The updated work list.

remove

public boolean remove(T ref)
Removes an entry from the work list

Parameters:
ref - The entry.
Returns:
True if the entry is removed, false if the entry is not found.

process

public boolean process(scala.Function1<T,java.lang.Object> processFn)
Tries to process each entry using the processing function. Stops at the first entry processing succeeds. If the entry is not permanent, the entry is removed.

Parameters:
processFn - The processing function, returns true if processing succeeds.
Returns:
true if an entry has been processed, false if no entries are processed successfully.

addAll

public WorkList<T> addAll(WorkList<T> other)
Appends another WorkList to this WorkList.

Parameters:
other - The other WorkList
Returns:
This WorkList

removeAll

public boolean removeAll()
Removes all entries from this WorkList

Returns:
True if at least one entry is removed. False if none is removed.