From c88ca10d26a29f24d2076f885196a6b776ca306a Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 6 Nov 2009 22:00:30 +0000 Subject: [PATCH] Provide a means of adjusting the select loop time. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5988 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../server/net/ConnectionManager.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/java/com/threerings/presents/server/net/ConnectionManager.java b/src/java/com/threerings/presents/server/net/ConnectionManager.java index e75f1dc2c..9263d4f6c 100644 --- a/src/java/com/threerings/presents/server/net/ConnectionManager.java +++ b/src/java/com/threerings/presents/server/net/ConnectionManager.java @@ -136,6 +136,15 @@ public class ConnectionManager extends LoopingThread _authors.add(author); } + /** + * Sets the number of milliseconds to block in the select() method before checking for outgoing + * messages. + */ + public void setSelectLoopTime (int time) + { + _selectLoopTime = time; + } + /** * Instructs us to execute the specified runnable when the connection manager thread exits. * Note: this will be executed on the connection manager thread, so don't do anything @@ -574,10 +583,10 @@ public class ConnectionManager extends LoopingThread Set ready = null; int eventCount; try { -// log.debug("Selecting from " + _selector.keys() + " (" + SELECT_LOOP_TIME + ")."); +// log.debug("Selecting from " + _selector.keys() + " (" + _selectLoopTime + ")."); // check for incoming network events - eventCount = _selector.select(SELECT_LOOP_TIME); + eventCount = _selector.select(_selectLoopTime); ready = _selector.selectedKeys(); if (eventCount == 0) { if (ready.size() == 0) { @@ -1245,6 +1254,12 @@ public class ConnectionManager extends LoopingThread /** Used to periodically report connection manager activity when in debug mode. */ protected long _lastDebugStamp; + /** How long we wait for network events before checking our running flag to see if we should + * still be running. We don't want to loop too tightly, but we need to make sure we don't sit + * around listening for incoming network events too long when there are outgoing messages in + * the queue. */ + protected volatile int _selectLoopTime = 100; + /** A runnable to execute when the connection manager thread exits. */ protected volatile Runnable _onExit; @@ -1254,12 +1269,6 @@ public class ConnectionManager extends LoopingThread @Inject protected PresentsDObjectMgr _omgr; @Inject protected PresentsServer _server; - /** How long we wait for network events before checking our running flag to see if we should - * still be running. We don't want to loop too tightly, but we need to make sure we don't sit - * around listening for incoming network events too long when there are outgoing messages in - * the queue. */ - protected static final int SELECT_LOOP_TIME = 100; - /** Used to denote asynchronous close requests. */ protected static final byte[] ASYNC_CLOSE_REQUEST = new byte[0];