Last active
August 29, 2015 14:06
-
-
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
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
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