use of javax.resource.spi.work.Work in project spring-framework by spring-projects.
the class WorkManagerTaskExecutor method execute.
@Override
public void execute(Runnable task, long startTimeout) {
Assert.state(this.workManager != null, "No WorkManager specified");
Work work = new DelegatingWork(this.taskDecorator != null ? this.taskDecorator.decorate(task) : task);
try {
if (this.blockUntilCompleted) {
if (startTimeout != TIMEOUT_INDEFINITE || this.workListener != null) {
this.workManager.doWork(work, startTimeout, null, this.workListener);
} else {
this.workManager.doWork(work);
}
} else if (this.blockUntilStarted) {
if (startTimeout != TIMEOUT_INDEFINITE || this.workListener != null) {
this.workManager.startWork(work, startTimeout, null, this.workListener);
} else {
this.workManager.startWork(work);
}
} else {
if (startTimeout != TIMEOUT_INDEFINITE || this.workListener != null) {
this.workManager.scheduleWork(work, startTimeout, null, this.workListener);
} else {
this.workManager.scheduleWork(work);
}
}
} catch (WorkRejectedException ex) {
if (WorkException.START_TIMED_OUT.equals(ex.getErrorCode())) {
throw new TaskTimeoutException("JCA WorkManager rejected task because of timeout: " + task, ex);
} else {
throw new TaskRejectedException("JCA WorkManager rejected task: " + task, ex);
}
} catch (WorkException ex) {
throw new SchedulingException("Could not schedule task on JCA WorkManager", ex);
}
}
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 maintaining 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(jtaxLogger.i18NLogger.get_jtax_transaction_jts_jca_busy(), WorkException.TX_CONCURRENT_WORK_DISALLOWED);
}
synchronized (workers) {
workers.push(work);
}
}
use of javax.resource.spi.work.Work in project wildfly by wildfly.
the class MultipleResourceAdapter2 method start.
/**
* This is called when a resource adapter instance is bootstrapped.
*
* @param ctx A bootstrap context containing references
* @throws ResourceAdapterInternalException indicates bootstrap failure.
*/
public void start(BootstrapContext ctx) throws ResourceAdapterInternalException {
log.trace("start()");
if (ctx instanceof NamedBootstrapContext) {
NamedBootstrapContext nc = (NamedBootstrapContext) ctx;
setBootstrapContextName(nc.getName());
log.trace("Bootstrap-context:" + nc.getName());
}
WorkManager wm = ctx.getWorkManager();
if (wm instanceof NamedWorkManager) {
NamedWorkManager nw = (NamedWorkManager) wm;
setWorkManagerName(nw.getName());
log.trace("Work-manager:" + nw.getName());
}
Work myWork1 = new MultipleWork();
Work myWork2 = new MultipleWork();
Work myWork3 = new MultipleWork();
try {
wm.doWork(myWork1);
wm.scheduleWork(myWork2);
wm.startWork(myWork3);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations