Search in sources :

Example 1 with InvalidSubscriberException

use of com.netflix.eventbus.spi.InvalidSubscriberException in project eureka by Netflix.

the class DiscoveryClientResource method awaitCacheUpdate.

public boolean awaitCacheUpdate(long timeout, TimeUnit unit) throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    Object eventListener = new Object() {

        @Subscribe
        public void consume(CacheRefreshedEvent event) {
            latch.countDown();
        }
    };
    try {
        getEventBus().registerSubscriber(eventListener);
    } catch (InvalidSubscriberException e) {
        throw new IllegalStateException("Unexpected error during subscriber registration", e);
    }
    try {
        return latch.await(timeout, unit);
    } finally {
        getEventBus().unregisterSubscriber(eventListener);
    }
}
Also used : InvalidSubscriberException(com.netflix.eventbus.spi.InvalidSubscriberException) CountDownLatch(java.util.concurrent.CountDownLatch) CacheRefreshedEvent(com.netflix.discovery.CacheRefreshedEvent)

Aggregations

CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)1 InvalidSubscriberException (com.netflix.eventbus.spi.InvalidSubscriberException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1