Groovy Documentation

gpars.actor
Class Actors

java.lang.Object
  gpars.actor.Actors

class Actors

Provides handy helper methods to create pooled actors and customize the underlying thread pool. Use static import to be able to call Actors methods without the need to prepend them with the Actors identifier.

 import static org.gpars.actor.Actors.*

 Actors.defaultActorPGroup.resize 1

 def actor = actor {*     react {message ->
         println message
}*     //this line will never be reached
}.start()

 actor.send 'Hi!'
 
All actors created through the Actors class will belong to the same default actor group and run on daemon threads. The DefaultPGroup class should be used when actors need to be grouped into multiple groups or when non-daemon threads are to be used.
author:
Vaclav Pech, Alex Tkachman Date: Feb 18, 2009


Property Summary
static DefaultPGroup defaultActorPGroup

The default actor group to share by all actors created through the Actors class.

 
Constructor Summary
Actors()

 
Method Summary
static AbstractPooledActor actor(Runnable handler)

Creates a new instance of PooledActor, using the passed-in closure as the body of the actor's act() method.

static AbstractPooledActor messageHandler(groovy.lang.Closure code)

Creates an instance of DynamicDispatchActor.

static AbstractPooledActor reactor(groovy.lang.Closure code)

Creates a reactor around the supplied code.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Property Detail

defaultActorPGroup

public static final DefaultPGroup defaultActorPGroup
The default actor group to share by all actors created through the Actors class.


 
Constructor Detail

Actors

Actors()


 
Method Detail

actor

public static AbstractPooledActor actor(Runnable handler)
Creates a new instance of PooledActor, using the passed-in closure as the body of the actor's act() method. The created actor will be part of the default actor group.
param:
handler The body of the newly created actor's act method.
return:
A newly created instance of the AbstractPooledActor class


messageHandler

public static AbstractPooledActor messageHandler(groovy.lang.Closure code)
Creates an instance of DynamicDispatchActor.
param:
code The closure specifying individual message handlers.


reactor

public static AbstractPooledActor reactor(groovy.lang.Closure code)
Creates a reactor around the supplied code. When a reactor receives a message, the supplied block of code is run with the message as a parameter and the result of the code is send in reply. The created actor will be part of the default actor group.
param:
The code to invoke for each received message
return:
A new instance of ReactiveEventBasedThread


 

Groovy Documentation