Configure a larger invocation listener timeout between peers.

10 minutes now, up from 90 seconds. Overrideable in PeerNode to set
a different value.
This commit is contained in:
Ray J. Greenwell
2018-04-03 16:18:34 -07:00
parent eb9e96ab2b
commit bfbe439942
2 changed files with 28 additions and 6 deletions
@@ -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<ListenerMarshaller> 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;
}
@@ -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;
}