Skip to content

Commit

Permalink
refactor: use PGProperty enum instead of text ref for targetServerTyp…
Browse files Browse the repository at this point in the history
…e, hostRecheckSeconds, loadBalanceHosts (#912) (#915)
  • Loading branch information
zemian authored and vlsi committed Aug 10, 2017
1 parent 50d5dd3 commit b0cfc33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ public QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, String user, Strin

// - the targetServerType setting
HostRequirement targetServerType;
String targetServerTypeStr = PGProperty.TARGET_SERVER_TYPE.get(info);
try {
targetServerType =
HostRequirement.valueOf(info.getProperty("targetServerType", HostRequirement.any.name()));
targetServerType = HostRequirement.valueOf(targetServerTypeStr);
} catch (IllegalArgumentException ex) {
throw new PSQLException(
GT.tr("Invalid targetServerType value: {0}", info.getProperty("targetServerType")),
GT.tr("Invalid targetServerType value: {0}", targetServerTypeStr),
PSQLState.CONNECTION_UNABLE_TO_CONNECT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

package org.postgresql.hostchooser;

import static java.lang.Boolean.parseBoolean;
import static java.lang.Integer.parseInt;
import static java.util.Arrays.asList;
import static java.util.Collections.shuffle;
import static java.util.Collections.sort;

import org.postgresql.PGProperty;
import org.postgresql.hostchooser.GlobalHostStatusTracker.HostSpecStatus;
import org.postgresql.util.HostSpec;
import org.postgresql.util.PSQLException;

import java.util.ArrayList;
import java.util.Comparator;
Expand All @@ -33,8 +33,12 @@ protected MultiHostChooser(HostSpec[] hostSpecs, HostRequirement targetServerTyp
Properties info) {
this.hostSpecs = hostSpecs;
this.targetServerType = targetServerType;
hostRecheckTime = parseInt(info.getProperty("hostRecheckSeconds", "10")) * 1000;
loadBalance = parseBoolean(info.getProperty("loadBalanceHosts", "false"));
try {
hostRecheckTime = PGProperty.HOST_RECHECK_SECONDS.getInt(info) * 1000;
loadBalance = PGProperty.LOAD_BALANCE_HOSTS.getBoolean(info);
} catch (PSQLException e) {
throw new RuntimeException(e);
}
}

@Override
Expand Down

0 comments on commit b0cfc33

Please sign in to comment.