Search in sources :

Example 11 with WorkException

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();
    }
}
Also used : WorkException(javax.resource.spi.work.WorkException) JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) WorkEvent(javax.resource.spi.work.WorkEvent) ResourceException(javax.resource.ResourceException) WorkException(javax.resource.spi.work.WorkException) WorkRejectedException(javax.resource.spi.work.WorkRejectedException) WorkCompletedException(javax.resource.spi.work.WorkCompletedException)

Example 12 with WorkException

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;
}
Also used : Serializable(java.io.Serializable) ExceptionSupplier(org.wildfly.common.function.ExceptionSupplier) Optional(java.util.Optional) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) WorkException(javax.resource.spi.work.WorkException) CancellationException(java.util.concurrent.CancellationException) CompletionException(java.util.concurrent.CompletionException)

Aggregations

WorkException (javax.resource.spi.work.WorkException)12 WorkEvent (javax.resource.spi.work.WorkEvent)4 WorkRejectedException (javax.resource.spi.work.WorkRejectedException)4 CancellationException (java.util.concurrent.CancellationException)2 CompletionException (java.util.concurrent.CompletionException)2 Work (javax.resource.spi.work.Work)2 WorkCompletedException (javax.resource.spi.work.WorkCompletedException)2 TaskRejectedException (org.springframework.core.task.TaskRejectedException)2 TaskTimeoutException (org.springframework.core.task.TaskTimeoutException)2 CommandDispatcherException (org.wildfly.clustering.dispatcher.CommandDispatcherException)2 JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)1 GlobalTID (com.sun.jts.CosTransactions.GlobalTID)1 Serializable (java.io.Serializable)1 ClosedWatchServiceException (java.nio.file.ClosedWatchServiceException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Callable (java.util.concurrent.Callable)1 CompletionStage (java.util.concurrent.CompletionStage)1 ExecutionException (java.util.concurrent.ExecutionException)1