Remove IMonitorHandler

This commit is contained in:
Tony Garnock-Jones 2020-12-06 00:09:06 +01:00
parent fb7e17b624
commit 9965027eb6
2 changed files with 7 additions and 11 deletions

View File

@ -6,6 +6,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.logging.Level;
@ -28,7 +29,7 @@ public class Actor implements Executor {
private Throwable _exitReason = null;
private boolean _isCounted = true;
private Set<Actor> _links = null;
private Map<Object, Remote<IMonitorHandler>> _monitors = null;
private Map<Object, Remote<BiConsumer<Actor, Object>>> _monitors = null;
private Consumer<Actor> _exitTrap = null;
public static Actor current() {
@ -103,7 +104,7 @@ public class Actor implements Executor {
}
public<T> Remote<T> proxyFor(T o) {
return new Remote<T>(this, o);
return new Remote<>(this, o);
}
private void _perform(Runnable work, Runnable ifNotAlive) {
@ -159,12 +160,12 @@ public class Actor implements Executor {
peer.notifyExit(this);
}
}
Map<Object, Remote<IMonitorHandler>> monitoringPeers = _monitors;
Map<Object, Remote<BiConsumer<Actor, Object>>> monitoringPeers = _monitors;
if (monitoringPeers != null) {
_monitors = null;
for (var entry : monitoringPeers.entrySet()) {
final var ref = entry.getKey();
entry.getValue().async((h) -> h.handleMonitor(this, ref));
entry.getValue().async((h) -> h.accept(this, ref));
}
}
_releaseCount();
@ -273,12 +274,12 @@ public class Actor implements Executor {
return ref;
}
public synchronized void monitor(final Object ref, IMonitorHandler handler) {
public synchronized void monitor(final Object ref, BiConsumer<Actor, Object> handler) {
if (this._alive) {
if (_monitors == null) _monitors = new HashMap<>();
_monitors.put(ref, Actor.ref(handler));
} else {
Actor.ref(handler).async((h) -> h.handleMonitor(this, ref));
Actor.ref(handler).async((h) -> h.accept(this, ref));
}
}
}

View File

@ -1,5 +0,0 @@
package org.syndicate_lang.actors;
public interface IMonitorHandler {
void handleMonitor(Actor exitingPeer, Object ref);
}