Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
properly handle counters in async requests
  • Loading branch information
ar committed Apr 25, 2017
1 parent 5376a0f commit 903f1a2
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions jpos/src/main/java/org/jpos/q2/iso/QMUX.java
Expand Up @@ -178,7 +178,11 @@ public void request (ISOMsg m, long timeout, ISOResponseListener rl, Object hand
ar.setFuture(getScheduledThreadPoolExecutor().schedule(ar, timeout, TimeUnit.MILLISECONDS));
}
isp.out (req, ar, timeout);
sp.out (out, m, timeout);
if (timeout > 0)
sp.out (out, m, timeout);
else
sp.out (out, m);
synchronized (this) { tx++; rxPending++; }
}
public void notify (Object k, Object value) {
Object obj = sp.inp (k);
Expand Down Expand Up @@ -433,7 +437,7 @@ private void append (StringBuffer sb, String name, int value) {
sb.append (name);
sb.append (value);
}
public static class AsyncRequest implements Runnable {
public class AsyncRequest implements Runnable {
ISOResponseListener rl;
Object handBack;
ScheduledFuture future;
Expand All @@ -446,10 +450,19 @@ public void setFuture(ScheduledFuture future) {
this.future = future;
}
public void responseReceived (ISOMsg response) {
if (future == null || future.cancel(false))
rl.responseReceived (response, handBack);
if (future == null || future.cancel(false)) {
synchronized (QMUX.this) {
rx++;
rxPending--;
lastTxn = System.currentTimeMillis();
}
rl.responseReceived(response, handBack);
}
}
public void run() {
synchronized(QMUX.this) {
rxPending--;
}
rl.expired(handBack);
}
}
Expand Down

0 comments on commit 903f1a2

Please sign in to comment.