本文整理汇总了Java中javax.resource.spi.work.WorkManager类的典型用法代码示例。如果您正苦于以下问题:Java WorkManager类的具体用法?Java WorkManager怎么用?Java WorkManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WorkManager类属于javax.resource.spi.work包,在下文中一共展示了WorkManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWorkManager
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
/**
* Obtain the default JBoss JCA WorkManager through a JMX lookup
* for the JBossWorkManagerMBean.
* @param mbeanName the JMX object name to use
* @see org.jboss.resource.work.JBossWorkManagerMBean
*/
public static WorkManager getWorkManager(String mbeanName) {
Assert.hasLength(mbeanName, "JBossWorkManagerMBean name must not be empty");
try {
Class<?> mbeanClass = JBossWorkManagerUtils.class.getClassLoader().loadClass(JBOSS_WORK_MANAGER_MBEAN_CLASS_NAME);
InitialContext jndiContext = new InitialContext();
MBeanServerConnection mconn = (MBeanServerConnection) jndiContext.lookup(MBEAN_SERVER_CONNECTION_JNDI_NAME);
ObjectName objectName = ObjectName.getInstance(mbeanName);
Object workManagerMBean = MBeanServerInvocationHandler.newProxyInstance(mconn, objectName, mbeanClass, false);
Method getInstanceMethod = workManagerMBean.getClass().getMethod("getInstance");
return (WorkManager) getInstanceMethod.invoke(workManagerMBean);
}
catch (Exception ex) {
throw new IllegalStateException(
"Could not initialize JBossWorkManagerTaskExecutor because JBoss API is not available", ex);
}
}
示例2: run
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
/**
* run method
*/
public void run()
{
try
{
if (nestWork != null && workManager != null)
{
if (nestDo)
workManager.doWork(nestWork, WorkManager.INDEFINITE, null, wa);
else
workManager.startWork(nestWork, WorkManager.INDEFINITE, null, wa);
}
}
catch (Throwable e)
{
throw new RuntimeException(e.getMessage());
}
}
示例3: testThrowWorkCompletedException
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
/**
* 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();
}
}
示例4: testFifoStartLifoFinish
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
/**
* Test for paragraph 3
* doWork method: this provides a first in, first out (FIFO) execution start
* ordering and last in, first out (LIFO) execution completion ordering guarantee.
* @throws Throwable throwable exception
*/
@Test
public void testFifoStartLifoFinish() throws Throwable
{
ContextWorkAdapter wa = new ContextWorkAdapter();
NestProviderWork workA = new NestProviderWork("A", wa);
workA.addContext(new TransactionContext());
NestProviderWork workB = new NestProviderWork("B", null);
workB.addContext(new WorkContextSetupListenerTransactionContext());
WorkConnection wc = wcf.getConnection();
workA.setNestDo(true);
workA.setWorkManager(wc.getWorkManager());
workA.setWork(workB);
wc.doWork(workA, WorkManager.INDEFINITE, null, wa);
assertEquals(wa.getStart(), "AB");
assertEquals(wa.getDone(), "BA");
wc.close();
}
示例5: testFifoStart
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
/**
* Test for paragraph 4
* startWork method: this provides a FIFO execution start ordering guarantee,
* but no execution completion ordering guarantee.
* @throws Throwable throwable exception
*/
//@Test
public void testFifoStart() throws Throwable
{
ContextWorkAdapter wa = new ContextWorkAdapter();
NestProviderWork workA = new NestProviderWork("A", wa);
workA.addContext(new NestedWorkSecurityContext());
NestProviderWork workB = new NestProviderWork("B", null);
workB.addContext(new HintsContext());
WorkConnection wc = wcf.getConnection();
workA.setNestDo(false);
workA.setWorkManager(wc.getWorkManager());
workA.setWork(workB);
CyclicBarrier barrier = new CyclicBarrier(3);
workA.setBarrier(barrier);
workB.setBarrier(barrier);
wc.startWork(workA, WorkManager.INDEFINITE, null, wa);
barrier.await();
assertEquals(wa.getStart(), "AB");
wc.close();
}
示例6: testFifoSchedule
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
/**
* Test for paragraph 4
* scheduletWork method: this provides a FIFO execution start ordering guarantee,
* but no execution completion ordering guarantee.
* @throws Throwable throwable exception
*/
//@Test
public void testFifoSchedule() throws Throwable
{
ContextWorkAdapter wa = new ContextWorkAdapter();
NestProviderWork workA = new NestProviderWork("A", wa);
workA.addContext(new NestedWorkSecurityContext());
NestProviderWork workB = new NestProviderWork("B", null);
workB.addContext(new HintsContext());
WorkConnection wc = wcf.getConnection();
workA.setNestDo(false);
workA.setWorkManager(wc.getWorkManager());
workA.setWork(workB);
CyclicBarrier barrier = new CyclicBarrier(3);
workA.setBarrier(barrier);
workB.setBarrier(barrier);
wc.scheduleWork(workA, WorkManager.INDEFINITE, null, wa);
barrier.await();
assertEquals(wa.getStart(), "AB");
wc.close();
}
示例7: testDoWorkUnsupportedContext
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
/**
* Test unsupported context nested doWork.
* @throws Throwable throwable exception
*/
//@Test(expected = Throwable.class)
public void testDoWorkUnsupportedContext() throws Throwable
{
ContextWorkAdapter wa = new ContextWorkAdapter();
NestProviderWork workA = new NestProviderWork("A", wa);
workA.addContext(new TransactionContext());
NestProviderWork workB = new NestProviderWork("B", null);
workB.addContext(new UnsupportedContext());
WorkConnection wc = wcf.getConnection();
workA.setNestDo(true);
workA.setWorkManager(wc.getWorkManager());
workA.setWork(workB);
wc.doWork(workA, WorkManager.INDEFINITE, null, wa);
wc.close();
}
示例8: testStartWorkUnsupportedContext
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
/**
* Test unsupported context nested startWork
* @throws Throwable throwable exception
*/
//@Test
public void testStartWorkUnsupportedContext() throws Throwable
{
ContextWorkAdapter wa = new ContextWorkAdapter();
NestProviderWork workA = new NestProviderWork("A", wa);
workA.addContext(new HintsContext());
NestProviderWork workB = new NestProviderWork("B", null);
workB.addContext(new UnsupportedContext());
WorkConnection wc = wcf.getConnection();
workA.setNestDo(false);
workA.setWorkManager(wc.getWorkManager());
workA.setWork(workB);
CyclicBarrier barrier = new CyclicBarrier(2);
workA.setBarrier(barrier);
workB.setBarrier(barrier);
wc.startWork(workA, WorkManager.INDEFINITE, null, wa);
barrier.await();
assertNotNull(wa.getException());
wc.close();
}
示例9: testScheduleWorkUnsupportedContext
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
/**
* Test unsupported context nested scheduleWork
* @throws Throwable throwable exception
*/
//@Test
public void testScheduleWorkUnsupportedContext() throws Throwable
{
ContextWorkAdapter wa = new ContextWorkAdapter();
NestProviderWork workA = new NestProviderWork("A", wa);
workA.addContext(new HintsContext());
NestProviderWork workB = new NestProviderWork("B", null);
workB.addContext(new UnsupportedContext());
WorkConnection wc = wcf.getConnection();
workA.setNestDo(false);
workA.setWorkManager(wc.getWorkManager());
workA.setWork(workB);
CyclicBarrier barrier = new CyclicBarrier(2);
workA.setBarrier(barrier);
workB.setBarrier(barrier);
wc.getWorkManager().scheduleWork(workA, WorkManager.INDEFINITE, null, wa);
barrier.await();
assertNotNull(wa.getException());
wc.close();
}
示例10: doWork
import javax.resource.spi.work.WorkManager; //导入依赖的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);
}
}
}
示例11: clone
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
/**
* Clone the WorkManager implementation
* @return A copy of the implementation
* @exception CloneNotSupportedException Thrown if the copy operation isn't supported
*
*/
@Override
public org.ironjacamar.core.api.workmanager.WorkManager clone() throws CloneNotSupportedException
{
DistributedWorkManagerImpl wm = (DistributedWorkManagerImpl)super.clone();
wm.setPolicy(getPolicy());
wm.setSelector(getSelector());
wm.setTransport(getTransport());
wm.setDistributedStatisticsEnabled(isDistributedStatisticsEnabled());
wm.setDoWorkDistributionEnabled(isDoWorkDistributionEnabled());
wm.setStartWorkDistributionEnabled(isStartWorkDistributionEnabled());
wm.setScheduleWorkDistributionEnabled(isScheduleWorkDistributionEnabled());
DistributedWorkManagerStatisticsImpl dwmsi = new DistributedWorkManagerStatisticsImpl();
wm.setDistributedStatistics(dwmsi);
if (getPolicy() != null && getPolicy() instanceof NotificationListener)
wm.listeners.add((NotificationListener)getPolicy());
if (getSelector() != null && getSelector() instanceof NotificationListener)
wm.listeners.add((NotificationListener)getSelector());
if (getTransport() != null && getTransport() instanceof NotificationListener)
wm.listeners.add((NotificationListener)getTransport());
wm.listeners.add((NotificationListener)dwmsi);
return wm;
}
示例12: postProcessBeanFactory
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
@Override
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
beanFactory.addBeanPostProcessor(new BootstrapContextAwareProcessor(this.bootstrapContext));
beanFactory.ignoreDependencyInterface(BootstrapContextAware.class);
beanFactory.registerResolvableDependency(BootstrapContext.class, this.bootstrapContext);
// JCA WorkManager resolved lazily - may not be available.
beanFactory.registerResolvableDependency(WorkManager.class, new ObjectFactory<WorkManager>() {
@Override
public WorkManager getObject() {
return bootstrapContext.getWorkManager();
}
});
}
示例13: getWorkManager
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
@Override
public WorkManager getWorkManager() {
if (this.workManager == null) {
throw new IllegalStateException("No WorkManager available");
}
return this.workManager;
}
示例14: afterPropertiesSet
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws NamingException {
if (this.workManager == null) {
if (this.workManagerName != null) {
this.workManager = lookup(this.workManagerName, WorkManager.class);
}
else {
this.workManager = getDefaultWorkManager();
}
}
}
示例15: doWork
import javax.resource.spi.work.WorkManager; //导入依赖的package包/类
@Override
public void doWork(Work work) throws WorkException {
doWork(work, WorkManager.INDEFINITE, null, null);
}