javax.resource.spi.work.ExecutionContext Java Examples

The following examples show how to use javax.resource.spi.work.ExecutionContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorkWrapper.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Cancel
 */
protected void cancel()
{
   if (trace)
      log.tracef("Cancel work: %s", this);  

   ExecutionContext ctx = getWorkContext(TransactionContext.class);
   if (ctx == null)
   {
      ctx = getExecutionContext();
   }

   if (ctx != null)
   {
      Xid xid = ctx.getXid();
      if (xid != null)
      {
         workManager.getXATerminator().cancelWork(work, xid);
      }
   }

   if (trace)
      log.tracef("Canceled work: %s", this);  
}
 
Example #2
Source File: WorkWrapper.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * End
 */
protected void end()
{
   if (trace)
      log.tracef("Ending work: %s", this);  

   ExecutionContext ctx = getWorkContext(TransactionContext.class);
   if (ctx == null)
   {
      ctx = getExecutionContext();
   }

   if (ctx != null)
   {
      Xid xid = ctx.getXid();
      if (xid != null)
      {
         workManager.getXATerminator().endWork(work, xid);
      }
   }

   if (trace)
      log.tracef("Ended work: %s", this);  
}
 
Example #3
Source File: WorkWrapper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Cancel
 */
protected void cancel()
{
   log.tracef("Cancel work: %s", this);  

   ExecutionContext ctx = getWorkContext(TransactionContext.class);
   if (ctx == null)
   {
      ctx = getExecutionContext();
   }

   if (ctx != null)
   {
      Xid xid = ctx.getXid();
      if (xid != null)
      {
         workManager.getXATerminator().cancelWork(work, xid);
      }
   }

   log.tracef("Canceled work: %s", this);  
}
 
Example #4
Source File: WorkWrapper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * End
 */
protected void end()
{
   log.tracef("Ending work: %s", this);  

   ExecutionContext ctx = getWorkContext(TransactionContext.class);
   if (ctx == null)
   {
      ctx = getExecutionContext();
   }

   if (ctx != null)
   {
      Xid xid = ctx.getXid();
      if (xid != null)
      {
         workManager.getXATerminator().endWork(work, xid);
      }
   }

   log.tracef("Ended work: %s", this);  
}
 
Example #5
Source File: WorkManagerImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check and verify work before submitting.
 * @param work the work instance
 * @param executionContext any execution context that is passed by apadater
 * @throws WorkException if any exception occurs
 */
private void checkAndVerifyWork(Work work, ExecutionContext executionContext) throws WorkException
{
   if (specCompliant)
   {
      verifyWork(work);
   }

   if (work instanceof WorkContextProvider)
   {
      //Implements WorkContextProvider and not-null ExecutionContext
      if (executionContext != null)
      {
         throw new WorkRejectedException(bundle.workExecutionContextMustNullImplementsWorkContextProvider());
      }
   }
}
 
Example #6
Source File: WorkInterfaceTestCase.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Test for bullet 4 Section 3.3.6
 * When the application server is unable to recreate an execution context if it is  
 *                      specified for the submitted Work instance, it must throw a
 *                      WorkCompletedException set to an appropriate error code.
 * @throws Throwable throwable exception 
 */
@Test(expected = WorkCompletedException.class)
public void testThrowWorkCompletedException() throws Throwable
{
   ExecutionContext ec = new ExecutionContext();
   ShortRunningWork work = new ShortRunningWork();
   ec.setXid(new XidImpl());
   ec.setTransactionTimeout(Long.MAX_VALUE);

   WorkConnection wc = wcf.getConnection();
   try
   {
      wc.doWork(work, WorkManager.INDEFINITE, ec, null);
   }
   finally
   {
      wc.close();
   }
}
 
Example #7
Source File: SimpleTaskWorkManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long startWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener)
		throws WorkException {

	Assert.state(this.asyncTaskExecutor != null, "No 'asyncTaskExecutor' set");
	return executeWork(this.asyncTaskExecutor, work, startTimeout, true, executionContext, workListener);
}
 
Example #8
Source File: ActiveMQRATestBase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public long startWork(Work work,
                      long l,
                      ExecutionContext executionContext,
                      WorkListener workListener) throws WorkException {
   return 0;
}
 
Example #9
Source File: SimpleWorkManager.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public long startWork(Work work, long startTimeout, ExecutionContext execContext, WorkListener workListener)
		throws WorkException {
	SimpleWorkListener wrappedListener = new SimpleWorkListener(workListener);
	wrappedListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null));
	SimpleWork task = new SimpleWork();
	task.setSource(this);
	task.setWork(work);
	task.setWorkListener(wrappedListener);
	this.executor.submit(task);
	return wrappedListener.waitForStart();
}
 
Example #10
Source File: SimpleTaskWorkManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void scheduleWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener)
		throws WorkException {

	Assert.state(this.asyncTaskExecutor != null, "No 'asyncTaskExecutor' set");
	executeWork(this.asyncTaskExecutor, work, startTimeout, false, executionContext, workListener);
}
 
Example #11
Source File: SimpleTaskWorkManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public long startWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener)
		throws WorkException {

	Assert.state(this.asyncTaskExecutor != null, "No 'asyncTaskExecutor' set");
	return executeWork(this.asyncTaskExecutor, work, startTimeout, true, executionContext, workListener);
}
 
Example #12
Source File: SimpleTaskWorkManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void doWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener)
		throws WorkException {

	Assert.state(this.syncTaskExecutor != null, "No 'syncTaskExecutor' set");
	executeWork(this.syncTaskExecutor, work, startTimeout, false, executionContext, workListener);
}
 
Example #13
Source File: SimpleWorkManager.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void scheduleWork(Work work, long startTimeout, ExecutionContext execContext, WorkListener workListener)
		throws WorkException {
	// SimpleWorkListener wrappedListener = new SimpleWorkListener(workListener);
	// wrappedListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null));
	// SimpleWork task = new SimpleWork();
	// task.setSource(this);
	// task.setWork(work);
	// task.setWorkListener(wrappedListener);
	// // ScheduledFuture<?> future =
	// this.scheduled.scheduleAtFixedRate(task, 0, 1000, TimeUnit.MILLISECONDS);
	throw new WorkException("not supported yet!");
}
 
Example #14
Source File: WorkWrapper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new WorkWrapper
 *
 * @param workManager the work manager
 * @param si The security integration
 * @param work the work
 * @param executionContext the execution context
 * @param workListener the WorkListener
 * @param startedLatch The latch for when work has started
 * @param completedLatch The latch for when work has completed
 * @param startTime The start time
 * @throws IllegalArgumentException for null work, execution context or a negative start timeout
 */
public WorkWrapper(WorkManagerImpl workManager, 
                   SecurityIntegration si,
                   Work work, 
                   ExecutionContext executionContext, 
                   WorkListener workListener,
                   CountDownLatch startedLatch,
                   CountDownLatch completedLatch,
                   long startTime)
{
   super();

   if (workManager == null)
      throw new IllegalArgumentException("Null work manager");
   if (si == null)
      throw new IllegalArgumentException("Null security integration");
   if (work == null)
      throw new IllegalArgumentException("Null work");
   if (executionContext == null)
      throw new IllegalArgumentException("Null execution context");

   this.workManager = workManager;
   this.securityIntegration = si;
   this.work = work;
   this.executionContext = executionContext;
   this.workListener = workListener;
   this.startedLatch = startedLatch;
   this.completedLatch = completedLatch;
   this.startTime = startTime;
   this.workContexts = null;
}
 
Example #15
Source File: WorkManagerImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Do first checks for work starting methods
 * @param work to check
 * @param startTimeout to check
 * @param execContext to check
 * @throws WorkException in case of check don't pass
 */
public void doFirstChecks(Work work, long startTimeout, ExecutionContext execContext) throws WorkException
{
   if (isShutdown())
      throw new WorkRejectedException(bundle.workmanagerShutdown());

   if (work == null)
      throw new WorkRejectedException(bundle.workIsNull());

   if (startTimeout < 0)
      throw new WorkRejectedException(bundle.startTimeoutIsNegative(startTimeout));

   checkAndVerifyWork(work, execContext);
}
 
Example #16
Source File: SimpleTaskWorkManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void scheduleWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener)
		throws WorkException {

	Assert.state(this.asyncTaskExecutor != null, "No 'asyncTaskExecutor' set");
	executeWork(this.asyncTaskExecutor, work, startTimeout, false, executionContext, workListener);
}
 
Example #17
Source File: SimpleTaskWorkManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void doWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener)
		throws WorkException {

	Assert.state(this.syncTaskExecutor != null, "No 'syncTaskExecutor' set");
	executeWork(this.syncTaskExecutor, work, startTimeout, false, executionContext, workListener);
}
 
Example #18
Source File: SimpleTaskWorkManager.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void doWork(Work work, long startTimeout, @Nullable ExecutionContext executionContext, @Nullable WorkListener workListener)
		throws WorkException {

	Assert.state(this.syncTaskExecutor != null, "No 'syncTaskExecutor' set");
	executeWork(this.syncTaskExecutor, work, startTimeout, false, executionContext, workListener);
}
 
Example #19
Source File: SimpleTaskWorkManager.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public long startWork(Work work, long startTimeout, @Nullable ExecutionContext executionContext, @Nullable WorkListener workListener)
		throws WorkException {

	Assert.state(this.asyncTaskExecutor != null, "No 'asyncTaskExecutor' set");
	return executeWork(this.asyncTaskExecutor, work, startTimeout, true, executionContext, workListener);
}
 
Example #20
Source File: SimpleTaskWorkManager.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void scheduleWork(Work work, long startTimeout, @Nullable ExecutionContext executionContext, @Nullable WorkListener workListener)
		throws WorkException {

	Assert.state(this.asyncTaskExecutor != null, "No 'asyncTaskExecutor' set");
	executeWork(this.asyncTaskExecutor, work, startTimeout, false, executionContext, workListener);
}
 
Example #21
Source File: SimpleTaskWorkManager.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void doWork(Work work, long startTimeout, @Nullable ExecutionContext executionContext, @Nullable WorkListener workListener)
		throws WorkException {

	Assert.state(this.syncTaskExecutor != null, "No 'syncTaskExecutor' set");
	executeWork(this.syncTaskExecutor, work, startTimeout, false, executionContext, workListener);
}
 
Example #22
Source File: SimpleTaskWorkManager.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public long startWork(Work work, long startTimeout, @Nullable ExecutionContext executionContext, @Nullable WorkListener workListener)
		throws WorkException {

	Assert.state(this.asyncTaskExecutor != null, "No 'asyncTaskExecutor' set");
	return executeWork(this.asyncTaskExecutor, work, startTimeout, true, executionContext, workListener);
}
 
Example #23
Source File: SimpleTaskWorkManager.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void scheduleWork(Work work, long startTimeout, @Nullable ExecutionContext executionContext, @Nullable WorkListener workListener)
		throws WorkException {

	Assert.state(this.asyncTaskExecutor != null, "No 'asyncTaskExecutor' set");
	executeWork(this.asyncTaskExecutor, work, startTimeout, false, executionContext, workListener);
}
 
Example #24
Source File: WorkWrapper.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create a new WorkWrapper
 *
 * @param workManager the work manager
 * @param si The security integration
 * @param work the work
 * @param executionContext the execution context
 * @param workListener the WorkListener
 * @param startedLatch The latch for when work has started
 * @param completedLatch The latch for when work has completed
 * @param startTime The start time
 * @throws IllegalArgumentException for null work, execution context or a negative start timeout
 */
public WorkWrapper(WorkManagerImpl workManager, 
                   SecurityIntegration si,
                   Work work,
                   ExecutionContext executionContext,
                   WorkListener workListener,
                   CountDownLatch startedLatch,
                   CountDownLatch completedLatch,
                   long startTime)
{
   super();

   if (workManager == null)
      throw new IllegalArgumentException("Null work manager");
   if (si == null)
      throw new IllegalArgumentException("Null security integration");
   if (work == null)
      throw new IllegalArgumentException("Null work");
   if (executionContext == null)
      throw new IllegalArgumentException("Null execution context");

   this.workManager = workManager;
   this.securityIntegration = si;
   this.work = work;
   this.executionContext = executionContext;
   this.workListener = workListener;
   this.startedLatch = startedLatch;
   this.completedLatch = completedLatch;
   this.startTime = startTime;
   this.workContexts = null;
}
 
Example #25
Source File: WorkManagerImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check and verify work before submitting.
 * @param work the work instance
 * @param executionContext any execution context that is passed by apadater
 * @throws WorkException if any exception occurs
 */
private void checkAndVerifyWork(Work work, ExecutionContext executionContext) throws WorkException
{
   if (specCompliant)
   {
      verifyWork(work);
   }

   if (work instanceof WorkContextProvider && executionContext != null)
   {
      //Implements WorkContextProvider and not-null ExecutionContext
      throw new WorkRejectedException(bundle.workExecutionContextMustNullImplementsWorkContextProvider());
   }
}
 
Example #26
Source File: WorkManagerImpl.java    From ironjacamar with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Do first checks for work starting methods
 * @param work to check
 * @param startTimeout to check
 * @param execContext to check
 * @throws WorkException in case of check don't pass
 */
public void doFirstChecks(Work work, long startTimeout, ExecutionContext execContext) throws WorkException
{
   if (isShutdown())
      throw new WorkRejectedException(bundle.workmanagerShutdown());

   if (work == null)
      throw new WorkRejectedException(bundle.workIsNull());

   if (startTimeout < 0)
      throw new WorkRejectedException(bundle.startTimeoutIsNegative(startTimeout));

   checkAndVerifyWork(work, execContext);
}
 
Example #27
Source File: WorkConnectionImpl.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public long startWork(Work work, long startTimeout, ExecutionContext execContext, WorkListener workListener)
   throws WorkException
{
   return mc.startWork(work, startTimeout, execContext, workListener);
}
 
Example #28
Source File: WorkConnectionImpl.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void scheduleWork(Work work, long startTimeout, ExecutionContext execContext, WorkListener workListener)
   throws WorkException
{
   mc.scheduleWork(work, startTimeout, execContext, workListener);
}
 
Example #29
Source File: WorkConnectionImpl.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void doWork(Work work, long startTimeout, ExecutionContext execContext, WorkListener workListener)
   throws WorkException
{
   mc.doWork(work, startTimeout, execContext, workListener);
}
 
Example #30
Source File: SimpleWorkManager.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void doWork(final Work work, final long startTimeout, final ExecutionContext executionContext, final WorkListener workListener) throws WorkException {
    if (work == null) {
        throw new NullPointerException("work is null");
    }
    executeWork(WorkType.DO, work, startTimeout, executionContext, workListener);
}