From bfbe439942e57339d2d3ee9bb523f13e25165b42 Mon Sep 17 00:00:00 2001 From: "Ray J. Greenwell" Date: Tue, 3 Apr 2018 16:18:34 -0700 Subject: [PATCH] Configure a larger invocation listener timeout between peers. 10 minutes now, up from 90 seconds. Overrideable in PeerNode to set a different value. --- .../presents/client/InvocationDirector.java | 22 ++++++++++++++----- .../presents/peer/server/PeerNode.java | 12 ++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/threerings/presents/client/InvocationDirector.java b/core/src/main/java/com/threerings/presents/client/InvocationDirector.java index d7bd0595a..b9d8370bc 100644 --- a/core/src/main/java/com/threerings/presents/client/InvocationDirector.java +++ b/core/src/main/java/com/threerings/presents/client/InvocationDirector.java @@ -24,6 +24,7 @@ package com.threerings.presents.client; import java.util.ArrayList; import java.util.Iterator; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.samskivert.util.HashIntMap; @@ -99,6 +100,15 @@ public class InvocationDirector }); } + /** + * Set the maximum time to keep listeners if we haven't heard a response back. + */ + public void setMaximumListenerAge (long milliseconds) + { + Preconditions.checkArgument(milliseconds > 0); + _listenerMaxAge = milliseconds; + } + /** * Clears out our session information. This is called when the client ends its session with the * server. @@ -272,7 +282,7 @@ public class InvocationDirector if (listener == null) { log.warning("Received invocation response for which we have no registered listener. " + "It is possible that this listener was flushed because the response did " + - "not arrive within " + LISTENER_MAX_AGE + " milliseconds.", + "not arrive within " + _listenerMaxAge + " milliseconds.", "reqId", reqId, "methId", methodId, "args", args); return; } @@ -362,7 +372,7 @@ public class InvocationDirector } /** - * Flushes listener mappings that are older than {@link #LISTENER_MAX_AGE} milliseconds. An + * Flushes listener mappings that are older than {@link #_listenerMaxAge} milliseconds. An * alternative to flushing listeners that did not explicitly receive a response within our * expiry time period is to have the server's proxy listener send a message to the client when * it is finalized. We then know that no server entity will subsequently use that proxy @@ -373,7 +383,7 @@ public class InvocationDirector protected void flushListeners (long now) { if (_listeners.size() > 0) { - long then = now - LISTENER_MAX_AGE; + long then = now - _listenerMaxAge; Iterator iter = _listeners.values().iterator(); while (iter.hasNext()) { ListenerMarshaller lm = iter.next(); @@ -430,9 +440,9 @@ public class InvocationDirector /** The last time we flushed our listeners. */ protected long _lastFlushTime; + /** The max age of listeners. */ + protected long _listenerMaxAge = 90 * 1000L; + /** The minimum interval between listener flush attempts. */ protected static final long LISTENER_FLUSH_INTERVAL = 15000L; - - /** Listener mappings older than 90 seconds are reaped. */ - protected static final long LISTENER_MAX_AGE = 90 * 1000L; } diff --git a/core/src/main/java/com/threerings/presents/peer/server/PeerNode.java b/core/src/main/java/com/threerings/presents/peer/server/PeerNode.java index 0a062e1a8..bda3f5547 100644 --- a/core/src/main/java/com/threerings/presents/peer/server/PeerNode.java +++ b/core/src/main/java/com/threerings/presents/peer/server/PeerNode.java @@ -86,6 +86,7 @@ public class PeerNode } }; _client.addClientObserver(this); + _client.getInvocationDirector().setMaximumListenerAge(getMaximumInvocationWait()); } /** @@ -265,6 +266,14 @@ public class PeerNode log.warning("Failed to subscribe to peer's node object", "peer", _record, "cause", cause); } + /** + * Get the maximum wait for an invocation request. + */ + protected long getMaximumInvocationWait () + { + return MAX_INVOCATION_WAIT; + } + protected Communicator createCommunicator (Client client) { return new ServerCommunicator(client, _conmgr, _omgr); @@ -339,4 +348,7 @@ public class PeerNode /** The amount of time after which a node record can be considered out of date and invalid. */ protected static final long STALE_INTERVAL = 5L * 60L * 1000L; + + /** The default maximum time we wait for an invocation response from a peer. */ + protected static final long MAX_INVOCATION_WAIT = 10L * 60L * 1000L; }