From 96fb4752b32e3ed8a58e17c5a9a7f104eaff0c44 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 10 Jan 2009 22:51:26 +0000 Subject: [PATCH] Make it easy to determine how many (if any) nodes on which your function was called. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5631 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/presents/peer/server/PeerManager.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/presents/peer/server/PeerManager.java b/src/java/com/threerings/presents/peer/server/PeerManager.java index 1c15b0e75..d5ac8b92a 100644 --- a/src/java/com/threerings/presents/peer/server/PeerManager.java +++ b/src/java/com/threerings/presents/peer/server/PeerManager.java @@ -28,6 +28,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import com.google.common.base.Function; +import com.google.common.base.Predicate; import com.google.common.collect.Maps; import com.google.inject.Inject; import com.google.inject.Injector; @@ -290,14 +291,20 @@ public abstract class PeerManager * Invokes the supplied function on all node objects (except the local node). A caller * that needs to call an invocation service method on a remote node should use this mechanism * to locate the appropriate node (or nodes) and call the desired method. + * + * @return the number of times the invoked function returned true. */ - public void invokeOnNodes (Function,Void> func) + public int invokeOnNodes (Function,Boolean> func) { + int invoked = 0; for (PeerNode peer : _peers.values()) { if (peer.nodeobj != null) { - func.apply(Tuple.newTuple(peer.getClient(), peer.nodeobj)); + if (func.apply(Tuple.newTuple(peer.getClient(), peer.nodeobj))) { + invoked++; + } } } + return invoked; } /**