本文整理汇总了Java中javax.resource.spi.work.Work类的典型用法代码示例。如果您正苦于以下问题:Java Work类的具体用法?Java Work怎么用?Java Work使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Work类属于javax.resource.spi.work包,在下文中一共展示了Work类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startWork
import javax.resource.spi.work.Work; //导入依赖的package包/类
@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);
}
示例2: testFailingWork
import javax.resource.spi.work.Work; //导入依赖的package包/类
@Test public void testFailingWork() throws Exception {
pool = new ThreadReuseExecutor("test", 5); //$NON-NLS-1$
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));
}
示例3: execute
import javax.resource.spi.work.Work; //导入依赖的package包/类
void execute(final Work arg0, final WorkListener arg3, boolean join) throws WorkException {
if (arg3 != null) {
arg3.workAccepted(Mockito.mock(WorkEvent.class));
arg3.workStarted(Mockito.mock(WorkEvent.class));
}
t = new Thread(new Runnable() {
@Override
public void run() {
arg0.run();
if (arg3 != null) {
arg3.workCompleted(Mockito.mock(WorkEvent.class));
}
}
});
t.start();
if (join) {
try {
t.join();
} catch (InterruptedException e) {
throw new WorkException(e);
}
}
}
示例4: invoke
import javax.resource.spi.work.Work; //导入依赖的package包/类
private void invoke(final MessageEndpoint endpoint, final Method m, final Path path) throws WorkException {
resourceAdapter.getBootstrapContext().getWorkManager().scheduleWork(new Work() {
@Override
public void run() {
try {
Method endpointMethod = endpoint.getClass().getMethod(m.getName(), m.getParameterTypes());
endpoint.beforeDelivery(endpointMethod);
endpointMethod.invoke(endpoint, path.toFile());
endpoint.afterDelivery();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void release() {}
});
}
示例5: workStarted
import javax.resource.spi.work.Work; //导入依赖的package包/类
/**
* start work
*
* @param e workEvent
*/
@Override
public void workStarted(WorkEvent e)
{
if (e.getType() != WorkEvent.WORK_STARTED)
fail("Wrong started type");
timeStarted = System.currentTimeMillis();
super.workStarted(e);
Work work = e.getWork();
if (work instanceof NestProviderWork)
{
NestProviderWork nw = (NestProviderWork) work;
start.append(nw.getName());
}
}
示例6: workRejected
import javax.resource.spi.work.Work; //导入依赖的package包/类
/**
* start work
*
* @param e workEvent
*/
@Override
public void workRejected(WorkEvent e)
{
if (e.getType() != WorkEvent.WORK_REJECTED)
fail("Wrong rejected type");
timeRejected = System.currentTimeMillis();
super.workRejected(e);
Work work = e.getWork();
if (work instanceof NestProviderWork)
{
NestProviderWork nw = (NestProviderWork) work;
reject.append(nw.getName());
}
}
示例7: workCompleted
import javax.resource.spi.work.Work; //导入依赖的package包/类
/**
* complete work
*
* @param e workEvent
*/
@Override
public void workCompleted(WorkEvent e)
{
if (e.getType() != WorkEvent.WORK_COMPLETED)
fail("Wrong completed type");
timeCompleted = System.currentTimeMillis();
super.workCompleted(e);
Work work = e.getWork();
if (work instanceof NestProviderWork)
{
NestProviderWork nw = (NestProviderWork) work;
done.append(nw.getName());
exception = e.getException();
}
}
示例8: doWork
import javax.resource.spi.work.Work; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void doWork(Work work) throws WorkException
{
if (policy == null || selector == null || transport == null ||
work == null || !(work instanceof DistributableWork) || !doWorkDistributionEnabled)
{
localDoWork(work);
}
else
{
doFirstChecks(work, WorkManager.INDEFINITE, null);
checkTransport();
DistributableWork dw = (DistributableWork)work;
boolean executed = false;
if (policy.shouldDistribute(this, dw))
{
Address dwmAddress = selector.selectDistributedWorkManager(getLocalAddress(), dw);
if (dwmAddress != null && !getLocalAddress().equals(dwmAddress))
{
transport.doWork(dwmAddress, dw);
executed = true;
}
}
if (!executed)
{
localDoWork(work);
}
}
}
示例9: verifyWork
import javax.resource.spi.work.Work; //导入依赖的package包/类
/**
* Verify the given work instance.
* @param work The work
* @throws WorkException Thrown if a spec compliant issue is found
*/
private void verifyWork(Work work) throws WorkException
{
Class<? extends Work> workClass = work.getClass();
String className = workClass.getName();
if (!validatedWork.contains(className))
{
if (isWorkMethodSynchronized(workClass, RUN_METHOD_NAME))
throw new WorkException(bundle.runMethodIsSynchronized(className));
if (isWorkMethodSynchronized(workClass, RELEASE_METHOD_NAME))
throw new WorkException(bundle.releaseMethodIsSynchronized(className));
validatedWork.add(className);
}
}
示例10: isWorkMethodSynchronized
import javax.resource.spi.work.Work; //导入依赖的package包/类
/**
* Checks, if Work implementation class method is synchronized
* @param workClass - implementation class
* @param methodName - could be "run" or "release"
* @return true, if method is synchronized, false elsewhere
*/
private boolean isWorkMethodSynchronized(Class<? extends Work> workClass, String methodName)
{
try
{
Method method = SecurityActions.getMethod(workClass, methodName, new Class[0]);
if (Modifier.isSynchronized(method.getModifiers()))
return true;
}
catch (NoSuchMethodException e)
{
//Never happens, Work implementation should have these methods
}
return false;
}
示例11: doWork
import javax.resource.spi.work.Work; //导入依赖的package包/类
@Override
public void doWork(Work work) throws WorkException {
doWork(work, WorkManager.INDEFINITE, null, null);
}
示例12: scheduleWork
import javax.resource.spi.work.Work; //导入依赖的package包/类
@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);
}
示例13: doWork
import javax.resource.spi.work.Work; //导入依赖的package包/类
@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);
}
示例14: startWork
import javax.resource.spi.work.Work; //导入依赖的package包/类
@Override
public long startWork(Work work,
long l,
ExecutionContext executionContext,
WorkListener workListener) throws WorkException {
return 0;
}
示例15: stop
import javax.resource.spi.work.Work; //导入依赖的package包/类
public void stop() {
for (int i = 0; this.workList != null && i < this.workList.size(); i++) {
Work work = this.workList.get(i);
try {
work.release();
} catch (RuntimeException rex) {
logger.debug(rex.getMessage(), rex);
}
}
}