@ThriftMethod
public PathChildrenCacheProjection startPathChildrenCache(final CuratorProjection projection, final String path, boolean cacheData, boolean dataIsCompressed, PathChildrenCacheStartMode startMode) throws RpcException
{
try
{
final CuratorEntry entry = CuratorEntry.mustGetEntry(connectionManager, projection);
final PathChildrenCache cache = new PathChildrenCache(entry.getClient(), path, cacheData, dataIsCompressed, ThreadUtils.newThreadFactory("PathChildrenCacheResource"));
cache.start(PathChildrenCache.StartMode.valueOf(startMode.name()));
Closer closer = new Closer()
{
@Override
public void close()
{
try
{
cache.close();
}
catch ( IOException e )
{
log.error("Could not close left-over PathChildrenCache for path: " + path, e);
}
}
};
String id = entry.addThing(cache, closer);
PathChildrenCacheListener listener = new PathChildrenCacheListener()
{
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws RpcException
{
entry.addEvent(new RpcCuratorEvent(new RpcPathChildrenCacheEvent(path, event)));
}
};
cache.getListenable().addListener(listener);
return new PathChildrenCacheProjection(id);