本文整理汇总了Java中javax.enterprise.concurrent.ManagedScheduledExecutorService类的典型用法代码示例。如果您正苦于以下问题:Java ManagedScheduledExecutorService类的具体用法?Java ManagedScheduledExecutorService怎么用?Java ManagedScheduledExecutorService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ManagedScheduledExecutorService类属于javax.enterprise.concurrent包,在下文中一共展示了ManagedScheduledExecutorService类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doCheck
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
private static void doCheck(final ManagedExecutorService es, final ManagedScheduledExecutorService ses, final ManagedThreadFactory tf) {
assertNotNull(es);
assertNotNull(ses);
assertNotNull(tf);
assertThat(es, instanceOf(ManagedExecutorServiceImpl.class));
assertEquals(2, pool(es).getCorePoolSize());
assertEquals(10, pool(es).getMaximumPoolSize());
assertEquals(4, pool(es).getKeepAliveTime(TimeUnit.MINUTES));
assertThat(ses, instanceOf(ManagedScheduledExecutorServiceImpl.class));
assertEquals(12, pool(ses).getCorePoolSize());
assertThat(tf, instanceOf(ManagedThreadFactoryImpl.class));
assertEquals("custom-", Reflections.get(tf, "prefix"));
}
示例2: schedule
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) {
ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor;
return executor.schedule(task, new javax.enterprise.concurrent.Trigger() {
@Override
public Date getNextRunTime(LastExecution le, Date taskScheduledTime) {
return trigger.nextExecutionTime(le != null ?
new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) :
new SimpleTriggerContext());
}
@Override
public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) {
return false;
}
});
}
示例3: schedule
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) {
ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor;
return executor.schedule(task, new javax.enterprise.concurrent.Trigger() {
@Override
public Date getNextRunTime(LastExecution le, Date taskScheduledTime) {
return trigger.nextExecutionTime(le != null ? new SimpleTriggerContext(le.getScheduledStart(), le
.getRunStart(), le.getRunEnd()) : new SimpleTriggerContext());
}
@Override
public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) {
return false;
}
});
}
示例4: testCreateConnectingDelegateHelloBadConnectionType
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
@Test
public void testCreateConnectingDelegateHelloBadConnectionType(@Mocked Site site1,
@Mocked RoomInfo info,
@Mocked ClientMediatorPod pod1) throws Exception {
// Special mock of sched exec to run immediately
ManagedScheduledExecutorService executor = new MockUp<ManagedScheduledExecutorService>() {
@Mock
public void execute(Runnable command) {
System.out.println("HEY!!!");
command.run();
}
}.getMockInstance();
builder.scheduledExecutor = executor;
new Expectations() {{
site1.getId(); result = roomId;
site1.getInfo(); result = info;
info.getName(); result = roomName;
info.getFullName(); result = roomFullName;
info.getConnectionDetails().getType(); result = "unknown";
}};
RemoteRoomProxy proxy = new RemoteRoomProxy(builder, userView, roomId);
Field field_updating = RemoteRoomProxy.class.getDeclaredField("updating");
field_updating.setAccessible(true);
AtomicBoolean updating = (AtomicBoolean) field_updating.get(proxy);
Assert.assertEquals(Type.CONNECTING, proxy.getType()); // proxy type should reflect the guts!
// Attempt connection with bad type
proxy.hello(pod1);
Assert.assertFalse("Updating flag should be reset to false", updating.get());
Assert.assertEquals(Type.SICK, proxy.getType()); // proxy type should reflect the guts!
}
示例5: afterInitialized
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
public final void afterInitialized(@Observes @Initialized(ApplicationScoped.class) Object event)
throws NamingException {
ManagedScheduledExecutorService executor =
lookupBean("java:comp/DefaultManagedScheduledExecutorService", ManagedScheduledExecutorService.class);
ContextService proxy = lookupBean("java:comp/DefaultContextService", ContextService.class);
future = executor.scheduleAtFixedRate(
() -> proxy.createContextualProxy(lookupBean(getJobType()), Runnable.class).run(),
0,
getPeriodTime(),
getTimeUnit());
}
示例6: schedule
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
/**
* Schedule.
*
* @param task
* the task
* @param trigger
* the trigger
* @return the scheduled future
*/
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) {
ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor;
return executor.schedule(task, new javax.enterprise.concurrent.Trigger() {
@Override
public Date getNextRunTime(LastExecution le, Date taskScheduledTime) {
return trigger.nextExecutionTime(le != null ? new SimpleTriggerContext(le.getScheduledStart(), le
.getRunStart(), le.getRunEnd()) : new SimpleTriggerContext());
}
@Override
public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) {
return false;
}
});
}
示例7: add
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
private void add(final JndiConsumer jndi, final DeploymentModule module, final DeploymentModule app, final boolean defaults) {
// Standard names
add(jndi.getEnvEntryMap(), new EnvEntry().name("java:module/ModuleName").value(module.getModuleId()).type(String.class));
add(jndi.getEnvEntryMap(), new EnvEntry().name("java:app/AppName").value(app.getModuleId()).type(String.class));
// Standard References to built-in objects
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/BeanManager").type(BeanManager.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/Validator").type(Validator.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/ValidatorFactory").type(ValidatorFactory.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/TransactionManager").type(TransactionManager.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/TransactionSynchronizationRegistry").type(TransactionSynchronizationRegistry.class));
if (defaults) {
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedExecutorService").type(ManagedExecutorService.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedScheduledExecutorService").type(ManagedScheduledExecutorService.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedThreadFactory").type(ManagedThreadFactory.class));
add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultContextService").type(ContextService.class));
try {
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
contextClassLoader.loadClass("org.apache.activemq.ActiveMQSslConnectionFactory");
final ResourceEnvRef ref = new ResourceEnvRef().name("java:comp/DefaultJMSConnectionFactory")
.type(contextClassLoader.loadClass("javax.jms.ConnectionFactory"));
add(jndi.getResourceEnvRefMap(), ref);
} catch (final ClassNotFoundException | NoClassDefFoundError notThere) {
// no-op
}
}
// OpenEJB specific feature
add(jndi.getEnvEntryMap(), new EnvEntry().name("java:comp/ComponentName").value(jndi.getJndiConsumerName()).type(String.class));
}
示例8: doCheck
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
private static void doCheck(final ManagedExecutorService es, final ManagedScheduledExecutorService ses,
final ContextService ces, final ManagedThreadFactory tf) {
assertNotNull(es);
assertNotNull(ses);
assertNotNull(ces);
assertNotNull(tf);
assertThat(es, instanceOf(ManagedExecutorServiceImpl.class));
assertThat(ses, instanceOf(ManagedScheduledExecutorServiceImpl.class));
assertThat(ces, instanceOf(ContextServiceImpl.class));
assertThat(tf, instanceOf(ManagedThreadFactoryImpl.class));
}
示例9: simpleSchedule
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
@Test
public void simpleSchedule() throws Exception {
final ManagedScheduledExecutorService es = new ManagedScheduledExecutorServiceImplFactory().create();
final long start = System.currentTimeMillis();
final ScheduledFuture<Long> future = es.schedule(new Callable<Long>() {
@Override
public Long call() throws Exception {
Thread.sleep(4000);
return System.currentTimeMillis();
}
}, 2, TimeUnit.SECONDS);
assertEquals(6, TimeUnit.MILLISECONDS.toSeconds(future.get() - start), 1);
}
示例10: getExecutorService
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
@Override
protected ManagedScheduledExecutorService getExecutorService() {
return executorService;
}
示例11: init
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
public void init(@Observes @Initialized(ApplicationScoped.class) Object o) {
ManagedScheduledExecutorService executorService = getExecutorService();
executorService.scheduleAtFixedRate(new ActorTask(this), 0L, 10L, TimeUnit.SECONDS);
}
示例12: testEmitEvents
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testEmitEvents(@Mocked ManagedScheduledExecutorService executor,
@Mocked KafkaConsumer<String,String> consumer,
@Mocked ScheduledFuture future, @Mocked ConsumerRecord<String,String> record1, @Mocked ConsumerRecord<String,String> record2){
KafkaCDIBridge kcdib = new KafkaCDIBridge();
Deencapsulation.setField(kcdib,"consumer",consumer);
Deencapsulation.setField(kcdib,"executor",executor);
Map<TopicPartition, List<ConsumerRecord<String,String>>> data = new HashMap<>();
List<ConsumerRecord<String,String>> records = new ArrayList<>();
records.add(record1);
records.add(record2);
data.put(new TopicPartition("playerEvents", 1), records);
ConsumerRecords<String, String> cr = new ConsumerRecords<String,String>(data);
new Expectations() {{
executor.scheduleWithFixedDelay((Runnable) any,anyLong,anyLong,(TimeUnit)any); result = future;
consumer.subscribe((List<String>)any);
record1.offset(); result=0L;
record2.offset(); result=1L;
record1.key(); result="stilettos";
record2.key(); result="wedge";
record1.topic(); result="playerEvents";
record2.topic(); result="playerEvents";
record1.value(); result="leather";
record2.value(); result="patent";
}};
kcdib.init(null);
new Verifications() {{
//retrieve and invoke the nested thread..
Runnable r;
executor.scheduleWithFixedDelay(r = withCapture(), anyLong, anyLong, (TimeUnit)any);
consumer.subscribe((List<String>)any);
new Expectations() {{
CDI.current(); result = cdi;
cdi.getBeanManager(); result = bm;
consumer.poll(anyLong); result = cr;
}};
r.run();
new Verifications() {{
List<Object> events = new ArrayList<>();
//verify that 2 fire event calls are made.
bm.fireEvent(withCapture(events)); times = 2;
Assert.assertEquals(2, events.size());
Assert.assertEquals(GameOnEvent.class, events.get(0).getClass());
Assert.assertEquals(GameOnEvent.class, events.get(1).getClass());
GameOnEvent e1 = (GameOnEvent)events.get(0);
GameOnEvent e2 = (GameOnEvent)events.get(1);
Assert.assertEquals("stilettos",e1.getKey());
Assert.assertEquals("wedge",e2.getKey());
Assert.assertEquals("playerEvents",e1.getTopic());
Assert.assertEquals("playerEvents",e2.getTopic());
Assert.assertEquals("leather",e1.getValue());
Assert.assertEquals("patent",e2.getValue());
Assert.assertEquals(0L,e1.getOffset());
Assert.assertEquals(1L,e2.getOffset());
}};
}};
new Expectations() {{
future.cancel(anyBoolean);
consumer.close();
}};
kcdib.destroy(null);
}
示例13: getExecutorService
import javax.enterprise.concurrent.ManagedScheduledExecutorService; //导入依赖的package包/类
protected abstract ManagedScheduledExecutorService getExecutorService();