63 lines
2.2 KiB
Java
63 lines
2.2 KiB
Java
package org.syndicate_lang.actors.example.example1;
|
|
|
|
import org.syndicate_lang.actors.Actor;
|
|
import org.syndicate_lang.actors.Entity;
|
|
import org.syndicate_lang.actors.Ref;
|
|
import org.syndicate_lang.actors.Turn;
|
|
|
|
public class Main extends Entity {
|
|
public static void main(String[] args) throws InterruptedException {
|
|
Actor.convenientLogging();
|
|
Turn.forActor(new Actor().daemonize(), t -> {
|
|
final var vh = Actor.forEntity(new ValueHolder<>("There"));
|
|
vh.getActor().daemonize();
|
|
final var m = Actor.boot(u -> {
|
|
Main main = new Main();
|
|
u.later(10, v -> main.run(v, vh));
|
|
return main;
|
|
});
|
|
|
|
t.message_(vh, new IValueHolder.Get(t.ref(new Entity() {
|
|
public void message_(Turn t0, Object v0) {
|
|
System.out.println("Value: " + v0);
|
|
t0.message_(vh, new IValueHolder.Set<>("Second"));
|
|
t0.message_(vh, new IValueHolder.Get(t0.ref(new Entity() {
|
|
public void message_(Turn t1, Object v1) {
|
|
System.out.println("Value: " + v1);
|
|
System.out.println("Cell: " + vh);
|
|
}
|
|
})));
|
|
}
|
|
})));
|
|
});
|
|
|
|
Actor.awaitAll();
|
|
System.out.println("Overall main returning");
|
|
}
|
|
|
|
private Actor me;
|
|
private int greetingCounter = 0;
|
|
|
|
public void run(Turn t0, Ref vh) {
|
|
me = t0.getActor();
|
|
t0.message_(vh, new IValueHolder.Get(t0.ref(new Entity() {
|
|
public void message_(Turn t1, Object v1) {
|
|
Main.this.greet((String) v1);
|
|
t1.message_(vh, new IValueHolder.Set<>("World"));
|
|
t1.every(1000, t -> {
|
|
if (greetingCounter >= 3) t.quit();
|
|
t.message_(vh, new IValueHolder.Get(t.ref(new Entity() {
|
|
public void message_(Turn t2, Object v2) {
|
|
Main.this.greet((String) v2);
|
|
}
|
|
})));
|
|
});
|
|
}
|
|
})));
|
|
}
|
|
|
|
public void greet(String who) {
|
|
me.log().info((greetingCounter++) + ": Hi " + who);
|
|
}
|
|
}
|