List of usage examples for javax.resource.spi.work WorkEvent WorkEvent
public WorkEvent(Object source, int type, Work work, WorkException exc)
From source file:org.mule.work.WorkerContext.java
/** * Call-back method used by a Work executor in order to notify this instance that * the wrapped Work instance has been accepted. * /*from w w w .j a v a2 s .c om*/ * @param anObject Object on which the event initially occurred. It should be the * work executor. */ public synchronized void workAccepted(Object anObject) { acceptedTime = System.currentTimeMillis(); workListener.workAccepted(new WorkEvent(anObject, WorkEvent.WORK_ACCEPTED, worker, null)); }
From source file:org.mule.work.WorkerContext.java
/** * Used by a Work executor in order to know if this work, which should be * accepted but not started has timed out. This method MUST be called prior to * retry the execution of a Work./*from w ww . j a v a2 s. com*/ * * @return true if the Work has timed out and false otherwise. */ public synchronized boolean isTimedOut() { // A value of 0 means that the work never times out. // ??? really? if (0 == startTimeOut || startTimeOut == MuleWorkManager.INDEFINITE) { return false; } boolean isTimeout = acceptedTime + startTimeOut > 0 && System.currentTimeMillis() > acceptedTime + startTimeOut; if (logger.isDebugEnabled()) { logger.debug( this + " accepted at " + acceptedTime + (isTimeout ? " has timed out." : " has not timed out. ") + retryCount + " retries have been performed."); } if (isTimeout) { workException = new WorkRejectedException(this + " has timed out.", WorkException.START_TIMED_OUT); workListener.workRejected(new WorkEvent(this, WorkEvent.WORK_REJECTED, worker, workException)); return true; } retryCount++; return isTimeout; }
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();/*www . jav a 2 s . co m*/ 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(); } }