final Callable executionCallable;
if(isTwoWay)
{
// Defer the invoke until the transaction commits.
Scheduler scheduler = executionEnvironment.getScheduler();
executionCallable = new TwoWayCallable(mex.getMessageExchangeId());
scheduler.registerSynchronizer(new Scheduler.Synchronizer() {
public void afterCompletion(boolean success)
{
// If the TX is rolled back, then we don't send the request.
if (!success) return;
// The invocation must happen in a separate thread, holding on the afterCompletion
// blocks other operations that could have been listed there as well.
ExecutorService executorService = executionEnvironment.getExecutorService();
executorService.submit(executionCallable);
}
public void beforeCompletion(){}
}
);
mex.replyAsync();
}
else
{
// one-way invocation, also defer the invoke until the transaction commits.
Scheduler scheduler = executionEnvironment.getScheduler();
executionCallable = new OneWayCallable(mex.getMessageExchangeId());
scheduler.registerSynchronizer(new Scheduler.Synchronizer() {
public void beforeCompletion() {
}