本文整理汇总了Java中com.google.common.util.concurrent.Service.State.STARTING属性的典型用法代码示例。如果您正苦于以下问题:Java State.STARTING属性的具体用法?Java State.STARTING怎么用?Java State.STARTING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.common.util.concurrent.Service.State
的用法示例。
在下文中一共展示了State.STARTING属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCustomScheduler_deadlock
public void testCustomScheduler_deadlock() throws InterruptedException, BrokenBarrierException {
final CyclicBarrier inGetNextSchedule = new CyclicBarrier(2);
// This will flakily deadlock, so run it multiple times to increase the flake likelihood
for (int i = 0; i < 1000; i++) {
Service service = new AbstractScheduledService() {
@Override protected void runOneIteration() {}
@Override protected Scheduler scheduler() {
return new CustomScheduler() {
@Override protected Schedule getNextSchedule() throws Exception {
if (state() != State.STARTING) {
inGetNextSchedule.await();
Thread.yield();
throw new RuntimeException("boom");
}
return new Schedule(0, TimeUnit.NANOSECONDS);
}
};
}
};
service.startAsync().awaitRunning();
inGetNextSchedule.await();
service.stopAsync();
}
}
示例2: enqueueStoppingEvent
private void enqueueStoppingEvent(final State from) {
if (from == State.STARTING) {
listeners.enqueue(STOPPING_FROM_STARTING_EVENT);
} else if (from == State.RUNNING) {
listeners.enqueue(STOPPING_FROM_RUNNING_EVENT);
} else {
throw new AssertionError();
}
}
示例3: stopping
@Override public synchronized void stopping(State from) {
assertEquals(from, Iterables.getLast(stateHistory));
stateHistory.add(State.STOPPING);
if (from == State.STARTING) {
try {
service.awaitRunning();
fail();
} catch (IllegalStateException expected) {
assertNull(expected.getCause());
assertTrue(expected.getMessage().equals(
"Expected the service " + service + " to be RUNNING, but was STOPPING"));
}
}
assertNotSame(from, service.state());
}
示例4: stopping
@GuardedBy("monitor")
private void stopping(final State from) {
if (from == State.STARTING) {
STOPPING_FROM_STARTING_CALLBACK.enqueueOn(listeners);
} else if (from == State.RUNNING) {
STOPPING_FROM_RUNNING_CALLBACK.enqueueOn(listeners);
} else {
throw new AssertionError();
}
}
示例5: isStarting
@Override
public final boolean isStarting() {
return service.state() == State.STARTING;
}