* If an async timeout was not scheduled:
*
* - We go through the same flow as we receive the same interfaces just the "timer.clear()" will do nothing.
*/
// get the timer we'll use to perform the timeout
TimerListener l = timer.get();
// remove the timer from the scheduler
timer.clear();
// determine how long we should wait for, taking into account time since work started
// and when this thread came in to block. If invocationTime hasn't been set then assume time remaining is entire timeout value
// as this maybe a case of multiple threads trying to run this command in which one thread wins but even before the winning thread is able to set
// the starttime another thread going via the Cached command route gets here first.
long timeout = originalCommand.properties.executionIsolationThreadTimeoutInMilliseconds().get();
long timeRemaining = timeout;
long currTime = System.currentTimeMillis();
if (originalCommand.invocationStartTime != -1) {
timeRemaining = (originalCommand.invocationStartTime
+ originalCommand.properties.executionIsolationThreadTimeoutInMilliseconds().get())
- currTime;
}
if (timeRemaining > 0) {
// we need to block with the calculated timeout
try {
return f.get(timeRemaining, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
if (l != null) {
// this perform the timeout logic on the Observable/Observer
l.tick();
}
}
} else {
// this means it should have already timed out so do so if it is not completed
if (!f.isDone()) {
if (l != null) {
l.tick();
}
}
}
}
}