Package fj.control.parallel
Class Actor<A>
java.lang.Object
fj.control.parallel.Actor<A>
Light weight actors for Java. Concurrency is controlled by a parallel Strategy.
The Strategy serves as the Actor's execution engine, and as its mailbox.
Given some effect, the Actor performs the effect on its messages using its Strategy, transforming them
into instances of fj.P1. The P1 represents a possibly running computation which is executing the effect.
NOTE: A value of this type may generally process more than one message at a time, depending on its Strategy.
An actor is not thread-safe unless either its Effect imposes an order on incoming messages or its Strategy is
single-threaded.
A queue actor which imposes an order on its messages is provided by the
queueActor(fj.control.parallel.Strategy<fj.Unit>, fj.function.Effect1<T>)
static method.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionPass a message to this actor, applying its side-effect to the message.static <A> Actor
<A> Creates a new Actor that uses the given parallelization strategy and has the given side-effect.static <A> Actor
<A> Creates a new Actor that uses the given parallelization strategy and has the given side-effect.<B> Actor
<B> Contravariant functor pattern.promise()
Transforms this actor to an actor on promises.static <T> Actor
<T> queueActor
(Strategy<Unit> s, Effect1<T> ea) An Actor equipped with a queue and which is guaranteed to process one message at a time.
-
Field Details
-
s
-
f
-
-
Constructor Details
-
Actor
-
-
Method Details
-
queueActor
An Actor equipped with a queue and which is guaranteed to process one message at a time. With respect to an enqueueing actor or thread, this actor will process messages in the same order as they are sent. -
actor
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.
-
actor
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 function projection of a 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
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 product referencing that computation.- Parameters:
a
- The message to send to this actor.- Returns:
- A unit-product that represents the action running concurrently.
-
contramap
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
Transforms this actor to an actor on promises.- Returns:
- A new actor, equivalent to this actor, that acts on promises.
-