diff --git a/jpos/src/main/java/org/jpos/q2/iso/QMUX.java b/jpos/src/main/java/org/jpos/q2/iso/QMUX.java index fcb6651281..ceca579a93 100644 --- a/jpos/src/main/java/org/jpos/q2/iso/QMUX.java +++ b/jpos/src/main/java/org/jpos/q2/iso/QMUX.java @@ -30,6 +30,8 @@ import java.io.IOException; import java.io.PrintStream; +import java.time.Duration; +import java.time.Instant; import java.util.*; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -58,7 +60,7 @@ public class QMUX List listeners; private volatile int rx, tx, rxExpired, txExpired, rxPending, rxUnhandled, rxForwarded; - private volatile long lastTxn = 0L; + private volatile Duration lastTxn = null; private boolean listenerRegistered; public QMUX () { super (); @@ -161,7 +163,7 @@ public ISOMsg request (ISOMsg m, long timeout) throws ISOException { if (resp != null) { rx++; - lastTxn = System.currentTimeMillis(); + lastTxn = Duration.ofNanos(System.nanoTime()); }else { rxExpired++; if (m.getDirection() != ISOMsg.OUTGOING) @@ -351,7 +353,7 @@ public boolean removeISORequestListener(ISORequestListener l) { } public synchronized void resetCounters() { rx = tx = rxExpired = txExpired = rxPending = rxUnhandled = rxForwarded = 0; - lastTxn = 0l; + lastTxn = null; } public String getCountersAsString () { StringBuffer sb = new StringBuffer(); @@ -366,10 +368,10 @@ public String getCountersAsString () { sb.append (", connected="); sb.append (Boolean.toString(isConnected())); sb.append (", last="); - sb.append (lastTxn); - if (lastTxn > 0) { + sb.append (getLastTxnTimestampInMillis()); + if (lastTxn != null) { sb.append (", idle="); - sb.append(System.currentTimeMillis() - lastTxn); + sb.append(Duration.ofNanos(System.nanoTime()).minus(lastTxn).toMillis()); sb.append ("ms"); } return sb.toString(); @@ -413,10 +415,12 @@ public int getRXForwarded() { } public long getLastTxnTimestampInMillis() { - return lastTxn; + if (lastTxn == null) + return 0L; + return Instant.now().minus(Duration.ofNanos(System.nanoTime()).minus(lastTxn)).toEpochMilli(); } public long getIdleTimeInMillis() { - return lastTxn > 0L ? System.currentTimeMillis() - lastTxn : -1L; + return lastTxn != null ? Duration.ofNanos(System.nanoTime()).minus(lastTxn).toMillis() : -1L; } protected void processUnhandled (ISOMsg m) { @@ -529,7 +533,7 @@ public void responseReceived (ISOMsg response) { synchronized (QMUX.this) { rx++; rxPending--; - lastTxn = System.currentTimeMillis(); + lastTxn = Duration.ofNanos(System.nanoTime()); } long elapsed = chrono.elapsed(); metrics.record("all", elapsed); diff --git a/jpos/src/test/java/org/jpos/q2/iso/QMUXTestCase.java b/jpos/src/test/java/org/jpos/q2/iso/QMUXTestCase.java index cc656ba048..714501b4ed 100644 --- a/jpos/src/test/java/org/jpos/q2/iso/QMUXTestCase.java +++ b/jpos/src/test/java/org/jpos/q2/iso/QMUXTestCase.java @@ -67,6 +67,7 @@ public static void setUp(@TempDir Path deployDir) throws IOException { }); q2 = new Q2(deployDir.toString()); q2.start(); + q2.ready(5000L); mux = NameRegistrar.get("mux.mux", 2000L); assertNotNull(mux); receivedHandback = null;