blob: 819cd23502379496f1288157d9f0c7670a2592c3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.curator;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.ChildData;
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutorService;
/**
* A directory cache backed by a curator path children cache.
*
* @author bratseth
*/
class PathChildrenCacheWrapper implements Curator.DirectoryCache {
private final PathChildrenCache wrapped;
public PathChildrenCacheWrapper(CuratorFramework curatorFramework, String path, boolean cacheData, boolean dataIsCompressed, ExecutorService executorService) {
wrapped = new PathChildrenCache(curatorFramework, path, cacheData, dataIsCompressed, executorService);
}
@Override
public void start() {
try {
wrapped.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);
} catch (Exception e) {
throw new IllegalStateException("Could not start the Curator cache", e);
}
}
@Override
public void addListener(PathChildrenCacheListener listener) {
wrapped.getListenable().addListener(listener);
}
@Override
public List<ChildData> getCurrentData() {
return wrapped.getCurrentData();
}
@Override
public void close() {
try {
wrapped.close();
} catch (IOException e) {
throw new RuntimeException("Exception closing curator cache", e);
}
}
}
|