Examples of WorkEvent


Examples of javax.resource.spi.work.WorkEvent

         }
      }

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

      if (trace)
      {
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

    try {
      _work.run();

      if (_listener != null)
        _listener.workCompleted(new WorkEvent(_manager,
                                              WorkEvent.WORK_COMPLETED,
                                              _work, null, 0));
    } finally {
      _manager.completeWork(_work);
    }
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

      }

      if (listener == null) {
      }
      else if (isStart)
        listener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED,
                                            work, null, 0));
      else {
        listener.workRejected(new WorkEvent(this, WorkEvent.WORK_REJECTED,
                                            work, exn, 0));
      }
     
      if (exn != null)
        throw exn;

      if (listener != null)
        listener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED,
                                           work, null, 0));
     
      work.run();

      if (listener != null)
        listener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED,
                                             work, null, 0));
    } finally {
      synchronized (this) {
        _activeTasks.remove(work);
      }
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

          _activeTasks.add(work);
      }

      if (exn != null) {
        if (listener != null)
          listener.workRejected(new WorkEvent(this, WorkEvent.WORK_REJECTED,
                                              work, exn, 0));
        throw exn;
      }
      else if (listener != null)
        listener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED,
                                            work, null, 0));

      ClassLoader loader = Thread.currentThread().getContextClassLoader();
      WorkThread workThread = new WorkThread(this, work, loader, listener);

      if (listener != null)
        listener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED,
                                           work, null, 0));

      if (waitForStart)
        isStart = ThreadPool.getThreadPool().start(workThread, startTimeout);
      else
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

        if (workListener == null) workListener = new LoggingWorkListener(workType);

        // reject work with an XID
        if (executionContext != null && executionContext.getXid() != null) {
            WorkRejectedException workRejectedException = new WorkRejectedException("SimpleWorkManager can not import an XID", WorkException.TX_RECREATE_FAILED);
            workListener.workRejected(new WorkEvent(this, WORK_REJECTED, work, workRejectedException));
            throw workRejectedException;
        }

        // accecpt all other work
        workListener.workAccepted(new WorkEvent(this, WORK_ACCEPTED, work, null));

        // execute work
        Worker worker = new Worker(work, workListener, startTimeout);
        executor.execute(worker);
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

            try {
                // check if we have started within the specified limit
                startDelay = System.currentTimeMillis() - created;
                if (startDelay > startTimeout) {
                    workException = new WorkRejectedException("Work not started within specified timeout " + startTimeout + "ms", START_TIMED_OUT);
                    workListener.workRejected(new WorkEvent(this, WORK_REJECTED, work, workException, startTimeout));
                    return;
                }

                // notify listener that work has been started
                workListener.workStarted(new WorkEvent(SimpleWorkManager.this, WORK_STARTED, work, null));

                // officially started
                started.countDown();

                // execute the real work
                workException = null;
                try {
                    work.run();
                } catch (Throwable e) {
                    workException = new WorkCompletedException(e);
                } finally {
                    // notify listener that work completed (with an optional exception)
                    workListener.workCompleted(new WorkEvent(SimpleWorkManager.this, WORK_COMPLETED, work, workException));
                }
            } finally {
                // assure that threads waiting for start are released
                started.countDown();
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

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

Examples of javax.resource.spi.work.WorkEvent

                         + " 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;
    }
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

            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
            {
                // try {
                // long transactionTimeout =
                // executionContext.getDefaultTransactionTimeout();
                // //translate -1 value to 0 to indicate default transaction
                // timeout.
                // transactionContextManager.begin(executionContext.getXid(),
                // transactionTimeout == -1 ? 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
                {
                    worker.run();
                }
                finally
                {
                    // transactionContextManager.end(executionContext.getXid());
                }

            }
            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();
            endLatch.countDown();
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

        }
    }

    private WorkEvent getTestWorkEvent()
    {
        return new WorkEvent(this, // source
            WorkEvent.WORK_REJECTED, getTestWork(), new WorkException(new Throwable("testThrowable")));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.