Hello,

I'm currently trying to implement an async REST  service,  but I'm having
trouble getting it to work.

I was using the "@UseAsyncMethod", but the when I call the service from the
AsyncClient, the service only does the synchronous logic.

I was wondering if you have and example on How to the the async service on
REST


My service look like

@UseAsyncMethod
@Override
public Device getDevice(int orderID) {
 LOG.info("Executing operation getOrder synchronously");
Order o = new Order();
  //ORder Logic
return o;
}


public Future<?> getOrderAsync( final int  orderID) {
 LOG.info("Executing operation greetMeSometimeAsync asynchronously\n");
final AsyncHandler<Order > asyncHandler = new AsyncHandler<Order >() {

@Override
public void handleResponse(Response<Order > res) {
// TODO Auto-generated method stub
LOG.info("handling");
}
};
 final ServerAsyncResponse<Device> r = new ServerAsyncResponse<Order >();
new Thread() {
public void run() {
Order resp = new Order ();
resp.setId(1);
resp.setName("Im async");
  r.set(resp);
 try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
 LOG.info("Responding on background thread\n");
asyncHandler.handleResponse(r);
}
}.start();

return r;
}


Thanks in advance for you help.

Regards

Marco Zapata

Reply via email to