Reduce API surface of Actor by avoiding subclassing

This commit is contained in:
Tony Garnock-Jones 2024-04-24 22:14:23 +02:00
parent 0835077035
commit 1d744181ec
1 changed files with 12 additions and 5 deletions

View File

@ -13,7 +13,7 @@ import java.util.logging.Logger;
/**
* I represent the shared execution context for a collection of objects; I am roughly analogous to the E concept of a Vat.
*/
public class Actor extends ForkJoinTask<Void> {
public class Actor {
private final static AtomicLong _count = new AtomicLong(0);
private final static AtomicLong _actorId = new AtomicLong(0);
protected final static ForkJoinPool _executor = new ForkJoinPool(
@ -206,14 +206,21 @@ public class Actor extends ForkJoinTask<Void> {
}
}
@Override public final Void getRawResult() { return null; }
@Override public final void setRawResult(Void v) { }
@Override public final boolean exec() { this._runWorkItems(); return false; }
private static final class Task extends ForkJoinTask<Void> {
private Actor _actor;
Task(Actor a) {
this._actor = a;
}
@Override public final Void getRawResult() { return null; }
@Override public final void setRawResult(Void v) { }
@Override public final boolean exec() { _actor._runWorkItems(); return false; }
};
private Task _task = new Task(this);
public void execute(WorkItem item) {
tail.getAndSet(item).set(item);
if (workItemCount.getAndIncrement() == 0) {
_executor.execute(this);
_executor.execute(this._task);
}
}