3030
3131import java .io .IOException ;
3232import java .io .PrintStream ;
33+ import java .time .Duration ;
34+ import java .time .Instant ;
3335import java .util .*;
3436import java .util .concurrent .ScheduledFuture ;
3537import java .util .concurrent .TimeUnit ;
@@ -58,7 +60,7 @@ public class QMUX
5860
5961 List <ISORequestListener > listeners ;
6062 private volatile int rx , tx , rxExpired , txExpired , rxPending , rxUnhandled , rxForwarded ;
61- private volatile long lastTxn = 0L ;
63+ private volatile Duration lastTxn = Duration . ZERO ;
6264 private boolean listenerRegistered ;
6365 public QMUX () {
6466 super ();
@@ -161,7 +163,7 @@ public ISOMsg request (ISOMsg m, long timeout) throws ISOException {
161163 if (resp != null )
162164 {
163165 rx ++;
164- lastTxn = System .currentTimeMillis ( );
166+ lastTxn = Duration . ofNanos ( System .nanoTime () );
165167 }else {
166168 rxExpired ++;
167169 if (m .getDirection () != ISOMsg .OUTGOING )
@@ -351,7 +353,7 @@ public boolean removeISORequestListener(ISORequestListener l) {
351353 }
352354 public synchronized void resetCounters () {
353355 rx = tx = rxExpired = txExpired = rxPending = rxUnhandled = rxForwarded = 0 ;
354- lastTxn = 0l ;
356+ lastTxn = Duration . ZERO ;
355357 }
356358 public String getCountersAsString () {
357359 StringBuffer sb = new StringBuffer ();
@@ -366,10 +368,10 @@ public String getCountersAsString () {
366368 sb .append (", connected=" );
367369 sb .append (Boolean .toString (isConnected ()));
368370 sb .append (", last=" );
369- sb .append (lastTxn );
370- if (lastTxn > 0 ) {
371+ sb .append (getLastTxnTimestampInMillis () );
372+ if (lastTxn != Duration . ZERO ) {
371373 sb .append (", idle=" );
372- sb .append (System .currentTimeMillis () - lastTxn );
374+ sb .append (Duration . ofNanos ( System .nanoTime ()). minus ( lastTxn ). toMillis () );
373375 sb .append ("ms" );
374376 }
375377 return sb .toString ();
@@ -413,10 +415,10 @@ public int getRXForwarded() {
413415 }
414416
415417 public long getLastTxnTimestampInMillis () {
416- return lastTxn ;
418+ return Instant . now (). minus ( Duration . ofNanos ( System . nanoTime ()). minus ( lastTxn )). toEpochMilli () ;
417419 }
418420 public long getIdleTimeInMillis () {
419- return lastTxn > 0L ? System .currentTimeMillis () - lastTxn : -1L ;
421+ return lastTxn != Duration . ZERO ? Duration . ofNanos ( System .nanoTime ()). minus ( lastTxn ). toMillis () : -1L ;
420422 }
421423
422424 protected void processUnhandled (ISOMsg m ) {
@@ -529,7 +531,7 @@ public void responseReceived (ISOMsg response) {
529531 synchronized (QMUX .this ) {
530532 rx ++;
531533 rxPending --;
532- lastTxn = System .currentTimeMillis ( );
534+ lastTxn = Duration . ofNanos ( System .nanoTime () );
533535 }
534536 long elapsed = chrono .elapsed ();
535537 metrics .record ("all" , elapsed );
0 commit comments