Search in sources :

Example 6 with WhatHappened

use of com.aws.greengrass.config.WhatHappened in project aws-greengrass-nucleus by aws-greengrass.

the class GreengrassService method waitForDependersToExit.

private void waitForDependersToExit() throws InterruptedException {
    List<GreengrassService> dependers = getHardDependers();
    Subscriber dependerExitWatcher = (WhatHappened what, Topic t) -> {
        synchronized (dependersExitedLock) {
            if (dependersExited(dependers)) {
                dependersExitedLock.notifyAll();
            }
        }
    };
    // subscribing to depender state changes
    dependers.forEach(dependerGreengrassService -> dependerGreengrassService.addStateSubscriber(dependerExitWatcher));
    synchronized (dependersExitedLock) {
        while (!dependersExited(dependers)) {
            logger.atDebug("service-waiting-for-depender-to-finish").log();
            dependersExitedLock.wait();
        }
    }
    // removing state change watchers
    dependers.forEach(dependerGreengrassService -> dependerGreengrassService.removeStateSubscriber(dependerExitWatcher));
}
Also used : WhatHappened(com.aws.greengrass.config.WhatHappened) Subscriber(com.aws.greengrass.config.Subscriber) Topic(com.aws.greengrass.config.Topic)

Aggregations

Topic (com.aws.greengrass.config.Topic)6 WhatHappened (com.aws.greengrass.config.WhatHappened)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 State (com.aws.greengrass.dependency.State)4 Test (org.junit.jupiter.api.Test)4 GenericExternalService (com.aws.greengrass.lifecyclemanager.GenericExternalService)3 Subscriber (com.aws.greengrass.config.Subscriber)2 DeploymentResult (com.aws.greengrass.deployment.model.DeploymentResult)2 HashMap (java.util.HashMap)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 GreengrassService (com.aws.greengrass.lifecyclemanager.GreengrassService)1 ServiceLoadException (com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1