Copyright Workingmouse Pty. Ltd. 2007, 2008

This software is released under an open source BSD licence.

fj.control.parallel
Class Actor<A>

java.lang.Object
  extended by fj.control.parallel.Actor<A>

public final class Actor<A>
extends Object

Light weight actors for Java. Concurrency is controlled by a parallel (or serial) Strategy. The Strategy serves as the Actor's execution engine, and as its mailbox.

An actor on messages of type A represents a transformation from an effect of A to a function of A. Given some effect, the Actor transforms messages to Futures using its Strategy. The Future represents a possibly running computation which is executing the effect.

Author: Runar


Method Summary
 Future<Unit> act(A a)
          Pass a message to this actor, applying its side-effect to the message.
static
<A> Actor<A>
actor(Strategy<Unit> s, Effect<A> e)
          Creates a new Actor that uses the given parallelization strategy and has the given side-effect.
<B> Actor<B>
comap(F<B,A> f)
          Contravariant functor pattern.
 Actor<Promise<A>> promise()
          Transforms this actor to an actor on promises.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

actor

public static <A> Actor<A> actor(Strategy<Unit> s,
                                 Effect<A> e)
Creates a new Actor that uses the given parallelization strategy and has the given side-effect.

Parameters:
s - The parallelization strategy to use for the new Actor.
e - The side-effect to apply to messages passed to the Actor.
Returns:
A new actor that uses the given parallelization strategy and has the given side-effect.

act

public Future<Unit> act(A a)
Pass a message to this actor, applying its side-effect to the message. The side-effect is applied in a concurrent computation, resulting in a Future referencing that computation.

Parameters:
a - The message to send to this actor.
Returns:
A Future that yields no value, but represents a concurrent computation.

comap

public <B> Actor<B> comap(F<B,A> f)
Contravariant functor pattern. Creates a new actor whose message is transformed by the given function before being passed to this actor.

Parameters:
f - The function to use for the transformation
Returns:
A new actor which passes its messages through the given function, to this actor.

promise

public Actor<Promise<A>> promise()
Transforms this actor to an actor on promises.

Returns:
A new actor, equivalent to this actor, that acts on promises.

Copyright Workingmouse Pty. Ltd. 2007, 2008

This software is released under an open source BSD licence.