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
This commit is contained in:
@@ -28,6 +28,7 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
@@ -290,14 +291,20 @@ public abstract class PeerManager
|
|||||||
* Invokes the supplied function on <em>all</em> node objects (except the local node). A caller
|
* Invokes the supplied function on <em>all</em> node objects (except the local node). A caller
|
||||||
* that needs to call an invocation service method on a remote node should use this mechanism
|
* 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.
|
* 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<Tuple<Client,NodeObject>,Void> func)
|
public int invokeOnNodes (Function<Tuple<Client,NodeObject>,Boolean> func)
|
||||||
{
|
{
|
||||||
|
int invoked = 0;
|
||||||
for (PeerNode peer : _peers.values()) {
|
for (PeerNode peer : _peers.values()) {
|
||||||
if (peer.nodeobj != null) {
|
if (peer.nodeobj != null) {
|
||||||
func.apply(Tuple.newTuple(peer.getClient(), peer.nodeobj));
|
if (func.apply(Tuple.newTuple(peer.getClient(), peer.nodeobj))) {
|
||||||
|
invoked++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return invoked;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user