List of usage examples for javax.resource.spi.work WorkCompletedException WorkCompletedException
public WorkCompletedException(String message, String errorCode)
From source file:org.mule.work.MuleWorkManager.java
/** * Execute the specified Work.// w ww . j a v a 2 s.c om * * @param work Work to be executed. * @exception WorkException Indicates that the Work execution has been * unsuccessful. */ private void executeWork(WorkerContext work, WorkExecutor workExecutor) throws WorkException { if (!isStarted()) { throw new IllegalStateException("This MuleWorkManager '" + name + "' is stopped"); } try { work.workAccepted(this); workExecutor.doExecute(work, workExecutorService); WorkException exception = work.getWorkException(); if (null != exception) { throw exception; } } catch (InterruptedException e) { WorkCompletedException wcj = new WorkCompletedException( "The execution has been interrupted for WorkManager: " + name, e); wcj.setErrorCode(WorkException.INTERNAL); throw wcj; } }
From source file:org.mule.work.WorkerContext.java
public void run() { if (isTimedOut()) { // In case of a time out, one releases the start and end latches // to prevent a dead-lock. startLatch.countDown();//from w ww . j av a 2s. com endLatch.countDown(); return; } // Implementation note: the work listener is notified prior to release // the start lock. This behavior is intentional and seems to be the // more conservative. workListener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED, worker, null)); startLatch.countDown(); // Implementation note: we assume this is being called without an // interesting TransactionContext, // and ignore/replace whatever is associated with the current thread. try { if (executionContext == null || executionContext.getXid() == null) { // TODO currently unused, see below // ExecutionContext context = new ExecutionContext(); final ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); try { // execute with the application-specific classloader in the context Thread.currentThread().setContextClassLoader(executionClassLoader); worker.run(); } finally { Thread.currentThread().setContextClassLoader(originalCl); // ExecutionContext returningContext = new // ExecutionContext(); // if (context != returningContext) { // throw new WorkCompletedException("Wrong // TransactionContext on return from work done"); // } } // TODO should we commit the txContext to flush any leftover // state??? } else { worker.run(); } workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, worker, null)); } catch (Throwable e) { workException = (WorkException) (e instanceof WorkCompletedException ? e : new WorkCompletedException("Unknown error", WorkCompletedException.UNDEFINED).initCause(e)); workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_REJECTED, worker, workException)); } finally { RequestContext.clear(); TransactionCoordination.getInstance().clear(); endLatch.countDown(); } }