Bump language level to JDK 16 to get records; update example1
This commit is contained in:
parent
af611e1b2b
commit
d6c8a80995
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -5,6 +5,7 @@ import java.util.Map;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@ -63,11 +64,11 @@ public class Actor implements Executor {
|
||||||
return new Actor().ref(o);
|
return new Actor().ref(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Promise<Ref> boot(ThrowingSupplier<IEntity> f) {
|
public static Promise<Ref> boot(Function<Turn, IEntity> f) {
|
||||||
final Promise<Ref> p = new Promise<>();
|
final Promise<Ref> p = new Promise<>();
|
||||||
final Actor a = new Actor();
|
final Actor a = new Actor();
|
||||||
a.execute(
|
a.execute(
|
||||||
() -> p.resolveCalling(() -> a.ref(f.get())),
|
() -> Turn.forActor(a, t -> p.resolveCalling(() -> a.ref(f.apply(t)))),
|
||||||
() -> p.rejectWith(new ActorTerminated(a)));
|
() -> p.rejectWith(new ActorTerminated(a)));
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,14 +114,12 @@ public class Turn {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Promise<Turn> sync_(Ref peer) {
|
public void sync_(Ref peer, Consumer<Turn> k) {
|
||||||
Promise<Turn> p = new Promise<>();
|
|
||||||
this._sync_(peer, this.ref(new Entity() {
|
this._sync_(peer, this.ref(new Entity() {
|
||||||
public void message_(Turn t, Object _message) {
|
public void message_(Turn t, Object _message) {
|
||||||
p.resolveWith(t);
|
k.accept(t);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _sync_(Ref peer, Ref callback) {
|
private void _sync_(Ref peer, Ref callback) {
|
||||||
|
@ -134,4 +132,16 @@ public class Turn {
|
||||||
this.enqueue(peer.getActor(), t -> peer.getEntity().message_(t, body));
|
this.enqueue(peer.getActor(), t -> peer.getEntity().message_(t, body));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void later(long delayMilliseconds, Consumer<Turn> action) {
|
||||||
|
_actor.later(delayMilliseconds, () -> Turn.forActor(_actor, action));
|
||||||
|
}
|
||||||
|
|
||||||
|
public PeriodicTimer every(long periodMilliseconds, Consumer<Turn> action) {
|
||||||
|
return every(0, periodMilliseconds, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PeriodicTimer every(long initialDelayMilliseconds, long periodMilliseconds, Consumer<Turn> action) {
|
||||||
|
return _actor.every(initialDelayMilliseconds, periodMilliseconds, () -> Turn.forActor(_actor, action));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package org.syndicate_lang.actors.example.example1;
|
package org.syndicate_lang.actors.example.example1;
|
||||||
|
|
||||||
public interface IValueHolder<T> {
|
import org.syndicate_lang.actors.Ref;
|
||||||
T get();
|
|
||||||
void set(T newValue);
|
public interface IValueHolder {
|
||||||
}
|
record Get(Ref k) implements IValueHolder {}
|
||||||
|
record Set<T>(T newValue) implements IValueHolder {}
|
||||||
|
}
|
|
@ -1,23 +1,35 @@
|
||||||
package org.syndicate_lang.actors.example.example1;
|
package org.syndicate_lang.actors.example.example1;
|
||||||
|
|
||||||
import org.syndicate_lang.actors.Actor;
|
import org.syndicate_lang.actors.Actor;
|
||||||
|
import org.syndicate_lang.actors.Entity;
|
||||||
import org.syndicate_lang.actors.Ref;
|
import org.syndicate_lang.actors.Ref;
|
||||||
|
import org.syndicate_lang.actors.Turn;
|
||||||
|
|
||||||
public class Main {
|
public class Main extends Entity {
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
Actor.convenientLogging();
|
Actor.convenientLogging();
|
||||||
final var vh = Actor.forEntity(new ValueHolder<>("There"));
|
Turn.forActor(new Actor().daemonize(), t -> {
|
||||||
vh.getActor().daemonize();
|
final var vh = Actor.forEntity(new ValueHolder<>("There"));
|
||||||
final var m = Actor.forEntity(new Main());
|
vh.getActor().daemonize();
|
||||||
m.async(10, (m_, ac) -> m_.run(ac, vh));
|
final var m = Actor.boot(u -> {
|
||||||
|
Main main = new Main();
|
||||||
|
u.later(10, v -> main.run(v, vh));
|
||||||
|
return main;
|
||||||
|
});
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
t.message_(vh, new IValueHolder.Get(t.ref(new Entity() {
|
||||||
IValueHolder<String> vv = vh.syncProxy(IValueHolder.class);
|
public void message_(Turn t0, Object v0) {
|
||||||
|
System.out.println("Value: " + v0);
|
||||||
System.out.println("Value: " + vv.get());
|
t0.message_(vh, new IValueHolder.Set<>("Second"));
|
||||||
vv.set("Second");
|
t0.message_(vh, new IValueHolder.Get(t0.ref(new Entity() {
|
||||||
System.out.println("Value: " + vv.get());
|
public void message_(Turn t1, Object v1) {
|
||||||
System.out.println("Underlying: " + Ref.from(vv));
|
System.out.println("Value: " + v1);
|
||||||
|
System.out.println("Cell: " + vh);
|
||||||
|
}
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
})));
|
||||||
|
});
|
||||||
|
|
||||||
Actor.awaitAll();
|
Actor.awaitAll();
|
||||||
System.out.println("Overall main returning");
|
System.out.println("Overall main returning");
|
||||||
|
@ -26,14 +38,22 @@ public class Main {
|
||||||
private Actor me;
|
private Actor me;
|
||||||
private int greetingCounter = 0;
|
private int greetingCounter = 0;
|
||||||
|
|
||||||
public void run(Actor me, Ref<ValueHolder<String>> vh) {
|
public void run(Turn t0, Ref vh) {
|
||||||
this.me = me;
|
me = t0.getActor();
|
||||||
this.greet((String) vh.syncProxy(IValueHolder.class).get());
|
t0.message_(vh, new IValueHolder.Get(t0.ref(new Entity() {
|
||||||
vh.syncVoid((v, _ac) -> v.set("World"));
|
public void message_(Turn t1, Object v1) {
|
||||||
me.every(1000, () -> {
|
Main.this.greet((String) v1);
|
||||||
if (greetingCounter >= 3) me.stop();
|
t1.message_(vh, new IValueHolder.Set<>("World"));
|
||||||
this.greet(vh.sync((v, _ac) -> v.get()).await());
|
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) {
|
public void greet(String who) {
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
package org.syndicate_lang.actors.example.example1;
|
package org.syndicate_lang.actors.example.example1;
|
||||||
|
|
||||||
public class ValueHolder<T> implements IValueHolder<T> {
|
import org.syndicate_lang.actors.Entity;
|
||||||
|
import org.syndicate_lang.actors.Turn;
|
||||||
|
|
||||||
|
public class ValueHolder<T> extends Entity {
|
||||||
private T value;
|
private T value;
|
||||||
|
|
||||||
public ValueHolder(T initialValue) {
|
public ValueHolder(T initialValue) {
|
||||||
this.value = initialValue;
|
this.value = initialValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T get() {
|
@Override
|
||||||
return this.value;
|
public void message_(Turn turn, Object body) {
|
||||||
}
|
if (body instanceof IValueHolder.Get op) {
|
||||||
|
turn.message_(op.k(), this.value);
|
||||||
public void set(T newValue) {
|
} else if (body instanceof IValueHolder.Set) {
|
||||||
this.value = newValue;
|
IValueHolder.Set<T> op = (IValueHolder.Set<T>) body;
|
||||||
|
this.value = op.newValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/java" isTestSource="true" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/java/org/syndicate_lang/actors/example/example2" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
|
Loading…
Reference in New Issue