Java Code Examples for org.apache.curator.framework.api.GetDataBuilder#forPath()
The following examples show how to use
org.apache.curator.framework.api.GetDataBuilder#forPath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeService.java From config-toolkit with Apache License 2.0 | 6 votes |
@Override public List<PropertyItem> findProperties(String node) { LOGGER.debug("Find properties in node: [{}]", node); List<PropertyItem> properties = Lists.newArrayList(); try { Stat stat = client.checkExists().forPath(node); if (stat != null) { GetChildrenBuilder childrenBuilder = client.getChildren(); List<String> children = childrenBuilder.forPath(node); GetDataBuilder dataBuilder = client.getData(); if (children != null) { for (String child : children) { String propPath = ZKPaths.makePath(node, child); PropertyItem item = new PropertyItem(child, new String(dataBuilder.forPath(propPath), Charsets.UTF_8)); properties.add(item); } } } } catch (Exception e) { LOGGER.error(e.getMessage(), e); } return properties; }
Example 2
Source File: ZkSubscriptionImpl.java From nakadi with MIT License | 5 votes |
@Override protected byte[] query(final boolean setListener) throws NakadiRuntimeException { final GetDataBuilder builder = curatorFramework.getData(); if (setListener) { builder.usingWatcher(this); } try { return builder.forPath(key); } catch (final Exception ex) { throw new NakadiRuntimeException(ex); } }
Example 3
Source File: CuratorManager.java From Singularity with Apache License 2.0 | 4 votes |
private <T> Optional<T> getData( String path, Optional<Stat> stat, Transcoder<T> transcoder, Optional<ZkCache<T>> zkCache, Optional<Boolean> shouldCheckExists ) { if (!stat.isPresent() && zkCache.isPresent()) { Optional<T> cachedValue = zkCache.get().get(path); if ( cachedValue.isPresent() && ( !shouldCheckExists.isPresent() || (shouldCheckExists.get().booleanValue() && checkExists(path).isPresent()) ) ) { return cachedValue; } } final long start = System.currentTimeMillis(); int bytes = 0; try { GetDataBuilder bldr = curator.getData(); if (stat.isPresent()) { bldr.storingStatIn(stat.get()); } byte[] data = bldr.forPath(path); if (data == null || data.length == 0) { LOG.trace("Empty data found for path {}", path); return Optional.empty(); } bytes = data.length; final T object = transcoder.fromBytes(data); if (zkCache.isPresent()) { zkCache.get().set(path, object); } return Optional.of(object); } catch (NoNodeException nne) { LOG.trace("No node found for path {}", path); return Optional.empty(); } catch (Throwable t) { throw new RuntimeException(t); } finally { log(OperationType.GET, Optional.empty(), Optional.<Integer>of(bytes), start, path); } }