Split out the way we handle the preferred port so we can override that.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4958 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Mike Thomas
2008-03-05 19:09:36 +00:00
parent 8a35738654
commit e8b5d41fb8
@@ -49,6 +49,20 @@ public class ClientCommunicator extends BlockingCommunicator
super(client);
}
/**
* Sets our preferred connection port via our preferences mechanism.
*/
protected void setPrefPort (String key, int port) {
PresentsPrefs.config.setValue(key, port);
}
/**
* Gets our preferred connection port via our preferences mechanism.
*/
protected int getPrefPort (String key, int defaultPort) {
return PresentsPrefs.config.getValue(key, defaultPort);
}
@Override // from BlockingCommunicator
protected void openChannel (InetAddress host)
throws IOException
@@ -57,7 +71,7 @@ public class ClientCommunicator extends BlockingCommunicator
// determine our preferred port
String pportKey = _client.getHostname() + ".preferred_port";
int[] ports = _client.getPorts();
int pport = PresentsPrefs.config.getValue(pportKey, ports[0]);
int pport = getPrefPort(pportKey, ports[0]);
int ppidx = Math.max(0, IntListUtil.indexOf(ports, pport));
// try connecting on each of the ports in succession
@@ -131,12 +145,12 @@ public class ClientCommunicator extends BlockingCommunicator
public void expired () {
if (clearPPI(false)) {
PresentsPrefs.config.setValue(_key, _thisPort);
setPrefPort(_key, _thisPort);
}
}
public void failed () {
PresentsPrefs.config.setValue(_key, _nextPort);
setPrefPort(_key, _nextPort);
}
protected String _key;