javax.resource.spi.work.WorkCompletedException Java Examples

The following examples show how to use javax.resource.spi.work.WorkCompletedException. 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: SimpleTaskWorkManager.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void run() {
	if (this.acceptOnExecution) {
		this.workListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, this.work, null));
	}
	synchronized (this.monitor) {
		this.started = true;
		this.monitor.notify();
	}
	this.workListener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED, this.work, null));
	try {
		this.work.run();
	}
	catch (RuntimeException | Error ex) {
		this.workListener.workCompleted(
				new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, new WorkCompletedException(ex)));
		throw ex;
	}
	this.workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, null));
}
 
Example #2
Source File: SimpleTaskWorkManager.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
	if (this.acceptOnExecution) {
		this.workListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null));
	}
	synchronized (this.monitor) {
		this.started = true;
		this.monitor.notify();
	}
	this.workListener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED, this.work, null));
	try {
		this.work.run();
	}
	catch (RuntimeException ex) {
		this.workListener.workCompleted(
				new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, new WorkCompletedException(ex)));
		throw ex;
	}
	catch (Error err) {
		this.workListener.workCompleted(
				new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, new WorkCompletedException(err)));
		throw err;
	}
	this.workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, null));
}
 
Example #3
Source File: SimpleTaskWorkManager.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public void run() {
	if (this.acceptOnExecution) {
		this.workListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, this.work, null));
	}
	synchronized (this.monitor) {
		this.started = true;
		this.monitor.notify();
	}
	this.workListener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED, this.work, null));
	try {
		this.work.run();
	}
	catch (RuntimeException | Error ex) {
		this.workListener.workCompleted(
				new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, new WorkCompletedException(ex)));
		throw ex;
	}
	this.workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, null));
}
 
Example #4
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 #5
Source File: SimpleTaskWorkManager.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
	if (this.acceptOnExecution) {
		this.workListener.workAccepted(new WorkEvent(this, WorkEvent.WORK_ACCEPTED, work, null));
	}
	synchronized (this.monitor) {
		this.started = true;
		this.monitor.notify();
	}
	this.workListener.workStarted(new WorkEvent(this, WorkEvent.WORK_STARTED, this.work, null));
	try {
		this.work.run();
	}
	catch (RuntimeException ex) {
		this.workListener.workCompleted(
				new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, new WorkCompletedException(ex)));
		throw ex;
	}
	catch (Error err) {
		this.workListener.workCompleted(
				new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, new WorkCompletedException(err)));
		throw err;
	}
	this.workListener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, this.work, null));
}
 
Example #6
Source File: SecurityContextHandler.java    From tomee with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void after(final SecurityContext securityContext) throws WorkCompletedException {
    final SecurityService securityService = SystemInstance.get().getComponent(SecurityService.class);
    final Object loginObj = securityService.disassociate();
    if (loginObj != null) {
        try {
            securityService.logout(loginObj);
        } catch (final LoginException e) {
            //Ignore
        }
    }
}
 
Example #7
Source File: SecurityContextHandler.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void before(final SecurityContext securityContext) throws WorkCompletedException {
    if (securityContext != null) {
        callbackHandler = new ConnectorCallbackHandler(securityRealmName);

        final Subject clientSubject = new Subject();
        securityContext.setupSecurityContext(callbackHandler, clientSubject, null);
    }
}
 
Example #8
Source File: XATerminatorImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void startWork(Work work, Xid xid) throws WorkCompletedException
{
}
 
Example #9
Source File: AbstractDistributedWorkManagerTest.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Test that a work instance can report a failure
 * @throws Throwable throwable exception
 */
@Test
public void testFailure() throws Throwable
{
   Context context = new InitialContext();

   WorkConnectionFactory wcf = (WorkConnectionFactory) context.lookup("java:/eis/WorkConnectionFactory");

   assertNotNull(wcf);

   WorkConnection wc = wcf.getConnection();
   DistributedWorkManager dwm = null;
   try
   {
      assertNotNull(wc.getWorkManager());
      assertTrue(wc.getWorkManager() instanceof javax.resource.spi.work.DistributableWorkManager);

      dwm = (DistributedWorkManager)wc.getWorkManager();
      verifyConfig(dwm);
      dwm.getStatistics().clear();
      dwm.getDistributedStatistics().clear();

      wc.doWork(new MyDistributableFailureWork());

      fail("Expected WorkException");
   }
   catch (WorkException we)
   {
      assertTrue(we instanceof WorkCompletedException);

      WorkException wce = (WorkException)we;

      assertNotNull(wce.getCause());

      assertTrue(wce.getCause() instanceof RuntimeException);
      
      RuntimeException re = (RuntimeException)wce.getCause();

      assertEquals("FAILURE", re.getMessage());
   }
   finally
   {
      assertNotNull(dwm);
      assertNotNull(dwm.getDistributedStatistics());
      assertEquals(1, dwm.getDistributedStatistics().getWorkFailed());

      wc.close();
   }
}
 
Example #10
Source File: XATerminatorImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void registerWork(Work work, Xid xid, long timeout) throws WorkCompletedException
{
}
 
Example #11
Source File: XATerminatorImpl.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void registerWork(Work work, Xid xid, long timeout) throws WorkCompletedException
{
}
 
Example #12
Source File: XATerminatorImpl.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void startWork(Work work, Xid xid) throws WorkCompletedException
{
}
 
Example #13
Source File: WorkWrapper.java    From ironjacamar with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Run
 */
public void run()
{
   ClassLoader oldCL = SecurityActions.getThreadContextClassLoader();
   SecurityActions.setThreadContextClassLoader(work.getClass().getClassLoader());

   org.ironjacamar.core.spi.security.SecurityContext oldSC = securityIntegration.getSecurityContext();

   try
   {
      start();
      workManager.addWorkWrapper(this);

      if (startedLatch != null)
         startedLatch.countDown();

      work.run();

      end();
   }
   catch (Throwable t)
   {
      exception = new WorkCompletedException(t.getMessage(), t);

      cancel();
   } 
   finally
   {
      workManager.removeWorkWrapper(this);
      work.release();

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

      securityIntegration.setSecurityContext(oldSC);
      SecurityActions.setThreadContextClassLoader(oldCL);

      if (startedLatch != null)
      {
         while (startedLatch.getCount() != 0)
            startedLatch.countDown();
      }

      if (completedLatch != null)
         completedLatch.countDown();

      if (trace)
         log.tracef("Executed work: %s", this);
   }
}
 
Example #14
Source File: WorkWrapper.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Runs the work.
 *
 * @throws WorkCompletedException if there is an error completing work execution
 */
protected void runWork() throws WorkCompletedException
{
   work.run();
}
 
Example #15
Source File: XATerminator.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Invoked for transaction inflow of work
 * 
 * @param work The work starting
 * @param xid The xid of the work
 * @param timeout The transaction timeout
 * @throws WorkCompletedException with error code WorkException.TX_CONCURRENT_WORK_DISALLOWED
 *         when work is already present for the xid or whose completion is in progress, only
 *         the global part of the xid must be used for this check.
 */
public void registerWork(Work work, Xid xid, long timeout) throws WorkCompletedException;
 
Example #16
Source File: XATerminator.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Invoked for transaction inflow of work
 * 
 * @param work The work starting
 * @param xid The xid of the work
 * @throws WorkCompletedException With error code WorkException.TX_RECREATE_FAILED if it is unable 
 *         to recreate the transaction context
 */
public void startWork(Work work, Xid xid) throws WorkCompletedException;
 
Example #17
Source File: XATerminatorImpl.java    From ironjacamar with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Invoked for transaction inflow of work
 * 
 * @param work The work starting
 * @param xid The xid of the work
 * @param timeout The transaction timeout
 * @throws WorkCompletedException with error code WorkException.TX_CONCURRENT_WORK_DISALLOWED
 *         when work is already present for the xid or whose completion is in progress, only
 *         the global part of the xid must be used for this check.
 */
public void registerWork(Work work, Xid xid, long timeout) throws WorkCompletedException
{
   delegator.registerWork(work, xid, timeout);
}
 
Example #18
Source File: XATerminatorImpl.java    From ironjacamar with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Invoked for transaction inflow of work
 * 
 * @param work The work starting
 * @param xid The xid of the work
 * @throws WorkCompletedException With error code WorkException.TX_RECREATE_FAILED if it is unable 
 *         to recreate the transaction context
 */
public void startWork(Work work, Xid xid) throws WorkCompletedException
{
   delegator.startWork(work, xid);
}
 
Example #19
Source File: XATerminator.java    From ironjacamar with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Invoked for transaction inflow of work
 * 
 * @param work The work starting
 * @param xid The xid of the work
 * @param timeout The transaction timeout
 * @throws WorkCompletedException with error code WorkException.TX_CONCURRENT_WORK_DISALLOWED
 *         when work is already present for the xid or whose completion is in progress, only
 *         the global part of the xid must be used for this check.
 */
public void registerWork(Work work, Xid xid, long timeout) throws WorkCompletedException;
 
Example #20
Source File: XATerminator.java    From ironjacamar with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Invoked for transaction inflow of work
 * 
 * @param work The work starting
 * @param xid The xid of the work
 * @throws WorkCompletedException With error code WorkException.TX_RECREATE_FAILED if it is unable 
 *         to recreate the transaction context
 */
public void startWork(Work work, Xid xid) throws WorkCompletedException;
 
Example #21
Source File: XATerminatorImpl.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Invoked for transaction inflow of work
 * 
 * @param work The work starting
 * @param xid The xid of the work
 * @throws WorkCompletedException With error code WorkException.TX_RECREATE_FAILED if it is unable 
 *         to recreate the transaction context
 */
public void startWork(Work work, Xid xid) throws WorkCompletedException
{
   delegator.startWork(work, xid);
}
 
Example #22
Source File: XATerminatorImpl.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Invoked for transaction inflow of work
 * 
 * @param work The work starting
 * @param xid The xid of the work
 * @param timeout The transaction timeout
 * @throws WorkCompletedException with error code WorkException.TX_CONCURRENT_WORK_DISALLOWED
 *         when work is already present for the xid or whose completion is in progress, only
 *         the global part of the xid must be used for this check.
 */
public void registerWork(Work work, Xid xid, long timeout) throws WorkCompletedException
{
   delegator.registerWork(work, xid, timeout);
}