com.google.common.util.concurrent.Service.stopAsync()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中com.google.common.util.concurrent.Service.stopAsync()方法的一些代码示例,展示了Service.stopAsync()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Service.stopAsync()方法的具体详情如下:
包路径:com.google.common.util.concurrent.Service
类名称:Service
方法名:stopAsync

Service.stopAsync介绍

[英]If the service is State#STARTING or State#RUNNING, this initiates service shutdown and returns immediately. If the service is State#NEW, it is State#TERMINATED without having been started nor stopped. If the service has already been stopped, this method returns immediately without taking action.
[中]如果服务处于状态#开始或状态#运行,则会启动服务关闭并立即返回。如果服务状态为#新建,则服务状态为#终止,且未启动或停止。如果服务已经停止,此方法将立即返回,而不采取任何操作。

代码示例

代码示例来源:origin: google/guava

/** @since 15.0 */
@CanIgnoreReturnValue
@Override
public final Service stopAsync() {
 delegate.stopAsync();
 return this;
}

代码示例来源:origin: google/guava

/**
 * Initiates service {@linkplain Service#stopAsync shutdown} if necessary on all the services
 * being managed.
 *
 * @return this
 */
@CanIgnoreReturnValue
public ServiceManager stopAsync() {
 for (Service service : services) {
  service.stopAsync();
 }
 return this;
}

代码示例来源:origin: google/guava

/** @since 15.0 */
@CanIgnoreReturnValue
@Override
public final Service stopAsync() {
 delegate.stopAsync();
 return this;
}

代码示例来源:origin: google/j2objc

/** @since 15.0 */
@CanIgnoreReturnValue
@Override
public final Service stopAsync() {
 delegate.stopAsync();
 return this;
}

代码示例来源:origin: google/j2objc

/** @since 15.0 */
@CanIgnoreReturnValue
@Override
public final Service stopAsync() {
 delegate.stopAsync();
 return this;
}

代码示例来源:origin: apache/incubator-gobblin

/**
  * Close {@link Closeable}s and shutdown {@link Service}s.
  */
 public static void shutdownObject(Object obj, Logger log) {
  if (obj instanceof Service) {
   ((Service) obj).stopAsync();
  } else if (obj instanceof Closeable) {
   try {
    ((Closeable) obj).close();
   } catch (IOException ioe) {
    log.error("Failed to close {}.", obj);
   }
  }
 }
}

代码示例来源:origin: google/j2objc

/**
 * Initiates service {@linkplain Service#stopAsync shutdown} if necessary on all the services
 * being managed.
 *
 * @return this
 */
@CanIgnoreReturnValue
public ServiceManager stopAsync() {
 for (Service service : services) {
  service.stopAsync();
 }
 return this;
}

代码示例来源:origin: wildfly/wildfly

/** @since 15.0 */
@CanIgnoreReturnValue
@Override
public final Service stopAsync() {
 delegate.stopAsync();
 return this;
}

代码示例来源:origin: spotify/helios

private void stopQuietly(final Service service) {
 if (service == null) {
  return;
 }
 try {
  service.stopAsync().awaitTerminated();
 } catch (Exception ignore) {
  // ignored
 }
}

代码示例来源:origin: wildfly/wildfly

/** @since 15.0 */
@CanIgnoreReturnValue
@Override
public final Service stopAsync() {
 delegate.stopAsync();
 return this;
}

代码示例来源:origin: Graylog2/graylog2-server

@Override
public void doStop() {
  if (generatorService == null || !generatorService.isRunning()) {
    log.error("Cannot stop generator transport, it isn't running.");
    return;
  }
  log.debug("Stopping generator transport service {}", generatorService);
  generatorService.stopAsync().awaitTerminated();
  generatorService = null;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Initiates service {@linkplain Service#stopAsync shutdown} if necessary on all the services
 * being managed.
 *
 * @return this
 */
@CanIgnoreReturnValue
public ServiceManager stopAsync() {
 for (Service service : services) {
  service.stopAsync();
 }
 return this;
}

代码示例来源:origin: apache/incubator-gobblin

@Override
 protected void shutDown() throws Exception {
  if (this.specConsumer instanceof Service) {
   ((Service) this.specConsumer).stopAsync().awaitTerminated(this.stopTimeoutSeconds,
     TimeUnit.SECONDS);
  }

  ExecutorsUtils.shutdownExecutorService(this.fetchJobSpecExecutor, Optional.of(LOGGER));
 }
}

代码示例来源:origin: apache/incubator-gobblin

/**
 * Stop the application launcher then any services that were started outside of the application launcher
 */
private void stopAppLauncherAndServices() {
 try {
  this.applicationLauncher.stop();
 } catch (ApplicationException ae) {
  LOGGER.error("Error while stopping Gobblin Cluster application launcher", ae);
 }
 if (this.jobCatalog instanceof Service) {
  ((Service) this.jobCatalog).stopAsync().awaitTerminated();
 }
}

代码示例来源:origin: apache/incubator-gobblin

@Override
 public void failure(Service service) {
  super.failure(service);
  LOG.error(String.format("Service %s has failed.", service.getClass().getSimpleName()), service.failureCause());
  try {
   service.stopAsync();
   ServiceBasedAppLauncher.this.stop();
  } catch (ApplicationException ae) {
   LOG.error("Could not shutdown services gracefully. This may cause the application to hang.");
  }
 }
});

代码示例来源:origin: google/guava

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();
 }
}

代码示例来源:origin: spotify/helios

service.stopAsync();
} catch (Exception e) {
 log.error("Uncaught exception", e);

代码示例来源:origin: torodb/stampede

stampedeService.stopAsync();
 stampedeService.awaitTerminated();
}));

代码示例来源:origin: com.google.guava/guava-jdk5

/**
 * Initiates service {@linkplain Service#stopAsync shutdown} if necessary on all the services
 * being managed. 
 *    
 * @return this
 */
public ServiceManager stopAsync() {
 for (Service service : services) {
  service.stopAsync();
 }
 return this;
}

代码示例来源:origin: org.graylog2/graylog2-server

@Override
public void doStop() {
  if (generatorService == null || !generatorService.isRunning()) {
    log.error("Cannot stop generator transport, it isn't running.");
    return;
  }
  log.debug("Stopping generator transport service {}", generatorService);
  generatorService.stopAsync().awaitTerminated();
  generatorService = null;
}

相关文章