use of javax.ws.rs.container.TimeoutHandler in project javaee7-samples by javaee-samples.
the class MyResource method getList.
// @Resource(name = "DefaultManagedThreadFactory")
// ManagedThreadFactory threadFactory;
@GET
public void getList(@Suspended final AsyncResponse ar) throws NamingException {
ar.setTimeoutHandler(new TimeoutHandler() {
@Override
public void handleTimeout(AsyncResponse ar) {
ar.resume("Operation timed out");
}
});
ar.setTimeout(4000, TimeUnit.MILLISECONDS);
ar.register(new MyCompletionCallback());
ar.register(new MyConnectionCallback());
ManagedThreadFactory threadFactory = (ManagedThreadFactory) new InitialContext().lookup("java:comp/DefaultManagedThreadFactory");
Executors.newSingleThreadExecutor(threadFactory).submit(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3000);
ar.resume(response[0]);
} catch (InterruptedException ex) {
}
}
});
}
use of javax.ws.rs.container.TimeoutHandler in project jersey by jersey.
the class AsyncCancelTimeoutResource method setTimeout.
@POST
@Path("timeout")
public void setTimeout(final String stage) throws Exception {
final AsyncResponse async = stages[Integer.parseInt(stage)].take();
async.setTimeoutHandler(new TimeoutHandler() {
@Override
public void handleTimeout(final AsyncResponse response) {
response.cancel();
}
});
async.setTimeout(200L, TimeUnit.MILLISECONDS);
stages[Integer.parseInt(stage) + 1].add(async);
}
use of javax.ws.rs.container.TimeoutHandler in project jersey by jersey.
the class AsyncResumeTimeoutResource method setTimeOut.
@POST
@Path("timeout")
public void setTimeOut(final Integer millis) throws InterruptedException {
final AsyncResponse asyncResponse = queue.take();
final boolean timeout1 = asyncResponse.setTimeout(millis, TimeUnit.MILLISECONDS);
asyncResponse.setTimeoutHandler(new TimeoutHandler() {
@Override
public void handleTimeout(final AsyncResponse asyncResponse) {
final boolean timeout2 = asyncResponse.setTimeout(millis, TimeUnit.MILLISECONDS);
asyncResponse.setTimeoutHandler(new TimeoutHandler() {
@Override
public void handleTimeout(final AsyncResponse asyncResponse) {
asyncResponse.resume("timeout1=" + timeout1 + "_timeout2=" + timeout2 + "_handled");
}
});
}
});
}
use of javax.ws.rs.container.TimeoutHandler in project jersey by jersey.
the class AsyncTimeoutResource method setTimeOut.
@POST
@Path("timeout")
public void setTimeOut(final Integer millis) throws InterruptedException {
final AsyncResponse asyncResponse = queue.take();
final boolean timeout1 = asyncResponse.setTimeout(millis, TimeUnit.MILLISECONDS);
asyncResponse.setTimeoutHandler(new TimeoutHandler() {
@Override
public void handleTimeout(final AsyncResponse asyncResponse) {
final boolean timeout2 = asyncResponse.setTimeout(millis, TimeUnit.MILLISECONDS);
asyncResponse.setTimeoutHandler(new TimeoutHandler() {
@Override
public void handleTimeout(final AsyncResponse asyncResponse) {
asyncResponse.resume("timeout1=" + timeout1 + "_timeout2=" + timeout2 + "_handled");
asyncResponse.cancel();
}
});
}
});
}
Aggregations