Package javax.resource.spi.work

Examples of javax.resource.spi.work.WorkEvent


      if (waitType != WAIT_NONE)
         blockedTime = time;

      if (workListener != null)
      {
         WorkEvent event = new WorkEvent(workManager, WorkEvent.WORK_STARTED, work, null);
         workListener.workStarted(event);
      }
   }
View Full Code Here


      if (trace)
         log.trace("Completed work " + this);

      if (workListener != null)
      {
         WorkEvent event = new WorkEvent(workManager, WorkEvent.WORK_COMPLETED, work, exception);
         workListener.workCompleted(event);
      }
   }
View Full Code Here

     *                 be the work executor.
     */
    public synchronized void workAccepted(Object anObject) {
        isAccepted = true;
        acceptedTime = System.currentTimeMillis();
        workListener.workAccepted(new WorkEvent(anObject,
                WorkEvent.WORK_ACCEPTED, adaptee, null));
    }
View Full Code Here

                    + " 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,
                    adaptee,
                    workException));
            return true;
        }
View Full Code Here

            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, adaptee, 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) {
                adaptee.run();
            } else {
                try {
                    long transactionTimeout = executionContext.getTransactionTimeout();
                    //translate -1 value to 0 to indicate default transaction timeout.
                    xaWork.begin(executionContext.getXid(), transactionTimeout < 0 ? 0 : transactionTimeout);
                } catch (XAException e) {
                    throw new WorkCompletedException("Transaction import failed for xid " + executionContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e);
                } catch (InvalidTransactionException e) {
                    throw new WorkCompletedException("Transaction import failed for xid " + executionContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e);
                } catch (SystemException e) {
                    throw new WorkCompletedException("Transaction import failed for xid " + executionContext.getXid(), WorkCompletedException.TX_RECREATE_FAILED).initCause(e);
                } catch (ImportedTransactionActiveException e) {
                    throw new WorkCompletedException("Transaction already active for xid " + executionContext.getXid(), WorkCompletedException.TX_CONCURRENT_WORK_DISALLOWED);
                }
                try {
                    adaptee.run();
                } finally {
                    xaWork.end(executionContext.getXid());
                }

            }
            workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, adaptee, 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, adaptee,
                    workException));
        } finally {
            endLatch.countDown();
        }
    }
View Full Code Here

     *                 be the work executor.
     */
    public synchronized void workAccepted(Object anObject) {
        isAccepted = true;
        acceptedTime = System.currentTimeMillis();
        workListener.workAccepted(new WorkEvent(anObject,
                WorkEvent.WORK_ACCEPTED, adaptee, null));
    }
View Full Code Here

                    + " 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,
                    adaptee,
                    workException));
            return true;
        }
View Full Code Here

        }

        // 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, adaptee, 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 {
            List<WorkContext> workContexts = NO_INFLOW_CONTEXT;
            if (executionContext != null) {
                TransactionContext txWorkContext = new TransactionContext();
                try {
                    txWorkContext.setTransactionTimeout(executionContext.getTransactionTimeout());
                } catch (NotSupportedException e) {
                    //not set, continue to not set it.
                }
                txWorkContext.setXid(executionContext.getXid());
                workContexts = Collections.<WorkContext>singletonList(txWorkContext);
                log.info("Translated ExecutionContext to TransactionContext");
            } else if (adaptee instanceof WorkContextProvider) {
                workContexts = ((WorkContextProvider) adaptee).getWorkContexts();
            }
            List<WorkContextHandler> sortedHandlers = new ArrayList<WorkContextHandler>(workContexts.size());
            for (WorkContext workContext : workContexts) {
                boolean found = false;
                for (Iterator<WorkContextHandler> it = workContextHandlers.iterator(); it.hasNext();) {
                    WorkContextHandler workContextHandler = it.next();
                    log.info("sorting WorkContextHandler: " + workContextHandler + " for work context: " + workContext);
                    if (workContextHandler.supports(workContext.getClass())) {
                        it.remove();
                        log.info("adding sorted WorkContextHandler: " + workContextHandler);
                        sortedHandlers.add(workContextHandler);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    for (WorkContextHandler workContextHandler: sortedHandlers) {
                        if (workContextHandler.supports(workContext.getClass())) {
                            throw new WorkCompletedException("Duplicate WorkContext: " + workContext, WorkContextErrorCodes.DUPLICATE_CONTEXTS);
                        }
                    }
                    throw new WorkCompletedException("Unhandled WorkContext: " + workContext, WorkContextErrorCodes.UNSUPPORTED_CONTEXT_TYPE);
                }
            }
            for (Iterator<WorkContextHandler> it = workContextHandlers.iterator(); it.hasNext();) {
                WorkContextHandler workContextHandler = it.next();
                if (!workContextHandler.required()) {
                    log.info("Removing non-required WorkContextHandler with no context: " + workContextHandler);
                    it.remove();
                }
            }
            // TODO use a WorkContextLifecycleListener

            int i = 0;
            for (WorkContext workContext : workContexts) {
                WorkContextHandler contextHandler = sortedHandlers.get(i++);
                log.info("calling before on WorkContextHandler: " + contextHandler + " with workContext: " + workContext);
                contextHandler.before(workContext);
            }
            for (WorkContextHandler workContextHandler: workContextHandlers) {
                log.info("calling before on WorkContextHandler: " + workContextHandler + " with null workContext");
                workContextHandler.before(null);
            }
            try {
                adaptee.run();
            } finally {
                int j = 0;
                for (WorkContext workContext : workContexts) {
                    WorkContextHandler contextHandler = sortedHandlers.get(j++);
                    log.info("calling after on WorkContextHandler: " + contextHandler + " with workContext: " + workContext);
                    contextHandler.after(workContext);
                }
                for (WorkContextHandler workContextHandler: workContextHandlers) {
                    log.info("calling after on WorkContextHandler: " + workContextHandler + " with null workContext");
                    workContextHandler.after(null);
                }
            }

            workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, adaptee, 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, adaptee,
                    workException));
        } finally {
            endLatch.countDown();
        }
    }
View Full Code Here

     * be the work executor.
     */
    public synchronized void workAccepted(Object anObject) {
        isAccepted = true;
        acceptedTime = System.currentTimeMillis();
        workListener.workAccepted(new WorkEvent(anObject,
                WorkEvent.WORK_ACCEPTED, adaptee, null));
    }
View Full Code Here

        }
        if (isTimeout) {
            workException = new WorkRejectedException(this + " has timed out.",
                    WorkException.START_TIMED_OUT);
            workListener.workRejected(
                    new WorkEvent(
                            this,
                            WorkEvent.WORK_REJECTED,
                            adaptee,
                            workException));
            return true;
View Full Code Here

TOP

Related Classes of javax.resource.spi.work.WorkEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.