Skip to content

Instantly share code, notes, and snippets.

@swapnil-kotwal-sp
Last active August 29, 2015 14:06
Show Gist options
  • Save swapnil-kotwal-sp/b2dbb71444c465d51195 to your computer and use it in GitHub Desktop.
Save swapnil-kotwal-sp/b2dbb71444c465d51195 to your computer and use it in GitHub Desktop.
Example for A java actor library https://github.com/edescourtis/actor
package com.test.actor;
import com.benbria.actor.Actor;
import com.benbria.actor.Behaviour;
import com.benbria.actor.ThreadActor;
public class ActorExample {
public static void main(String[] args) throws InterruptedException {
Actor<String> actor = ThreadActor.spawn(new Behaviour<String>() {
@Override
public boolean receive(Actor<String> self, String msg) {
System.out.println("Got: " + msg);
return !msg.equals("stop");
}
@Override
public void exception(Actor<String> self, Exception e) {
}
});
actor.send("hello");
actor.send("world");
Thread.sleep(1000);
actor.send("stop");
// as soon as stop message sent to actor, it will stop
// and following lines will not printed.
actor.send("hello");
actor.send("world");
}
}
*Output:-*
Got: hello
Got: world
Got: stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment