-
Notifications
You must be signed in to change notification settings - Fork 1
Sequences
laforge49 edited this page Aug 18, 2011
·
5 revisions
We define a sequence as an ordered series of key/value pairs. There are a number of reasons for this:
- Sequence actors over an unchanging collections are immutable, and immutable actors execute all requests synchronously.
- Sequence actors can be used by many other actors at the same time.
- When providing a remote service, stateless operations work best.
- A fast tail operation can be implemented.
There are 3 messages used to access the contents of a sequence.
case class First()
case class Current[K](key: K)
case class Next[K](key: K)
One way to think of a Current request is as the ceiling function on a navigable set, and Next can be thought of as the higher function.
The result returned by these requests are either null or an KVPair.
case class KVPair[K, V](key: K, value: V)
For many sequences, the values will be equal to the keys. But when we map a sequence, the keys remain unchanged while the values are updated. And when we have a sequence over a TreeMap, the key/value pairs are the same as the key/value pairs in the TreeMap.
Sequence is the base class for all sequence actors, and contains the code for binding the request messages to functions.
bind(classOf[First], first)
def first(msg: AnyRef, rf: Any => Unit)
bind(classOf[Current[K]], current)
def current(msg: AnyRef, rf: Any => Unit)
bind(classOf[Next[K]], next)
def next(msg: AnyRef, rf: Any => Unit)