From 8f63caef6e5a0fd88835d4be2b09f3ace82c4f79 Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Sat, 18 Jun 2011 22:47:23 +0000 Subject: [PATCH] Add a super-interface containing just isApplicable for NodeRequest and NodeAction to let findApplicableNodes be used on both. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6661 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../crowd/chat/server/ChatChannelManager.java | 4 +-- .../presents/peer/server/PeerManager.java | 29 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/threerings/crowd/chat/server/ChatChannelManager.java b/src/main/java/com/threerings/crowd/chat/server/ChatChannelManager.java index ee6cde7b0..c48f4d671 100644 --- a/src/main/java/com/threerings/crowd/chat/server/ChatChannelManager.java +++ b/src/main/java/com/threerings/crowd/chat/server/ChatChannelManager.java @@ -134,7 +134,7 @@ public abstract class ChatChannelManager public void collectChatHistory (final Name user, final ResultListener lner) { _peerMan.invokeNodeRequest(new NodeRequest() { - @Override public boolean isApplicable (NodeObject nodeobj) { + public boolean isApplicable (NodeObject nodeobj) { return true; // poll all nodes } @Override protected void execute (InvocationService.ResultListener listener) { @@ -401,7 +401,7 @@ public abstract class ChatChannelManager public ChannelAction (ChatChannel channel) { _channel = channel; } - @Override public boolean isApplicable (NodeObject nodeobj) { + public boolean isApplicable (NodeObject nodeobj) { return ((CrowdNodeObject)nodeobj).hostedChannels.contains(_channel); } protected ChatChannel _channel; diff --git a/src/main/java/com/threerings/presents/peer/server/PeerManager.java b/src/main/java/com/threerings/presents/peer/server/PeerManager.java index 078c827c4..26428fb5f 100644 --- a/src/main/java/com/threerings/presents/peer/server/PeerManager.java +++ b/src/main/java/com/threerings/presents/peer/server/PeerManager.java @@ -143,15 +143,19 @@ public abstract class PeerManager void fail (String peerName); } + public static interface NodeApplicant + { + /** Returns true if this should be executed on the specified node. This will be + * called on the originating server to decide whether or not to deliver the action to the + * server in question. */ + boolean isApplicable (NodeObject nodeobj); + } + /** * Encapsulates code that is meant to be executed one or more servers. */ - public static abstract class NodeAction implements Streamable.Closure + public static abstract class NodeAction implements Streamable.Closure, NodeApplicant { - /** Returns true if this action should be executed on the specified node. This will be - * called on the originating server to decide whether or not to deliver the action to the - * server in question. */ - public abstract boolean isApplicable (NodeObject nodeobj); /** Invokes the action on the target server. */ public void invoke () { @@ -168,13 +172,8 @@ public abstract class PeerManager /** * Encapsulates code that is meant to be executed one or more servers and return a result. */ - public static abstract class NodeRequest implements Streamable.Closure + public static abstract class NodeRequest implements Streamable.Closure, NodeApplicant { - /** Returns true if this request should be executed on the specified node. This will be - * called on the originating server to decide whether or not to deliver the request to the - * server in question. */ - public abstract boolean isApplicable (NodeObject nodeobj); - /** Invokes the action on the target server. */ public void invoke (final InvocationService.ResultListener listener) { try { @@ -529,16 +528,16 @@ public abstract class PeerManager } /** - * Returns all nodes for which request.isApplicable returns true. + * Returns all nodes for which applicant.isApplicable returns true. */ - public Set findApplicableNodes (NodeRequest request) + public Set findApplicableNodes (NodeApplicant applicant) { Set nodes = Sets.newHashSet(); - if (request.isApplicable(_nodeobj)) { + if (applicant.isApplicable(_nodeobj)) { nodes.add(_nodeobj.nodeName); } for (PeerNode peer : _peers.values()) { - if (request.isApplicable(peer.nodeobj)) { + if (applicant.isApplicable(peer.nodeobj)) { nodes.add(peer.getNodeName()); } }