Search in sources :

Example 6 with SafeRunnable

use of org.apache.bookkeeper.util.SafeRunnable in project pulsar by yahoo.

the class ZooKeeperCache method process.

public <T> void process(WatchedEvent event, final CacheUpdater<T> updater) {
    final String path = event.getPath();
    if (path != null) {
        dataCache.synchronous().invalidate(path);
        childrenCache.invalidate(path);
        existsCache.invalidate(path);
        if (executor != null && updater != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Submitting reload cache task to the executor for path: {}, updater: {}", path, updater);
            }
            try {
                executor.submitOrdered(path, new SafeRunnable() {

                    @Override
                    public void safeRun() {
                        updater.reloadCache(path);
                    }
                });
            } catch (RejectedExecutionException e) {
            // Ok, the service is shutting down
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Cannot reload cache for path: {}, updater: {}", path, updater);
            }
        }
    }
}
Also used : SafeRunnable(org.apache.bookkeeper.util.SafeRunnable) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

SafeRunnable (org.apache.bookkeeper.util.SafeRunnable)6 LockingException (com.twitter.distributedlog.exceptions.LockingException)2 ZKSessionLock (com.twitter.distributedlog.lock.ZKSessionLock)2 Promise (com.twitter.util.Promise)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 BoxedUnit (scala.runtime.BoxedUnit)2 DLInterruptedException (com.twitter.distributedlog.exceptions.DLInterruptedException)1 OwnershipAcquireFailedException (com.twitter.distributedlog.exceptions.OwnershipAcquireFailedException)1 UnexpectedException (com.twitter.distributedlog.exceptions.UnexpectedException)1 ZKException (com.twitter.distributedlog.exceptions.ZKException)1 OpStatsListener (com.twitter.distributedlog.stats.OpStatsListener)1 FutureEventListener (com.twitter.util.FutureEventListener)1 Return (com.twitter.util.Return)1 Throw (com.twitter.util.Throw)1 TimeoutException (com.twitter.util.TimeoutException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Pair (org.apache.commons.lang3.tuple.Pair)1