本文整理汇总了Java中com.google.common.util.concurrent.Service.State方法的典型用法代码示例。如果您正苦于以下问题:Java Service.State方法的具体用法?Java Service.State怎么用?Java Service.State使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.util.concurrent.Service
的用法示例。
在下文中一共展示了Service.State方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startAsync
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
public void startAsync() {
if (stratumClient == null){
log.info("Forcing service start");
connectionExec.remove(reconnectTask);
createStratumClient();
}
Service.State state = stratumClient.state();
if (state != NEW || stopped) {
log.debug("Not starting service as it is already started or explicitly stopped");
return;
}
try {
stratumClient.startAsync();
} catch (IllegalStateException e) {
// This can happen if the service has already been started or stopped (e.g. by another
// service or listener). Our contract says it is safe to call this method if
// all services were NEW when it was called, and this has already been verified above, so we
// don't propagate the exception.
log.warn("Unable to start Service " + type.getName(), e);
}
}
示例2: terminated
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Override
public void terminated(Service.State from) {
log.info("{} client stopped", type.getName());
broadcastOnDisconnect();
failedAddresses.add(lastServerAddress);
lastServerAddress = null;
stratumClient = null;
// Try to restart
if (!stopped) {
log.info("Reconnecting {} in {} seconds", type.getName(), retrySeconds);
connectionExec.remove(connectionCheckTask);
connectionExec.remove(reconnectTask);
if (retrySeconds > 0) {
reconnectAt = System.currentTimeMillis() + retrySeconds * 1000;
connectionExec.schedule(reconnectTask, retrySeconds, TimeUnit.SECONDS);
} else {
connectionExec.execute(reconnectTask);
}
}
}
示例3: stopping
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Override
public void stopping(final Service.State from) {
if (hasCalled(Service.State.STOPPING)) {
return;
}
executor.execute(new Runnable() {
@Override
public void run() {
try {
delegate.stopping(from);
} catch (Throwable t) {
LOG.warn("Exception thrown from listener", t);
}
}
});
}
示例4: terminated
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Override
public void terminated(final Service.State from) {
if (hasCalled(Service.State.TERMINATED)) {
return;
}
executor.execute(new Runnable() {
@Override
public void run() {
try {
delegate.terminated(from);
} catch (Throwable t) {
LOG.warn("Exception thrown from listener", t);
}
}
});
}
示例5: testCompletion
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Test
public void testCompletion() throws ExecutionException, InterruptedException {
Service service = new DummyService("s1", new AtomicBoolean());
ListenableFuture<Service.State> completion = Services.getCompletionFuture(service);
service.start();
service.stop();
completion.get();
AtomicBoolean transiting = new AtomicBoolean();
service = new DummyService("s2", transiting);
completion = Services.getCompletionFuture(service);
service.startAndWait();
transiting.set(true);
service.stop();
try {
completion.get();
Assert.assertTrue(false);
} catch (ExecutionException e) {
// Expected
}
}
示例6: onStop
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
/**
* Attaches the given callbacks which will be invoked when the given Service enters a TERMINATED or FAILED state.
* The callbacks are optional and may be invoked synchronously if the Service is already in one of these states.
*
* @param service The Service to attach to.
* @param terminatedCallback (Optional) A Runnable that will be invoked if the Service enters a TERMINATED state.
* @param failureCallback (Optional) A Runnable that will be invoked if the Service enters a FAILED state.
* @param executor An Executor to use for callback invocations.
*/
public static void onStop(Service service, Runnable terminatedCallback, Consumer<Throwable> failureCallback, Executor executor) {
ShutdownListener listener = new ShutdownListener(terminatedCallback, failureCallback);
service.addListener(listener, executor);
// addListener() will not invoke the callbacks if the service is already in a terminal state. As such, we need to
// manually check for these states after registering the listener and invoke the appropriate callback. The
// ShutdownListener will make sure they are not invoked multiple times.
Service.State state = service.state();
if (state == Service.State.FAILED) {
// We don't care (or know) the state from which we came, so we just pass some random one.
listener.failed(Service.State.FAILED, service.failureCause());
} else if (state == Service.State.TERMINATED) {
listener.terminated(Service.State.TERMINATED);
}
}
示例7: doChain
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
/**
* Performs the actual logic of chain Service start/stop.
*/
private static ListenableFuture<List<ListenableFuture<Service.State>>> doChain(boolean doStart,
Service firstService,
Service...moreServices) {
SettableFuture<List<ListenableFuture<Service.State>>> resultFuture = SettableFuture.create();
List<ListenableFuture<Service.State>> result = Lists.newArrayListWithCapacity(moreServices.length + 1);
ListenableFuture<Service.State> future = doStart ? firstService.start() : firstService.stop();
future.addListener(createChainListener(future, moreServices, new AtomicInteger(0), result, resultFuture, doStart),
Threads.SAME_THREAD_EXECUTOR);
return resultFuture;
}
示例8: serviceStatePredicate
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
private Predicate<Service> serviceStatePredicate(final Service.State state) {
return new Predicate<Service>() {
@Override
public boolean apply(Service service) {
return service.state() == state;
}
};
}
示例9: failed
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Override
public void failed(@Nonnull Service.State from, @Nonnull Throwable failure) {
if (!this.invoked.compareAndSet(false, true)) {
// Already invoked once. Don't double-call.
return;
}
if (this.failureCallback != null) {
this.failureCallback.accept(failure);
}
}
示例10: terminated
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Override
public void terminated(@Nonnull Service.State from) {
if (!this.invoked.compareAndSet(false, true)) {
// Already invoked once. Don't double-call.
return;
}
if (this.terminatedCallback != null) {
this.terminatedCallback.run();
}
}
示例11: describeState
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
private String describeState(Service.State state, boolean hasLeadership) {
if (state == Service.State.RUNNING && !hasLeadership) {
return "waiting to win leadership election";
} else {
return state.name();
}
}
示例12: servicesByState
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
public ImmutableMultimap<Service.State, Service> servicesByState() {
return serviceManager.servicesByState();
}
示例13: run
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Override
public void run() {
LOG.info("Starting Collector v{} (commit {})", CollectorVersion.CURRENT.version(), CollectorVersion.CURRENT.commitIdShort());
showOsInfo();
final Injector injector = getInjector();
serviceManager = injector.getInstance(CollectorServiceManager.class);
validateConfiguration(serviceManager.getConfiguration());
serviceManager.start();
for (Map.Entry<Service.State, Service> entry : serviceManager.servicesByState().entries()) {
LOG.info("Service {}: {}", entry.getKey().toString(), entry.getValue().toString());
}
serviceManager.awaitStopped();
}
示例14: run
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Override
public void run() {
// mark we are running now
this.sourceRunning = true;
try {
// start the endpoint, connect to the cluster
Service.State state = replicationEndpoint.start().get();
if (state != Service.State.RUNNING) {
LOG.warn("ReplicationEndpoint was not started. Exiting");
uninitialize();
return;
}
} catch (Exception ex) {
LOG.warn("Error starting ReplicationEndpoint, exiting", ex);
throw new RuntimeException(ex);
}
// get the WALEntryFilter from ReplicationEndpoint and add it to default filters
ArrayList<WALEntryFilter> filters = Lists.newArrayList(
(WALEntryFilter)new SystemTableWALEntryFilter());
WALEntryFilter filterFromEndpoint = this.replicationEndpoint.getWALEntryfilter();
if (filterFromEndpoint != null) {
filters.add(filterFromEndpoint);
}
this.walEntryFilter = new ChainWALEntryFilter(filters);
int sleepMultiplier = 1;
// delay this until we are in an asynchronous thread
while (this.isSourceActive() && this.peerClusterId == null) {
this.peerClusterId = replicationEndpoint.getPeerUUID();
if (this.isSourceActive() && this.peerClusterId == null) {
if (sleepForRetries("Cannot contact the peer's zk ensemble", sleepMultiplier)) {
sleepMultiplier++;
}
}
}
// In rare case, zookeeper setting may be messed up. That leads to the incorrect
// peerClusterId value, which is the same as the source clusterId
if (clusterId.equals(peerClusterId) && !replicationEndpoint.canReplicateToSameCluster()) {
this.terminate("ClusterId " + clusterId + " is replicating to itself: peerClusterId "
+ peerClusterId + " which is not allowed by ReplicationEndpoint:"
+ replicationEndpoint.getClass().getName(), null, false);
}
LOG.info("Replicating " + clusterId + " -> " + peerClusterId);
// start workers
for (Map.Entry<String, PriorityBlockingQueue<Path>> entry : queues.entrySet()) {
String walGroupId = entry.getKey();
PriorityBlockingQueue<Path> queue = entry.getValue();
final ReplicationSourceWorkerThread worker =
new ReplicationSourceWorkerThread(walGroupId, queue, replicationQueueInfo, this);
ReplicationSourceWorkerThread extant = workerThreads.putIfAbsent(walGroupId, worker);
if (extant != null) {
LOG.debug("Someone has beat us to start a worker thread for wal group " + walGroupId);
} else {
LOG.debug("Starting up worker for wal group " + walGroupId);
worker.startup();
}
}
}
示例15: stopping
import com.google.common.util.concurrent.Service; //导入方法依赖的package包/类
@Override
public void stopping(Service.State from) {
// No-op
}