use of javax.resource.spi.work.WorkException in project Payara by payara.
the class WorkCoordinator method postInvoke.
/**
* Post-invoke operation. This does the following after the work is executed.
* <pre>
* 1. Releases the transaction with JTS.
* 2. Generates work completed event.
* 3. Clear the thread context.
* </pre>
*/
public void postInvoke() {
boolean txImported = (getExecutionContext(ec, work) != null && getExecutionContext(ec, work).getXid() != null);
try {
JavaEETransactionManager tm = getTransactionManager();
if (txImported) {
tm.release(getExecutionContext(ec, work).getXid());
}
} catch (WorkException ex) {
setException(ex);
} finally {
try {
if (!isTimedOut()) {
if (probeProvider != null) {
probeProvider.workProcessingCompleted(raName);
probeProvider.workProcessed(raName);
}
// If exception is not null, the work has already been rejected.
if (listener != null) {
listener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, work, getException()));
}
}
// Also release the TX from the record of TX Optimizer
if (txImported) {
getTransactionManager().clearThreadTx();
}
} catch (Exception e) {
logger.log(Level.WARNING, e.getMessage());
} finally {
// reset the securityContext once the work has completed
com.sun.enterprise.security.SecurityContext.setUnauthenticatedContext();
}
}
setState(COMPLETED);
if (waitMode == WAIT_UNTIL_FINISH) {
unLock();
}
}
use of javax.resource.spi.work.WorkException in project wildfly by wildfly.
the class CommandDispatcherTransport method sendMessage.
@Override
protected Serializable sendMessage(Node physicalAddress, Request request, Serializable... parameters) throws WorkException {
Command<?, CommandDispatcherTransport> command = createCommand(request, parameters);
CommandDispatcher<CommandDispatcherTransport> dispatcher = this.dispatcher;
ExceptionSupplier<Optional<Serializable>, WorkException> task = new ExceptionSupplier<Optional<Serializable>, WorkException>() {
@Override
public Optional<Serializable> get() throws WorkException {
try {
CompletionStage<?> response = dispatcher.executeOnMember(command, physicalAddress);
return Optional.ofNullable((Serializable) response.toCompletableFuture().join());
} catch (CancellationException e) {
return Optional.empty();
} catch (CommandDispatcherException | CompletionException e) {
throw new WorkException(e);
}
}
};
Optional<Serializable> val = this.executor.execute(task).orElse(null);
return val != null ? val.orElse(null) : null;
}
Aggregations