groovyx.gpars.group
Class DefaultPGroup

java.lang.Object
  extended by groovyx.gpars.group.PGroup
      extended by groovyx.gpars.group.DefaultPGroup
All Implemented Interfaces:
groovy.lang.GroovyObject, Pool

public final class DefaultPGroup
extends groovyx.gpars.group.PGroup

Provides logical grouping for actors, agents and dataflow tasks and operators. Each group has an underlying thread pool, which will perform actions on behalf of the users belonging to the group. Actors created through the DefaultPGroup.actor method will automatically belong to the group through which they were created, just like agents created through the agent or fairAgent methods or dataflow tasks and operators created through the task or operator methods. Uses a pool of non-daemon threads. The DefaultPGroup class implements the Pool interface through @Delegate.

 def group = new DefaultPGroup()
 group.resize 1
 def actor = group.actor {
   react { message ->
     println message
   }
 }.start()
 actor.send 'Hi!'
 . . .
 group.shutdown()
 

Otherwise, if constructing Actors directly through their constructors, the AbstractPooledActor.parallelGroup property, which defaults to the Actors.defaultActorPGroup, can be set before the actor is started.

 def group = new DefaultPGroup()
 def actor = new MyActor()
 actor.parallelGroup = group
 actor.start()
 . . .
 group.shutdown()
 

Author:
Vaclav Pech

Field Summary
 
Fields inherited from interface groovyx.gpars.scheduler.Pool
POOL_SIZE_MUST_BE_A_POSITIVE_NUMBER, UNCAUGHT_EXCEPTION_OCCURRED_IN_ACTOR_POOL
 
Constructor Summary
DefaultPGroup()
          Creates a group for actors, agents, tasks and operators.
DefaultPGroup(int poolSize)
          Creates a group for actors, agents, tasks and operators.
DefaultPGroup(Pool threadPool)
          Creates a group for actors, agents, tasks and operators.
 
Method Summary
 
Methods inherited from class groovyx.gpars.group.PGroup
, actor, agent, agent, blockingActor, execute, fairActor, fairAgent, fairAgent, fairMessageHandler, fairReactor, finalize, getMetaClass, getPoolSize, getProperty, getThreadPool, invokeMethod, messageHandler, operator, operator, operator, operator, operator, prioritySelector, prioritySelector, prioritySelector, prioritySelector, reactor, resetDefaultSize, resize, select, select, selector, selector, selector, selector, setMetaClass, setProperty, shutdown, splitter, splitter, task, task, task
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPGroup

public DefaultPGroup(Pool threadPool)
Creates a group for actors, agents, tasks and operators. The actors will share the supplied thread pool.

Parameters:
threadPool - The thread pool to use for the group

DefaultPGroup

public DefaultPGroup()
Creates a group for actors, agents, tasks and operators. The actors will share a common daemon thread pool.


DefaultPGroup

public DefaultPGroup(int poolSize)
Creates a group for actors, agents, tasks and operators. The actors will share a common daemon thread pool.

Parameters:
poolSize - The initial size of the underlying thread pool

Copyright © 2008–2010 Václav Pech. All Rights Reserved.