From 6b67de9fcac98c4d0166b1e9ef4371a718a85818 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 17 Jul 2007 22:03:12 +0000 Subject: [PATCH] Looking something up in all the peer node objects is tricky, so let's encapsulate it into a mechanism that takes care of the trickiness for us. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4770 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/peer/server/PeerManager.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/java/com/threerings/presents/peer/server/PeerManager.java b/src/java/com/threerings/presents/peer/server/PeerManager.java index a21b5590d..c0f8d35b7 100644 --- a/src/java/com/threerings/presents/peer/server/PeerManager.java +++ b/src/java/com/threerings/presents/peer/server/PeerManager.java @@ -97,6 +97,12 @@ public class PeerManager public void droppedLock (NodeObject.Lock lock); } + /** Used by {@link #lookupNodeDatum}. */ + public static interface Lookup + { + public T lookup (NodeObject nodeobj); + } + /** * Creates a peer manager which will create a {@link NodeRepository} which will be used to * publish our existence and discover the other nodes. @@ -216,6 +222,29 @@ public class PeerManager } } + /** + * Locates a datum from among the set of peer {@link NodeObject}s. Objects are searched in + * arbitrary order and the first non-null value returned by the supplied lookup operation is + * returned to the caller. Null if all lookup operations returned null. + */ + public T lookupNodeDatum (Lookup op) + { + T value = op.lookup(_nodeobj); + if (value != null) { + return value; + } + for (PeerNode peer : _peers.values()) { + if (peer.nodeobj == null) { + continue; + } + value = op.lookup(peer.nodeobj); + if (value != null) { + return value; + } + } + return value; + } + /** * Returns true if the supplied peer credentials match our shared secret. */