本文整理汇总了Java中com.google.common.util.concurrent.Service.State.compareTo方法的典型用法代码示例。如果您正苦于以下问题:Java State.compareTo方法的具体用法?Java State.compareTo怎么用?Java State.compareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.util.concurrent.Service.State
的用法示例。
在下文中一共展示了State.compareTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transitionService
import com.google.common.util.concurrent.Service.State; //导入方法依赖的package包/类
/**
* Updates the state with the given service transition.
*
* <p>This method performs the main logic of ServiceManager in the following steps.
* <ol>
* <li>Update the {@link #servicesByState()}
* <li>Update the {@link #startupTimers}
* <li>Based on the new state queue listeners to run
* <li>Run the listeners (outside of the lock)
* </ol>
*/
void transitionService(final Service service, State from, State to) {
checkNotNull(service);
checkArgument(from != to);
monitor.enter();
try {
transitioned = true;
if (!ready) {
return;
}
// Update state.
checkState(
servicesByState.remove(from, service),
"Service %s not at the expected location in the state map %s",
service,
from);
checkState(
servicesByState.put(to, service),
"Service %s in the state map unexpectedly at %s",
service,
to);
// Update the timer
Stopwatch stopwatch = startupTimers.get(service);
if (stopwatch == null) {
// This means the service was started by some means other than ServiceManager.startAsync
stopwatch = Stopwatch.createStarted();
startupTimers.put(service, stopwatch);
}
if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {
// N.B. if we miss the STARTING event then we may never record a startup time.
stopwatch.stop();
if (!(service instanceof NoOpService)) {
logger.log(Level.FINE, "Started {0} in {1}.", new Object[] {service, stopwatch});
}
}
// Queue our listeners
// Did a service fail?
if (to == FAILED) {
enqueueFailedEvent(service);
}
if (states.count(RUNNING) == numberOfServices) {
// This means that the manager is currently healthy. N.B. If other threads call isHealthy
// they are not guaranteed to get 'true', because any service could fail right now.
enqueueHealthyEvent();
} else if (states.count(TERMINATED) + states.count(FAILED) == numberOfServices) {
enqueueStoppedEvent();
}
} finally {
monitor.leave();
// Run our executors outside of the lock
dispatchListenerEvents();
}
}
示例2: transitionService
import com.google.common.util.concurrent.Service.State; //导入方法依赖的package包/类
/**
* Updates the state with the given service transition.
*
* <p>This method performs the main logic of ServiceManager in the following steps.
* <ol>
* <li>Update the {@link #servicesByState()}
* <li>Update the {@link #startupTimers}
* <li>Based on the new state queue listeners to run
* <li>Run the listeners (outside of the lock)
* </ol>
*/
void transitionService(final Service service, State from, State to) {
checkNotNull(service);
checkArgument(from != to);
monitor.enter();
try {
transitioned = true;
if (!ready) {
return;
}
// Update state.
checkState(
servicesByState.remove(from, service),
"Service %s not at the expected location in the state map %s",
service,
from);
checkState(
servicesByState.put(to, service),
"Service %s in the state map unexpectedly at %s",
service,
to);
// Update the timer
Stopwatch stopwatch = startupTimers.get(service);
if (stopwatch == null) {
// This means the service was started by some means other than ServiceManager.startAsync
stopwatch = Stopwatch.createStarted();
startupTimers.put(service, stopwatch);
}
if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {
// N.B. if we miss the STARTING event then we may never record a startup time.
stopwatch.stop();
if (!(service instanceof NoOpService)) {
logger.log(Level.FINE, "Started {0} in {1}.", new Object[] {service, stopwatch});
}
}
// Queue our listeners
// Did a service fail?
if (to == FAILED) {
fireFailedListeners(service);
}
if (states.count(RUNNING) == numberOfServices) {
// This means that the manager is currently healthy. N.B. If other threads call isHealthy
// they are not guaranteed to get 'true', because any service could fail right now.
fireHealthyListeners();
} else if (states.count(TERMINATED) + states.count(FAILED) == numberOfServices) {
fireStoppedListeners();
}
} finally {
monitor.leave();
// Run our executors outside of the lock
executeListeners();
}
}