Example usage for javax.resource.spi.work Work run

List of usage examples for javax.resource.spi.work Work run

Introduction

In this page you can find the example usage for javax.resource.spi.work Work run.

Prototype

public abstract void run();

Source Link

Document

When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

Usage

From source file:org.mule.execution.FlowProcessingPhase.java

@Override
public void runPhase(final FlowProcessingPhaseTemplate flowProcessingPhaseTemplate,
        final MessageProcessContext messageProcessContext, final PhaseResultNotifier phaseResultNotifier) {
    Work flowExecutionWork = new Work() {
        @Override//from  ww w . j a va2s.  c  o m
        public void release() {
        }

        @Override
        public void run() {
            try {
                try {
                    TransactionalErrorHandlingExecutionTemplate transactionTemplate = TransactionalErrorHandlingExecutionTemplate
                            .createMainExecutionTemplate(
                                    messageProcessContext.getFlowConstruct().getMuleContext(),
                                    (messageProcessContext.getTransactionConfig() == null
                                            ? new MuleTransactionConfig()
                                            : messageProcessContext.getTransactionConfig()),
                                    messageProcessContext.getFlowConstruct().getExceptionListener());
                    MuleEvent response = transactionTemplate.execute(new ExecutionCallback<MuleEvent>() {
                        @Override
                        public MuleEvent process() throws Exception {
                            Object message = flowProcessingPhaseTemplate.getOriginalMessage();
                            if (message == null) {
                                return null;
                            }
                            MuleEvent muleEvent = flowProcessingPhaseTemplate.getMuleEvent();
                            muleEvent = flowProcessingPhaseTemplate.beforeRouteEvent(muleEvent);
                            muleEvent = flowProcessingPhaseTemplate.routeEvent(muleEvent);
                            muleEvent = flowProcessingPhaseTemplate.afterRouteEvent(muleEvent);
                            return muleEvent;
                        }
                    });
                    if (flowProcessingPhaseTemplate instanceof RequestResponseFlowProcessingPhaseTemplate) {
                        ((RequestResponseFlowProcessingPhaseTemplate) flowProcessingPhaseTemplate)
                                .sendResponseToClient(response);
                    }
                    flowProcessingPhaseTemplate.afterSuccessfulProcessingFlow(response);
                } catch (MessagingException e) {
                    flowProcessingPhaseTemplate.afterFailureProcessingFlow(e);
                }
                phaseResultNotifier.phaseSuccessfully();
            } catch (Exception e) {
                MuleException me = new DefaultMuleException(e);
                try {
                    flowProcessingPhaseTemplate.afterFailureProcessingFlow(me);
                } catch (MuleException e1) {
                    logger.warn("Failure during exception processing in flow template: " + e.getMessage());
                    if (logger.isDebugEnabled()) {
                        logger.debug(e);
                    }
                }
                phaseResultNotifier.phaseFailure(e);
            }
        }
    };
    if (messageProcessContext.supportsAsynchronousProcessing()) {
        try {
            messageProcessContext.getFlowExecutionWorkManager().scheduleWork(flowExecutionWork);
        } catch (WorkException e) {
            phaseResultNotifier.phaseFailure(e);
        }
    } else {
        flowExecutionWork.run();
    }
}