Compare commits
2 Commits
7d9174c363
...
636da3f28f
Author | SHA1 | Date |
---|---|---|
|
636da3f28f | |
|
732bb0066d |
|
@ -20,6 +20,7 @@ public class Actor implements Executor {
|
||||||
|
|
||||||
private final String _name;
|
private final String _name;
|
||||||
private final Logger _logger;
|
private final Logger _logger;
|
||||||
|
final Turn _turn = new Turn(this);
|
||||||
|
|
||||||
private boolean _alive = true;
|
private boolean _alive = true;
|
||||||
private Throwable _exitReason = null;
|
private Throwable _exitReason = null;
|
||||||
|
|
|
@ -9,7 +9,6 @@ public class Turn {
|
||||||
private final static AtomicLong nextHandle = new AtomicLong(0);
|
private final static AtomicLong nextHandle = new AtomicLong(0);
|
||||||
|
|
||||||
private final Actor _actor;
|
private final Actor _actor;
|
||||||
private boolean _complete = false;
|
|
||||||
|
|
||||||
private Actor _pendingTarget = null;
|
private Actor _pendingTarget = null;
|
||||||
private Consumer<Turn> _pending0 = null;
|
private Consumer<Turn> _pending0 = null;
|
||||||
|
@ -22,7 +21,7 @@ public class Turn {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _forActor(Actor a, Consumer<Turn> f) {
|
static void _forActor(Actor a, Consumer<Turn> f) {
|
||||||
Turn t = new Turn(a);
|
Turn t = a._turn;
|
||||||
try {
|
try {
|
||||||
f.accept(t);
|
f.accept(t);
|
||||||
t.commit();
|
t.commit();
|
||||||
|
@ -31,7 +30,7 @@ public class Turn {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Turn(Actor a) {
|
Turn(Actor a) {
|
||||||
this._actor = a;
|
this._actor = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,16 +57,12 @@ public class Turn {
|
||||||
if (q2 != null) q2.accept(t);
|
if (q2 != null) q2.accept(t);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
_complete = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enqueue(Actor target, Consumer<Turn> action) {
|
private void enqueue(Actor target, Consumer<Turn> action) {
|
||||||
if (_complete) throw new IllegalStateException("Attempt to reuse a committed Turn");
|
|
||||||
if (_pending == null) {
|
if (_pending == null) {
|
||||||
if (_pendingTarget == null) {
|
if (_pendingTarget == null) {
|
||||||
_pendingTarget = target;
|
_pendingTarget = target;
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
var q = (Consumer<Turn>[]) new Consumer<?>[3];
|
|
||||||
_pending0 = action;
|
_pending0 = action;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -87,11 +82,6 @@ public class Turn {
|
||||||
_pending.computeIfAbsent(target, k -> new LinkedList<>()).add(action);
|
_pending.computeIfAbsent(target, k -> new LinkedList<>()).add(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void freshen(Consumer<Turn> action) {
|
|
||||||
if (!_complete) throw new IllegalStateException(("Attempt to freshen a non-stale Turn"));
|
|
||||||
Turn.forActor(this._actor, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Ref ref(IEntity o) {
|
public Ref ref(IEntity o) {
|
||||||
return _actor.ref(o);
|
return _actor.ref(o);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue