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
This commit is contained in:
@@ -97,6 +97,12 @@ public class PeerManager
|
|||||||
public void droppedLock (NodeObject.Lock lock);
|
public void droppedLock (NodeObject.Lock lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Used by {@link #lookupNodeDatum}. */
|
||||||
|
public static interface Lookup<T>
|
||||||
|
{
|
||||||
|
public T lookup (NodeObject nodeobj);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a peer manager which will create a {@link NodeRepository} which will be used to
|
* Creates a peer manager which will create a {@link NodeRepository} which will be used to
|
||||||
* publish our existence and discover the other nodes.
|
* 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> T lookupNodeDatum (Lookup<T> 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.
|
* Returns true if the supplied peer credentials match our shared secret.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user