(Quick Reference)

Creating an actor using a factory method

Actors.actor {
    println "actor1 has started"

delegate.metaClass { afterStop = {List undeliveredMessages -> println "actor1 has stopped" }

onInterrupt = {InterruptedException e -> println "actor1 has been interrupted" }

onTimeout = {-> println "actor1 has timed out" }

onException = {Exception e -> println "actor1 threw an exception" } } println("Running actor1") … }

Sub-classing the DefaultActor class

class PooledLifeCycleSampleActor extends DefaultActor {

protected void act() { println("Running actor2") … }

private void afterStart() { println "actor2 has started" }

private void afterStop(List undeliveredMessages) { println "actor2 has stopped" }

private void onInterrupt(InterruptedException e) { println "actor2 has been interrupted" }

private void onTimeout() { println "actor2 has timed out" }

private void onException(Exception e) { println "actor2 threw an exception" } }