Example usage for com.google.common.util.concurrent Service state

List of usage examples for com.google.common.util.concurrent Service state

Introduction

In this page you can find the example usage for com.google.common.util.concurrent Service state.

Prototype

State state();

Source Link

Document

Returns the lifecycle state of the service.

Usage

From source file:co.cask.tigon.internal.app.runtime.distributed.AbstractTwillProgramController.java

private TwillController.Listener createTwillListener() {
    return new ServiceListenerAdapter() {

        @Override//from www .  ja v a  2  s .co m
        public void running() {
            LOG.info("Twill program running: {} {}", programName, twillController.getRunId());
            started();
        }

        @Override
        public void terminated(Service.State from) {
            LOG.info("Twill program terminated: {} {}", programName, twillController.getRunId());
            stop();
        }

        @Override
        public void failed(Service.State from, Throwable failure) {
            LOG.info("Twill program failed: {} {}", programName, twillController.getRunId());
            error(failure);
        }
    };
}

From source file:org.graylog2.utilities.LoggingServiceListener.java

@Override
public void stopping(Service.State from) {
    logger.info("{} {} STOPPING, was {}", serviceName, id, from);
}

From source file:com.arpnetworking.clusteraggregator.configuration.ConfigurableActorProxy.java

/**
 * {@inheritDoc}/*from   w  w  w  . j  ava 2s  .c  om*/
 */
@Override
public void onReceive(final Object message) throws Exception {
    if (message instanceof ApplyConfiguration) {
        @SuppressWarnings("unchecked")
        final ApplyConfiguration<T> applyConfiguration = (ApplyConfiguration<T>) message;
        applyConfiguration(applyConfiguration);
    } else if (message instanceof SwapActor) {
        swapActor();
    } else if (message instanceof Terminated) {
        actorTerminated((Terminated) message);
    } else if (message instanceof SubscribeToNotifications) {
        _observers.add(sender());
    } else {
        if (_state.equals(Service.State.RUNNING)) {
            _currentChild.get().forward(message, context());
        } else {
            if (_messageBuffer.size() >= MAX_BUFFERED_MESSAGES) {
                final BufferedMessage dropped = _messageBuffer.remove();
                LOGGER.error().setMessage("Message buffer full, dropping oldest message")
                        .addData("dropped", dropped.getMessage()).addContext("actor", self()).log();
            }
            // TODO(barp): record the buffer size as a metric [MAI-472]
            _messageBuffer.add(new BufferedMessage(sender(), message));
        }
    }
}

From source file:co.cask.cdap.internal.app.runtime.workflow.WorkflowProgramController.java

private void startListen(Service service) {
    // Forward state changes from the given service to this controller.
    service.addListener(new ServiceListenerAdapter() {
        @Override/*from   w  w w .  j a  va  2 s.  com*/
        public void running() {
            InetSocketAddress endpoint = driver.getServiceEndpoint();
            cancelAnnounce = serviceAnnouncer.announce(serviceName, endpoint.getPort());
            LOG.info("Workflow service {} announced at {}", serviceName, endpoint);
            started();
        }

        @Override
        public void terminated(Service.State from) {
            LOG.info("Workflow service terminated from {}. Un-registering service {}.", from, serviceName);
            cancelAnnounce.cancel();
            LOG.info("Service {} unregistered.", serviceName);
            if (getState() != State.STOPPING) {
                // service completed itself.
                complete();
            } else {
                // service was terminated
                stop();
            }
        }

        @Override
        public void failed(Service.State from, Throwable failure) {
            LOG.info("Workflow service failed from {}. Un-registering service {}.", from, serviceName, failure);
            cancelAnnounce.cancel();
            LOG.info("Service {} unregistered.", serviceName);
            error(failure);
        }
    }, Threads.SAME_THREAD_EXECUTOR);
}

From source file:com.continuuity.weave.common.Services.java

/**
 * Returns a {@link Runnable} that can be used as a {@link ListenableFuture} listener to trigger
 * further service action or completing the result future. Used by
 * {@link #doChain(boolean, com.google.common.util.concurrent.Service, com.google.common.util.concurrent.Service...)}
 */// www  .j a  v a  2 s  . com
private static Runnable createChainListener(final ListenableFuture<Service.State> future,
        final Service[] services, final AtomicInteger idx, final List<ListenableFuture<Service.State>> result,
        final SettableFuture<List<ListenableFuture<Service.State>>> resultFuture, final boolean doStart) {
    return new Runnable() {

        @Override
        public void run() {
            result.add(future);
            int nextIdx = idx.getAndIncrement();
            if (nextIdx == services.length) {
                resultFuture.set(result);
                return;
            }
            ListenableFuture<Service.State> actionFuture = doStart ? services[nextIdx].start()
                    : services[nextIdx].stop();
            actionFuture.addListener(
                    createChainListener(actionFuture, services, idx, result, resultFuture, doStart),
                    Threads.SAME_THREAD_EXECUTOR);
        }
    };
}

From source file:com.continuuity.weave.internal.ListenerExecutor.java

@Override
public void terminated(final Service.State from) {
    if (hasCalled(Service.State.TERMINATED)) {
        return;//from  w  w  w  . j  a va  2  s. c  om
    }
    executor.execute(new Runnable() {
        @Override
        public void run() {
            try {
                delegate.terminated(from);
            } catch (Throwable t) {
                LOG.warn("Exception thrown from listener", t);
            }
        }
    });
}

From source file:org.graylog2.utilities.LoggingServiceListener.java

@Override
public void terminated(Service.State from) {
    logger.info("{} {} TERMINATED, was {}", serviceName, id, from);
}

From source file:org.apache.usergrid.rest.management.ImportResourceIT.java

@BeforeClass
public static void setup() throws Exception {

    bucketPrefix = System.getProperty("bucketName");

    // start the scheduler after we're all set up
    JobSchedulerService jobScheduler = ConcurrentProcessSingleton.getInstance().getSpringResource()
            .getBean(JobSchedulerService.class);

    if (jobScheduler.state() != Service.State.RUNNING) {
        jobScheduler.startAsync();//  w w w  .j  a va2  s . co m
        jobScheduler.awaitRunning();
    }

}

From source file:org.graylog2.utilities.LoggingServiceListener.java

@Override
public void failed(Service.State from, Throwable failure) {
    logger.info("{} {} FAILED, was {}: {}", serviceName, id, from, ExceptionUtils.getRootCauseMessage(failure));
}

From source file:GRSX.WalletSettingsController.java

public void restoreClicked(ActionEvent event) {
    if (Main.groestlcoin.wallet().getBalance().value > 0) {
        informationalAlert("Vortex Notification",
                "You must empty this wallet out before attempting to restore an older one, as mixing wallets "
                        + "together can lead to invalidated backups.");
        return;//from w  ww .  j  av  a2  s  .com
    }

    overlayUI.done();
    Main.instance.controller.restoreFromSeedAnimation();

    DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(wordsArea.getText()), null, "",
            0);
    Main.groestlcoin.addListener(new Service.Listener() {
        @Override
        public void terminated(Service.State from) {
            Main.instance.setupWalletKit(seed);
            Main.groestlcoin.startAsync();
        }
    }, Platform::runLater);

    Main.groestlcoin.stopAsync();
}