Created
November 5, 2010 05:58
-
-
Save vaclav/663708 to your computer and use it in GitHub Desktop.
Using GPars actors in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.lang.Closure; | |
import groovyx.gpars.actor.DynamicDispatchActor; | |
public class StatelessActorDemo { | |
public static void main(String[] args) throws InterruptedException { | |
final MyStatelessActor actor = new MyStatelessActor(); | |
actor.start(); | |
actor.send("Hello"); | |
actor.sendAndWait(10); | |
actor.sendAndContinue(10.0, new Closure(null) { | |
@Override public Object call(final Object arguments) { | |
System.out.println("Received a reply " + arguments); | |
return null; | |
} | |
}); | |
} | |
} | |
class MyStatelessActor extends DynamicDispatchActor { | |
public void onMessage(final String msg) { | |
System.out.println("Received " + msg); | |
replyIfExists("Thank you"); | |
} | |
public void onMessage(final Integer msg) { | |
System.out.println("Received a number " + msg); | |
replyIfExists("Thank you"); | |
} | |
public void onMessage(final Object msg) { | |
System.out.println("Received an object " + msg); | |
replyIfExists("Thank you"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment