Examples of WorkEvent


Examples of javax.resource.spi.work.WorkEvent

    public long startWork(final Work work, final long timeout, final ExecutionContext executionContext,
            final WorkListener workListener) throws WorkRejectedException, WorkException {

        ResourceWork resourceWork = new ResourceWork(work, timeout, executionContext, workListener);
        if (workListener != null) {
            workListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null));
        }
        long starttime = System.currentTimeMillis();
        long duration = 0;
        synchronized (this.workList) {
            this.workList.add(resourceWork);
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

    public void scheduleWork(final Work work, final long timeout, final ExecutionContext executionContext,
            final WorkListener workListener) throws WorkRejectedException, WorkException {

        ResourceWork resourceWork = new ResourceWork(work, timeout, executionContext, workListener);
        if (workListener != null) {
            workListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null));
        }
        synchronized (this.workList) {
            this.workList.add(resourceWork);
            if (this.poolsz < this.maxpoolsz && this.workList.size() > this.freeThreads) {
                // We need one more thread.
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

        if (workListener != null) {
            long duration = System.currentTimeMillis() - creationTime;
            if (duration > timeout) {
                // This can occur only in case of scheduleWork
                logger.warn("REJECTED: duration= {0}", duration);
                workListener.workRejected(new WorkEvent(this, WorkEvent.WORK_REJECTED, work, null));
                return;
            }
            workListener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED, work, null));
        }

        // Setup ExecutionContext
        Xid xid = null;
        if (executionContext != null) {
            xid = executionContext.getXid();
            if (xid != null) {
                long txtimeout = executionContext.getTransactionTimeout();
                try {
                    if (txtimeout != WorkManager.UNKNOWN) {
                        this.transactionComponent.begin(xid, txtimeout);
                    } else {
                        this.transactionComponent.begin(xid);
                    }
                } catch (NotSupportedException e) {
                    throw new WorkException("Error starting a new transaction", e);
                } catch (SystemException e) {
                    throw new WorkException("Error starting a new transaction", e);
                }
            }
        }

        try {
            work.run();
            // Notify the listener that the work is completed.
            if (workListener != null) {
                workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, work, null));
            }
        } catch (Exception e) {
            if (workListener != null) {
                workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, work, null));
            }
            throw new WorkCompletedException(e);
        } finally {
            if (xid != null) {
                this.transactionComponent.clearThreadTx();
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

         wrapper = new WorkWrapper(this, work, execContext, workListener, null, completedLatch);

         if (workListener != null)
         {
            WorkEvent event = new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null);
            workListener.workAccepted(event);
         }

         BlockingExecutor executor = getExecutor(work);

         if (startTimeout == WorkManager.INDEFINITE)
         {
            executor.executeBlocking(wrapper);
         }
         else
         {
            executor.executeBlocking(wrapper, startTimeout, TimeUnit.MILLISECONDS);
         }

         completedLatch.await();
      }
      catch (ExecutionTimedOutException etoe)
      {
         exception = new WorkRejectedException(etoe);
         exception.setErrorCode(WorkRejectedException.START_TIMED_OUT)
      }
      catch (RejectedExecutionException ree)
      {
         exception = new WorkRejectedException(ree);
      }
      catch (WorkException we)
      {
         exception = we;
      }
      catch (InterruptedException ie)
      {
         Thread.currentThread().interrupt();
         exception = new WorkRejectedException("Interrupted while requesting permit");
      }
      finally
      {
         if (exception != null)
         {
            if (workListener != null)
            {
               WorkEvent event = new WorkEvent(this, WorkEvent.WORK_REJECTED, work, exception);
               workListener.workRejected(event);
            }

            throw exception;
         }
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

         wrapper = new WorkWrapper(this, work, execContext, workListener, startedLatch, null);

         if (workListener != null)
         {
            WorkEvent event = new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null);
            workListener.workAccepted(event);
         }

         BlockingExecutor executor = getExecutor(work);

         if (startTimeout == WorkManager.INDEFINITE)
         {
            executor.executeBlocking(wrapper);
         }
         else
         {
            executor.executeBlocking(wrapper, startTimeout, TimeUnit.MILLISECONDS);
         }

         startedLatch.await();

         return System.currentTimeMillis() - started;
      }
      catch (ExecutionTimedOutException etoe)
      {
         exception = new WorkRejectedException(etoe);
         exception.setErrorCode(WorkRejectedException.START_TIMED_OUT)
      }
      catch (RejectedExecutionException ree)
      {
         exception = new WorkRejectedException(ree);
      }
      catch (WorkException we)
      {
         exception = we;
      }
      catch (InterruptedException ie)
      {
         Thread.currentThread().interrupt();
         exception = new WorkRejectedException("Interrupted while requesting permit");
      }
      finally
      {
         if (exception != null)
         {
            if (workListener != null)
            {
               WorkEvent event = new WorkEvent(this, WorkEvent.WORK_REJECTED, work, exception);
               workListener.workRejected(event);
            }

            throw exception;
         }
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

         wrapper = new WorkWrapper(this, work, execContext, workListener, null, null);

         if (workListener != null)
         {
            WorkEvent event = new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null);
            workListener.workAccepted(event);
         }

         BlockingExecutor executor = getExecutor(work);

         if (startTimeout == WorkManager.INDEFINITE)
         {
            executor.executeBlocking(wrapper);
         }
         else
         {
            executor.executeBlocking(wrapper, startTimeout, TimeUnit.MILLISECONDS);
         }
      }
      catch (ExecutionTimedOutException etoe)
      {
         exception = new WorkRejectedException(etoe);
         exception.setErrorCode(WorkRejectedException.START_TIMED_OUT)
      }
      catch (RejectedExecutionException ree)
      {
         exception = new WorkRejectedException(ree);
      }
      catch (WorkException we)
      {
         exception = we;
      }
      catch (InterruptedException ie)
      {
         Thread.currentThread().interrupt();
         exception = new WorkRejectedException("Interrupted while requesting permit");
      }
      finally
      {
         if (exception != null)
         {
            if (workListener != null)
            {
               WorkEvent event = new WorkEvent(this, WorkEvent.WORK_REJECTED, work, exception);
               workListener.workRejected(event);
            }

            throw exception;
         }
View Full Code Here

Examples of javax.resource.spi.work.WorkEvent

      {
         work.release();

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

         if (startedLatch != null)
         {
View Full Code Here

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

     *                 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

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,
                    adaptee,
                    workException));
            return true;
        }
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.