com.google.common.util.concurrent.ServiceManager

Here are the examples of the java api class com.google.common.util.concurrent.ServiceManager taken from open source projects.

1. SchedulerServicesModule#provideSchedulerActiveServiceManager()

Project: aurora
Source File: SchedulerServicesModule.java
View license
@Provides
@Singleton
@SchedulerActive
ServiceManagerIface provideSchedulerActiveServiceManager(@SchedulerActive Set<Service> services, LifecycleShutdownListener listener) {
    ServiceManager manager = new ServiceManager(services);
    manager.addListener(listener);
    return GuavaUtils.serviceManager(manager);
}

2. SchedulerServicesModule#provideAppStartupServiceManager()

Project: aurora
Source File: SchedulerServicesModule.java
View license
@Provides
@Singleton
@AppStartup
ServiceManagerIface provideAppStartupServiceManager(@AppStartup Set<Service> services, LifecycleShutdownListener listener) {
    ServiceManager manager = new ServiceManager(services);
    manager.addListener(listener);
    return GuavaUtils.serviceManager(manager);
}

3. ServerBootstrap#startCommand()

View license
@Override
protected void startCommand() {
    final AuditLogger auditLogger = injector.getInstance(AuditLogger.class);
    final Map<String, Object> auditLogContext = ImmutableMap.of("version", version, "java", Tools.getSystemInformation());
    auditLogger.success("<system>", "initiated", "startup", auditLogContext);
    final OS os = OS.getOs();
    LOG.info("Graylog {} {} starting up", commandName, version);
    LOG.info("JRE: {}", Tools.getSystemInformation());
    LOG.info("Deployment: {}", configuration.getInstallationSource());
    LOG.info("OS: {}", os.getPlatformName());
    LOG.info("Arch: {}", os.getArch());
    final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
    serverStatus.initialize();
    startNodeRegistration(injector);
    final ActivityWriter activityWriter;
    final ServiceManager serviceManager;
    try {
        activityWriter = injector.getInstance(ActivityWriter.class);
        serviceManager = injector.getInstance(ServiceManager.class);
    } catch (ProvisionException e) {
        LOG.error("Guice error", e);
        annotateProvisionException(e);
        auditLogger.failure("<system>", "initiated", "startup", auditLogContext);
        System.exit(-1);
        return;
    } catch (Exception e) {
        LOG.error("Unexpected exception", e);
        auditLogger.failure("<system>", "initiated", "startup", auditLogContext);
        System.exit(-1);
        return;
    }
    Runtime.getRuntime().addShutdownHook(new Thread(injector.getInstance(shutdownHook())));
    // propagate default size to input plugins
    MessageInput.setDefaultRecvBufferSize(configuration.getUdpRecvBufferSizes());
    // Start services.
    final ServiceManagerListener serviceManagerListener = injector.getInstance(ServiceManagerListener.class);
    serviceManager.addListener(serviceManagerListener);
    try {
        serviceManager.startAsync().awaitHealthy();
    } catch (Exception e) {
        try {
            serviceManager.stopAsync().awaitStopped(configuration.getShutdownTimeout(), TimeUnit.MILLISECONDS);
        } catch (TimeoutException timeoutException) {
            LOG.error("Unable to shutdown properly on time. {}", serviceManager.servicesByState());
        }
        LOG.error("Graylog startup failed. Exiting. Exception was:", e);
        auditLogger.failure("<system>", "initiated", "startup", auditLogContext);
        System.exit(-1);
    }
    LOG.info("Services started, startup times in ms: {}", serviceManager.startupTimes());
    activityWriter.write(new Activity("Started up.", Main.class));
    LOG.info("Graylog " + commandName + " up and running.");
    auditLogger.success("<system>", "completed", "startup", auditLogContext);
    // Block forever.
    try {
        Thread.currentThread().join();
    } catch (InterruptedException e) {
        return;
    }
}

4. StandardRepository#doStart()

Project: es4j
Source File: StandardRepository.java
View license
@Override
@SuppressWarnings("unchecked")
protected void doStart() {
    if (journal == null) {
        notifyFailed(new IllegalStateException("journal == null"));
    }
    if (physicalTimeProvider == null) {
        notifyFailed(new IllegalStateException("physicalTimeProvider == null"));
    }
    if (indexEngine == null) {
        notifyFailed(new IllegalStateException("indexEngine == null"));
    }
    if (lockProvider == null) {
        notifyFailed(new IllegalStateException("lockProvider == null"));
    }
    addEventSetProvider(() -> {
        List<Class<? extends Event>> classes = Arrays.asList(CommandTerminatedExceptionally.class, EventCausalityEstablished.class, EntityLayoutIntroduced.class);
        return new HashSet<>(classes);
    });
    addCommandSetProvider(() -> {
        List<Class<? extends Command>> classes = Arrays.asList(IntroduceEntityLayouts.class);
        return new HashSet<>(classes);
    });
    journal.setRepository(this);
    indexEngine.setJournal(journal);
    indexEngine.setRepository(this);
    services = new ServiceManager(Arrays.asList(journal, indexEngine, lockProvider, physicalTimeProvider).stream().filter( s -> !s.isRunning()).collect(Collectors.toSet()));
    services.startAsync().awaitHealthy();
    initialization.forEach(Runnable::run);
    initialization.clear();
    commandConsumer = new DisruptorCommandConsumer(commands, physicalTimeProvider, this, journal, indexEngine, lockProvider);
    commandConsumer.startAsync().awaitRunning();
    journal.onCommandsAdded(commands);
    journal.onEventsAdded(events);
    publish(new IntroduceEntityLayouts(Iterables.concat(commands, events))).join();
    notifyStarted();
}

5. NTPServerTimeProviderTest#setup()

Project: es4j
Source File: NTPServerTimeProviderTest.java
View license
@BeforeClass
public void setup() throws UnknownHostException, ExecutionException, InterruptedException {
    // use localhost to avoid delays and usage caps
    provider = new NTPServerTimeProvider(new String[] { "localhost" });
    serviceManager = new ServiceManager(Arrays.asList(provider));
    serviceManager.startAsync().awaitHealthy();
}