-
1. Re: Common id between @Asynchronous method and a caller's Future<V>?
wdfink Aug 30, 2012 4:58 AM (in response to kwatsen)No, it will be against the EJB specification.
What is the usecase behind?
-
2. Re: Common id between @Asynchronous method and a caller's Future<V>?
kwatsen Aug 30, 2012 1:00 PM (in response to wdfink)The use-case behind is to support progress monitoring during the execution of a long running request (LRR).
Specifically, I have a stateless session bean that provides an EJB/REST API to start a LRR:
@POST
@Path("/some-long-running-request")
@Consumes({ "application/xml" })
@Produces({ "application/xml" })
public AsyncMethodOutput some_long_running_request(@Context SecurityContext context, @QueryParam("queue") String queueAddress, AsyncMethodInput asyncMethodInput) throws Exception {
// lookup JMS queue from queue-name
Queue queue = (Queue)HornetQDestination.fromAddress(queueAddress);
// extract list of targets from asyncMethodInput
List<Integer> targetList = asyncMethodInput.getTargets();
// execute the async version of self
Future<Void> future = ctx.getBusinessObject(MyTestService.class).some_long_running_request(queue, targetList);
// register Future with systemManager [Note: systemManager is @Singleton]
// warning: systemManager needs to calculate a "taskId" that is same as what the async method calculates (see below)
taskId = systemManager.registerFutureObject(future); // this is what I'm trying to figure out how to support!
// return associated taskId
return new AsyncMethodOutput(taskId);
}
Then, in the async version of the same method:
@Asynchronous
public Future<Void> some_long_running_request(Queue queue, List<Integer> targetList) throws Exception {
// determine the "taskId" progress-updates should use when posting to queue
taskId = ???
// alert system manager that this taskId is running
systemManager.registerActiveTask(taskId);
// fall into work loop
while(myContext.wasCancelCalled() == false) {
// do some work
// post progress-update to queue
}
// alert system manager that this taskId is completed
systemManager.deregisterActiveTask(taskId);
// we only return a Future for client cancellation
return new AsyncResult<Void>(null);
}
Lastly, SystemManager would have API enabling clients to list actively running tasks and cancel anyone by its "taskId"
Thanks