Skip to content

Commit

Permalink
Honor new round-robin property
Browse files Browse the repository at this point in the history
If round-robin equals true, if we have defined alternate hosts/ports,
we round-robin through those hosts/ports instead of starting at the
primary port on every attempt.

The patch was suggested in jpos-users by Bhavik Kumar, we just added
an option to make it configurable, with a default to the original
behaviour (round-robin=false)
  • Loading branch information
ar committed Jul 28, 2015
1 parent e4a8831 commit f93d986
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Bjarne Henriksen <[email protected]>
Michał Wiercioch <[email protected]>
Grzegorz Wieczorek <[email protected]>
Martin Muguiro <[email protected]>
Bhavik Kumar <[email protected]>

Contributors from other OpenSource projects
-------------------------------------------
Expand Down
10 changes: 8 additions & 2 deletions jpos/src/main/java/org/jpos/iso/BaseChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public abstract class BaseChannel extends Observable
protected String originalRealm = null;
protected byte[] header = null;
private static final int DEFAULT_TIMEOUT = 300000;
private int nextHostPort = 0;
private boolean roundRobin = false;

/**
* constructor shared by server and client
Expand Down Expand Up @@ -320,10 +322,13 @@ protected Socket newSocket (String[] hosts, int[] ports, LogEvent evt)
throws IOException
{
Socket s = null;
if (!roundRobin)
nextHostPort = 0;
for (int i=0; i<hosts.length; i++) {
try {
evt.addMessage (hosts[i]+":"+ports[i]);
s = newSocket (hosts[i], ports[i]);
int ii = nextHostPort++ % hosts.length;
evt.addMessage ("Try " + i + " " + hosts[ii]+":"+ports[ii]);
s = newSocket (hosts[ii], ports[ii]);
break;
} catch (IOException e) {
evt.addMessage (" " + e.getMessage());
Expand Down Expand Up @@ -1006,6 +1011,7 @@ public void setConfiguration (Configuration cfg)
setOverrideHeader(cfg.getBoolean ("override-header", false));
keepAlive = cfg.getBoolean ("keep-alive", false);
expectKeepAlive = cfg.getBoolean ("expect-keep-alive", false);
roundRobin = cfg.getBoolean ("round-robin", false);
if (socketFactory != this && socketFactory instanceof Configurable)
((Configurable)socketFactory).setConfiguration (cfg);
try {
Expand Down

0 comments on commit f93d986

Please sign in to comment.