Search in sources :

Example 1 with Work

use of javax.resource.spi.work.Work in project teiid by teiid.

the class TestThreadReuseExecutor method testFailingWork.

@Test
public void testFailingWork() throws Exception {
    // $NON-NLS-1$
    pool = new ThreadReuseExecutor("test", 5);
    final Semaphore signal = new Semaphore(1);
    pool.execute(new Work() {

        @Override
        public void run() {
            signal.release();
            throw new RuntimeException();
        }

        @Override
        public void release() {
        }
    });
    assertTrue(signal.tryAcquire(2, TimeUnit.SECONDS));
}
Also used : ThreadReuseExecutor(org.teiid.dqp.internal.process.ThreadReuseExecutor) Work(javax.resource.spi.work.Work) FutureWork(org.teiid.dqp.internal.process.FutureWork) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test)

Example 2 with Work

use of javax.resource.spi.work.Work in project narayana by jbosstm.

the class TxWorkManager method addWork.

/*
	 * Although we allow multiple units of work per transaction, currently
	 * JCA only allows one. Might not be worth the hassle of maintaing this
	 * support.
	 */
/**
 * Add the specified work unit to the specified transaction.
 *
 * @param work The work to associate with the transaction.
 * @param tx The transaction to have associated with the work.
 *
 * @throws WorkCompletedException thrown if there is already work
 * associated with the transaction.
 */
public static void addWork(Work work, Transaction tx) throws WorkCompletedException {
    Stack<Work> workers;
    synchronized (_transactions) {
        workers = _transactions.get(tx);
        if (workers == null) {
            workers = new Stack<Work>();
            _transactions.put(tx, workers);
        } else
            throw new WorkCompletedException(jtaLogger.i18NLogger.get_transaction_arjunacore_jca_busy(), WorkException.TX_CONCURRENT_WORK_DISALLOWED);
    }
    synchronized (workers) {
        workers.push(work);
    }
}
Also used : Work(javax.resource.spi.work.Work) WorkCompletedException(javax.resource.spi.work.WorkCompletedException)

Example 3 with Work

use of javax.resource.spi.work.Work in project javaee7-samples by javaee-samples.

the class WatchingThread method invoke.

private void invoke(final MessageEndpoint endpoint, final Method beanClassMethod, final Path path) throws WorkException {
    out.println("Watch thread scheduling endpoint call via workmanager for method: " + beanClassMethod.getName() + " and file" + path.getFileName());
    resourceAdapter.getBootstrapContext().getWorkManager().scheduleWork(new Work() {

        @Override
        public void run() {
            try {
                try {
                    endpoint.beforeDelivery(beanClassMethod);
                    beanClassMethod.invoke(endpoint, path.toFile());
                } finally {
                    endpoint.afterDelivery();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void release() {
        }
    });
}
Also used : Work(javax.resource.spi.work.Work) ClosedWatchServiceException(java.nio.file.ClosedWatchServiceException) WorkException(javax.resource.spi.work.WorkException)

Example 4 with Work

use of javax.resource.spi.work.Work in project wildfly by wildfly.

the class TelnetResourceAdapter method endpointActivation.

@Override
public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException {
    final TelnetActivationSpec telnetActivationSpec = (TelnetActivationSpec) activationSpec;
    final MessageEndpoint messageEndpoint = messageEndpointFactory.createEndpoint(null);
    // This messageEndpoint instance is also castable to the ejbClass of the MDB
    final TelnetListener telnetListener = (TelnetListener) messageEndpoint;
    try {
        final TelnetServer telnetServer = new TelnetServer(telnetActivationSpec, telnetListener, port);
        workManager.scheduleWork(new Work() {

            @Override
            public void release() {
            }

            @Override
            public void run() {
                try {
                    telnetServer.activate();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }, 0, null, null);
        activated.put(port, telnetServer);
    } catch (IOException e) {
        throw new ResourceException(e);
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) TelnetListener(org.jboss.as.test.integration.ejb.mdb.dynamic.api.TelnetListener) Work(javax.resource.spi.work.Work) ResourceException(javax.resource.ResourceException) IOException(java.io.IOException) TelnetServer(org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TelnetServer)

Example 5 with Work

use of javax.resource.spi.work.Work in project cxf by apache.

the class ResourceAdapterImpl method endpointActivation.

public void endpointActivation(MessageEndpointFactory mef, ActivationSpec as) throws ResourceException {
    if (!(as instanceof MDBActivationSpec)) {
        LOG.fine("Ignored unknown activation spec " + as);
        return;
    }
    MDBActivationSpec spec = (MDBActivationSpec) as;
    LOG.info("CXF resource adapter is activating " + spec.getDisplayName());
    Work work = new MDBActivationWork(spec, mef, endpoints);
    ctx.getWorkManager().scheduleWork(work);
}
Also used : MDBActivationSpec(org.apache.cxf.jca.inbound.MDBActivationSpec) MDBActivationWork(org.apache.cxf.jca.inbound.MDBActivationWork) MDBActivationWork(org.apache.cxf.jca.inbound.MDBActivationWork) Work(javax.resource.spi.work.Work)

Aggregations

Work (javax.resource.spi.work.Work)8 ResourceException (javax.resource.ResourceException)2 WorkCompletedException (javax.resource.spi.work.WorkCompletedException)2 WorkException (javax.resource.spi.work.WorkException)2 IOException (java.io.IOException)1 ClosedWatchServiceException (java.nio.file.ClosedWatchServiceException)1 Semaphore (java.util.concurrent.Semaphore)1 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)1 MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)1 WorkManager (javax.resource.spi.work.WorkManager)1 WorkRejectedException (javax.resource.spi.work.WorkRejectedException)1 MDBActivationSpec (org.apache.cxf.jca.inbound.MDBActivationSpec)1 MDBActivationWork (org.apache.cxf.jca.inbound.MDBActivationWork)1 NamedBootstrapContext (org.jboss.as.connector.services.bootstrap.NamedBootstrapContext)1 NamedWorkManager (org.jboss.as.connector.services.workmanager.NamedWorkManager)1 TelnetListener (org.jboss.as.test.integration.ejb.mdb.dynamic.api.TelnetListener)1 TelnetServer (org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TelnetServer)1 Test (org.junit.Test)1 TaskRejectedException (org.springframework.core.task.TaskRejectedException)1 TaskTimeoutException (org.springframework.core.task.TaskTimeoutException)1