Skip to content

Commit df7b55c

Browse files
committed
Renamed actor groups
1 parent 49de5a4 commit df7b55c

File tree

79 files changed

+241
-241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+241
-241
lines changed

grails-doc/src/guide/2.4 What's new.gdoc

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ h4. Renaming hints
2727
* withAsynchronizer() -> withPool()
2828
* withExistingAsynchronizer() -> withExistingPool()
2929
* orchestrate() -> runForkJoin()
30+
* ActorGroup -> PGroup
31+
* PooledActorGroup -> DefaultPGroup
32+
* NonDaemonActorGroup -> NonDaemonPGroup
3033

3134
h3. Fork / Join
3235

grails-doc/src/guide/5.1 Actors Principles.gdoc

+16-16
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ A little bit more realistic example of an event-driven actor that receives two n
115115
import static groovyx.gpars.actor.Actors.*
116116

117117
//not necessary, just showing that a single-threaded pool can still handle multiple actors
118-
defaultPooledActorGroup.resize 1
118+
defaultActorPGroup.resize 1
119119

120120
final def console = actor {
121121
loop {
@@ -187,7 +187,7 @@ Closure createMessageHandler(def parentActor) {
187187
}
188188
}
189189

190-
def console = new PooledActorGroup(1).actor {
190+
def console = new DefaultPGroup(1).actor {
191191
react {
192192
println "Sorted array:\t${it}"
193193
System.exit 0
@@ -251,7 +251,7 @@ h3. Pool management
251251
_Actors_ can be organized into groups and as a default there's always an application-wide pooled actor group available. And just like the _Actors_ abstract factory can be used to create actors in the default group, custom groups can be used as abstract factories to create new actors instances belonging to these groups.
252252

253253
{code}
254-
def myGroup = new PooledActorGroup()
254+
def myGroup = new DefaultPGroup()
255255

256256
def actor1 = myGroup.actor {
257257
...
@@ -265,35 +265,35 @@ def actor2 = myGroup.actor {
265265
The actors belonging to the same group share the *underlying thread pool* of that group. The pool by default contains *n + 1 threads*, where *n* stands for the number of *CPUs* detected by the JVM. The *pool size* can be set *explicitly* either by setting the _gpars.poolsize_ system property or individually for each actor group by specifying the appropriate constructor parameter.
266266

267267
{code}
268-
def myGroup = new PooledActorGroup(10) //the pool will contain 10 threads
268+
def myGroup = new DefaultPGroup(10) //the pool will contain 10 threads
269269
{code}
270270

271-
The thread pool can be manipulated through the appropriate _PooledActorGroup_ class, which *delegates* to the _Pool_ interface of the thread pool. For example, the _resize()_ method allows you to change the pool size any time and the _resetDefaultSize()_ sets it back to the default value. The _shutdown()_ method can be called when you need to safely finish all tasks, destroy the pool and stop all the threads in order to exit JVM in an organized manner.
271+
The thread pool can be manipulated through the appropriate _DefaultPGroup_ class, which *delegates* to the _Pool_ interface of the thread pool. For example, the _resize()_ method allows you to change the pool size any time and the _resetDefaultSize()_ sets it back to the default value. The _shutdown()_ method can be called when you need to safely finish all tasks, destroy the pool and stop all the threads in order to exit JVM in an organized manner.
272272

273273
{code}
274274
... (n+1 threads in the default pool after startup)
275275

276-
Actors.defaultPooledActorGroup.resize 1 //use one-thread pool
276+
Actors.defaultActorPGroup.resize 1 //use one-thread pool
277277

278278
... (1 thread in the pool)
279279

280-
Actors.defaultPooledActorGroup.resetDefaultSize()
280+
Actors.defaultActorPGroup.resetDefaultSize()
281281

282282
... (n+1 threads in the pool)
283283

284-
Actors.defaultPooledActorGroup.shutdown()
284+
Actors.defaultActorPGroup.shutdown()
285285
{code}
286286

287-
As an alternative to the _PooledActorGroup_, which creates a pool of daemon threads, the _NonDaemonActorGroup_ class can be used when non-daemon threads are required.
287+
As an alternative to the _DefaultPGroup_, which creates a pool of daemon threads, the _NonDaemonPGroup_ class can be used when non-daemon threads are required.
288288

289289
{code}
290-
def daemonGroup = new PooledActorGroup()
290+
def daemonGroup = new DefaultPGroup()
291291

292292
def actor1 = daemonGroup.actor {
293293
...
294294
}
295295

296-
def nonDaemonGroup = new NonDaemonActorGroup()
296+
def nonDaemonGroup = new NonDaemonPGroup()
297297

298298
def actor2 = nonDaemonGroup.actor {
299299
...
@@ -311,8 +311,8 @@ class MyActor {
311311
Actors belonging to the same group share the *underlying thread pool*. With pooled actor groups you can split your actors to leverage multiple thread pools of different sizes and so assign resources to different components of your system and tune their performance.
312312

313313
{code}
314-
def coreActors = new NonDaemonActorGroup(5) //5 non-daemon threads pool
315-
def helperActors = new PooledActorGroup(1) //1 daemon thread pool
314+
def coreActors = new NonDaemonPGroup(5) //5 non-daemon threads pool
315+
def helperActors = new DefaultPGroup(1) //1 daemon thread pool
316316

317317
def priceCalculator = coreActors.actor {
318318
...
@@ -342,15 +342,15 @@ Do not forget to shutdown custom pooled actor groups, once you no longer need th
342342
h3. Common trap: App terminates while actors do not receive messages
343343

344344
Most likely you're using daemon threads and pools, which is the default setting, and your main thread finishes. Calling _actor.join()_ on any, some or all of your actors would block the main thread until the actor terminates and thus keep all your actors running.
345-
Alternatively use instances of _NonDaemonActorGroup_ and assign some of your actors to these groups.
345+
Alternatively use instances of _NonDaemonPGroup_ and assign some of your actors to these groups.
346346
{code}
347-
def nonDaemonGroup = new NonDaemonActorGroup()
347+
def nonDaemonGroup = new NonDaemonPGroup()
348348
def myActor = nonDaemonGroup.actor {...}
349349
{code}
350350

351351
alternatively
352352
{code}
353-
def nonDaemonGroup = new NonDaemonActorGroup()
353+
def nonDaemonGroup = new NonDaemonPGroup()
354354

355355
class MyActor extends AbstractPooledActor {
356356
def MyActor() {

grails-doc/src/guide/5.2 Special Actors.gdoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ final def actor = new MyActor({
8080

8181
h3. Reactive Actor
8282

83-
The _ReactiveActor_ class, constructed typically by calling _Actors.reactor()_ or _PooledActorGroup.reactor()_, allow for more event-driven like approach. When a reactive actor receives a message, the supplied block of code, which makes up the reactive actor's body, is run with the message as a parameter. The result returned from the code is sent in reply.
83+
The _ReactiveActor_ class, constructed typically by calling _Actors.reactor()_ or _DefaultPGroup.reactor()_, allow for more event-driven like approach. When a reactive actor receives a message, the supplied block of code, which makes up the reactive actor's body, is run with the message as a parameter. The result returned from the code is sent in reply.
8484

8585
{code}
86-
import groovyx.gpars.actor.PooledActorGroup
86+
import groovyx.gpars.actor.DefaultPGroup
8787

88-
final def group = new PooledActorGroup()
88+
final def group = new DefaultPGroup()
8989

9090
final def doubler = group.reactor {
9191
2 * it

grails-doc/src/guide/5.4 Classic Examples using Actors.gdoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ h2. Sleeping Barber
1111

1212
"Problem description":http://en.wikipedia.org/wiki/Sleeping_barber_problem
1313

14-
{code}import groovyx.gpars.actor.PooledActorGroup
14+
{code}import groovyx.gpars.actor.DefaultPGroup
1515
import groovyx.gpars.actor.AbstractPooledActor
1616
import groovyx.gpars.actor.Actor
1717

18-
final def group = new PooledActorGroup()
18+
final def group = new DefaultPGroup()
1919

2020
final def barber = group.actor {
2121
final def random = new Random()
@@ -127,7 +127,7 @@ h2. Dining Philosophers
127127
{code}import groovyx.gpars.actor.AbstractPooledActor
128128
import groovyx.gpars.actor.Actors
129129

130-
Actors.defaultPooledActorGroup.resize 5
130+
Actors.defaultActorPGroup.resize 5
131131

132132
final class Philosopher extends AbstractPooledActor {
133133
private Random random = new Random()

grails-doc/src/guide/6. Safe.gdoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ To create a Safe instance belonging to a group, call the _safe()_ factory method
140140
and tune performance of agents.
141141

142142
{code}
143-
final def group = new NonDaemonActorGroup(5) //create a group around a thread pool
143+
final def group = new NonDaemonPGroup(5) //create a group around a thread pool
144144
def jugMembers = group.safe(['Me']) //add Me
145145
{code}
146146

147147
{note:Title=Custom thread pools for agents}
148148
The default thread pool for agents contains daemon threads. Make sure that your custom thread pools either use daemon threads, too, which can be achieved
149-
either by using PooledActorGroup or by providing your own thread factory to a thread pool constructor,
150-
or in case your thread pools use non-daemon threads, such as when using the NonDaemonActorGroup group class, make sure you shutdown the group or the thread pool explicitly by calling its shutdown() method,
149+
either by using DefaultPGroup or by providing your own thread factory to a thread pool constructor,
150+
or in case your thread pools use non-daemon threads, such as when using the NonDaemonPGroup group class, make sure you shutdown the group or the thread pool explicitly by calling its shutdown() method,
151151
otherwise your applications will not exit.
152152
{note}
153153

grails-doc/src/guide/7.1 Dataflow tasks.gdoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ Dataflow tasks can be organized into groups to allow for performance fine-tuning
5656
to create tasks attached to the groups.
5757

5858
{code}
59-
import groovyx.gpars.actor.PooledActorGroup
59+
import groovyx.gpars.actor.DefaultPGroup
6060

61-
def group = new PooledActorGroup()
61+
def group = new DefaultPGroup()
6262

6363
group.with {
6464
task {
@@ -74,8 +74,8 @@ group.with {
7474
{note:Title=Custom thread pools for dataflow}
7575
The default thread pool for dataflow tasks contains non-daemon threads, which means your application will not exit before all tasks complete.
7676
When grouping tasks, make sure that your custom thread pools either use daemon threads, too, which can be achieved by
77-
using PooledActorGroup or by providing your own thread factory to a thread pool constructor,
78-
or in case your thread pools use non-daemon threads, such as when using the NonDaemonActorGroup group class, make sure you shutdown the group or the thread pool explicitly by calling its shutdown() method,
77+
using DefaultPGroup or by providing your own thread factory to a thread pool constructor,
78+
or in case your thread pools use non-daemon threads, such as when using the NonDaemonPGroup group class, make sure you shutdown the group or the thread pool explicitly by calling its shutdown() method,
7979
otherwise your applications will not exit.
8080
{note}
8181

grails-doc/src/guide/7.2 Dataflow operators.gdoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ Dataflow operators can be organized into groups to allow for performance fine-tu
8686
to create tasks attached to the groups.
8787

8888
{code}
89-
import groovyx.gpars.actor.PooledActorGroup
89+
import groovyx.gpars.actor.DefaultPGroup
9090

91-
def group = new PooledActorGroup()
91+
def group = new DefaultPGroup()
9292

9393
group.with {
9494
operator(inputs: [a, b, c], outputs: [d]) {x, y, z ->
@@ -101,7 +101,7 @@ group.with {
101101
{note:Title=Custom thread pools for dataflow}
102102
The default thread pool for dataflow operators contains non-daemon threads, which means your application will not exit before all operators are stopped.
103103
When grouping operators, make sure that your custom thread pools either use daemon threads, too, which can be achieved by
104-
using PooledActorGroup or by providing your own thread factory to a thread pool constructor,
105-
or in case your thread pools use non-daemon threads, such as when using the NonDaemonActorGroup group class, make sure you shutdown the group or the thread pool explicitly by calling its shutdown() method,
104+
using DefaultPGroup or by providing your own thread factory to a thread pool constructor,
105+
or in case your thread pools use non-daemon threads, such as when using the NonDaemonPGroup group class, make sure you shutdown the group or the thread pool explicitly by calling its shutdown() method,
106106
otherwise your applications will not exit.
107107
{note}

grails-doc/src/guide/7.3 Dataflow implementation.gdoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The Dataflow Concurrency in GPars builds on top of its actor support. All of the dataflow tasks share a thread pool and so the number threads created through _DataFlow.task()_ factory method don't need to correspond to the number of physical threads required from the system.
2-
The _DataFlow.task()_ factory method takes an optional actorGroup parameter to specify a group to which the task should belong. Since each group defines its own thread pool, you can easily organize tasks around different thread pools just like you do with actors.
2+
The _PGroup.task()_ factory method can be used to attach the created task to a group. Since each group defines its own thread pool, you can easily organize tasks around different thread pools just like you do with actors.
33

44
h3. Combining actors and Dataflow Concurrency
55

grails-doc/src/ref/Actors/Usage.gdoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ me.join()
5252

5353
h3. Actor groups
5454
{code}
55-
def coreActors = new NonDaemonActorGroup(5) //5 non-daemon threads pool
56-
def helperActors = new PooledActorGroup(1) //1 daemon thread pool
55+
def coreActors = new NonDaemonPGroup(5) //5 non-daemon threads pool
56+
def helperActors = new DefaultPGroup(1) //1 daemon thread pool
5757

5858
def priceCalculator = coreActors.actor {
5959
...

src/main/groovy/groovyx/gpars/Definitions.gdsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ contributor(actorBody) {
6161
def currentMethod = call.bind()
6262
def clazz = currentMethod?.containingClass
6363
final def clazzName = clazz?.qualName?.toUpperCase()
64-
if ((clazzName?.contains("ACTORGROUP")) || (clazzName?.contains("ACTORS"))) {
64+
if ((clazzName?.contains("PGROUP")) || (clazzName?.contains("ACTORS"))) {
6565
method name: "react", type: "void", params: [closure: 'groovy.lang.Closure']
6666
method name: "react", type: "void", params: [timeout: 'long', unit: 'java.util.concurrent.TimeUnit', closure: 'groovy.lang.Closure']
6767
method name: "react", type: "void", params: [timeout: 'groovy.time.Duration', closure: 'groovy.lang.Closure']

src/main/groovy/groovyx/gpars/actor/AbstractPooledActor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
* AbstractPooledActor provides the default Actor implementation. It represents a standalone active object (actor),
3535
* which reacts asynchronously to messages sent to it from outside through the send() method.
3636
* Each Actor has its own message queue and a thread pool shared with other Actors by means of an instance
37-
* of the ActorGroup, which they have in common.
38-
* The ActorGroup instance is responsible for the pool creation, management and shutdown.
37+
* of the PGroup, which they have in common.
38+
* The PGroup instance is responsible for the pool creation, management and shutdown.
3939
* All work performed by an Actor is divided into chunks, which are sequentially submitted as independent tasks
4040
* to the thread pool for processing.
4141
* Whenever an Actor looks for a new message through the react() method, the actor gets detached

src/main/groovy/groovyx/gpars/actor/ActorGroup.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import groovyx.gpars.scheduler.Pool
2727
* @author Vaclav Pech, Alex Tkachman
2828
* Date: May 8, 2009
2929
*/
30-
public abstract class ActorGroup {
30+
public abstract class PGroup {
3131

3232
/**
3333
* Stores the group actors' thread pool
@@ -37,9 +37,9 @@ public abstract class ActorGroup {
3737
public Pool getThreadPool() { return threadPool; }
3838

3939
/**
40-
* Creates a group of pooled actors. The actors will share a common daemon thread pool.
40+
* Creates a group for actors, agents, tasks and operators. The actors will share a common daemon thread pool.
4141
*/
42-
protected def ActorGroup(final Pool threadPool) {
42+
protected def PGroup(final Pool threadPool) {
4343
this.threadPool = threadPool
4444
}
4545

src/main/groovy/groovyx/gpars/actor/Actors.groovy

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import groovyx.gpars.scheduler.ResizeablePool
2424
* <pre>
2525
* import static org.gpars.actor.Actors.*
2626
*
27-
* Actors.defaultPooledActorGroup.resize 1
27+
* Actors.defaultActorPGroup.resize 1
2828
*
2929
* def actor = actor {* react {message ->
3030
* println message
@@ -36,7 +36,7 @@ import groovyx.gpars.scheduler.ResizeablePool
3636
*
3737
* All actors created through the Actors class will belong to the same default actor group and run
3838
* on daemon threads.
39-
* The PooledActorGroup class should be used when actors need to be grouped into multiple groups or when non-daemon
39+
* The DefaultPGroup class should be used when actors need to be grouped into multiple groups or when non-daemon
4040
* threads are to be used.
4141
* @author Vaclav Pech, Alex Tkachman
4242
* Date: Feb 18, 2009
@@ -46,7 +46,7 @@ public abstract class Actors {
4646
/**
4747
* The default actor group to share by all actors created through the Actors class.
4848
*/
49-
public final static PooledActorGroup defaultPooledActorGroup = new PooledActorGroup(new ResizeablePool(true))
49+
public final static DefaultPGroup defaultActorPGroup = new DefaultPGroup(new ResizeablePool(true))
5050

5151
/**
5252
* Creates a new instance of PooledActor, using the passed-in closure as the body of the actor's act() method.
@@ -55,7 +55,7 @@ public abstract class Actors {
5555
* @return A newly created instance of the AbstractPooledActor class
5656
*/
5757
public static AbstractPooledActor actor(Runnable handler) {
58-
return defaultPooledActorGroup.actor(handler)
58+
return defaultActorPGroup.actor(handler)
5959
}
6060

6161
/**
@@ -67,14 +67,14 @@ public abstract class Actors {
6767
* @return A new instance of ReactiveEventBasedThread
6868
*/
6969
public static AbstractPooledActor reactor(final Closure code) {
70-
return defaultPooledActorGroup.reactor(code)
70+
return defaultActorPGroup.reactor(code)
7171
}
7272

7373
/**
7474
* Creates an instance of DynamicDispatchActor.
7575
* @param code The closure specifying individual message handlers.
7676
*/
7777
public static AbstractPooledActor messageHandler(final Closure code) {
78-
return defaultPooledActorGroup.messageHandler(code)
78+
return defaultActorPGroup.messageHandler(code)
7979
}
8080
}

src/main/groovy/groovyx/gpars/actor/DefaultPGroup.groovy

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import groovyx.gpars.scheduler.Pool
4141
* </pre>
4242
*
4343
* Otherwise, if constructing Actors directly through their constructors, the AbstractPooledActor.actorGroup property,
44-
* which defaults to the Actors.defaultPooledPGroup, can be set before the actor is started.
44+
* which defaults to the Actors.defaultActorPGroup, can be set before the actor is started.
4545
*
4646
* <pre>
4747
* def group = new DefaultPGroup()
@@ -60,21 +60,22 @@ import groovyx.gpars.scheduler.Pool
6060
public final class DefaultPGroup extends PGroup {
6161

6262
/**
63-
* Creates a group of pooled actors. The actors will share a common daemon thread pool.
63+
* Creates a group for actors, agents, tasks and operators. The actors will share the supplied thread pool.
64+
* @param threadPool The thread pool to use for the group
6465
*/
6566
public def DefaultPGroup(final Pool threadPool) {
6667
super(threadPool)
6768
}
6869

6970
/**
70-
* Creates a group of pooled actors. The actors will share a common daemon thread pool.
71+
* Creates a group for actors, agents, tasks and operators. The actors will share a common daemon thread pool.
7172
*/
7273
def DefaultPGroup() {
7374
super(new DefaultPool(true))
7475
}
7576

7677
/**
77-
* Creates a group of pooled actors. The actors will share a common daemon thread pool.
78+
* Creates a group for actors, agents, tasks and operators. The actors will share a common daemon thread pool.
7879
* @param poolSize The initial size of the underlying thread pool
7980
*/
8081
def DefaultPGroup(final int poolSize) {

0 commit comments

Comments
 (0)