Skip to content

Commit

Permalink
RESTEASY-1800 (#1406)
Browse files Browse the repository at this point in the history
* Use resteasy's scheduler to handle timeout

* Remove aysncContext timeout setting

* Set asynContext timeout -1 and resteasy will take care of the timeout thing

* timeout <=0
  • Loading branch information
asoldano committed Feb 8, 2018
1 parent 2b3cb5e commit 08d1ee4
Showing 1 changed file with 22 additions and 22 deletions.
Expand Up @@ -137,31 +137,29 @@ public void initialRequestThreadFinished()
@Override
public boolean setTimeout(long time, TimeUnit unit) throws IllegalStateException
{
//getAsyncContext().setTimeout(-1);
synchronized (responseLock)
{
if (done || cancelled) return false;
Thread thread = creatingThread.get();
if (thread != null && thread != Thread.currentThread()) {
// this is to get around TCK tests that call setTimeout in a separate thread which is illegal.
if (timeoutFuture != null && !timeoutFuture.cancel(false)) {
return false;
}
Runnable task = new Runnable() {
@Override
public void run()
{
LogMessages.LOGGER.debug(Messages.MESSAGES.scheduledTimeout());
handleTimeout();
}
};
LogMessages.LOGGER.debug(Messages.MESSAGES.schedulingTimeout());
timeoutFuture = asyncScheduler.schedule(task, time, unit);
} else {
AsyncContext asyncContext = getAsyncContext();
long l = unit.toMillis(time);
asyncContext.setTimeout(l);
}
if (done || cancelled)
return false;

// this is to get around TCK tests that call setTimeout in a separate thread which is illegal.
if (timeoutFuture != null && !timeoutFuture.cancel(false))
{
return false;
}
if (time <= 0) return true;
Runnable task = new Runnable()
{
@Override
public void run()
{
LogMessages.LOGGER.debug(Messages.MESSAGES.scheduledTimeout());
handleTimeout();
}
};
LogMessages.LOGGER.debug(Messages.MESSAGES.schedulingTimeout());
timeoutFuture = asyncScheduler.schedule(task, time, unit);
}
return true;
}
Expand Down Expand Up @@ -322,6 +320,8 @@ protected AsyncContext setupAsyncContext()
AsyncContext asyncContext = servletRequest.startAsync();
asyncContext.addListener(asynchronousResponse);
wasSuspended = true;
//set time out to -1 and resteasy will take care of timeout
asyncContext.setTimeout(-1);
return asyncContext;
}

Expand Down

0 comments on commit 08d1ee4

Please sign in to comment.