Java Code Examples for org.apache.helix.AccessOption#isThrowExceptionIfNotExist()
The following examples show how to use
org.apache.helix.AccessOption#isThrowExceptionIfNotExist() .
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: ZkCacheBaseDataAccessor.java From helix with Apache License 2.0 | 5 votes |
@Override public T get(String path, Stat stat, int options) { String clientPath = path; String serverPath = prependChroot(clientPath); Cache<T> cache = getCache(serverPath); if (cache != null) { T record = null; ZNode znode = cache.get(serverPath); if (znode != null) { // TODO: shall return a deep copy instead of reference record = ((T) znode.getData()); if (stat != null) { DataTree.copyStat(znode.getStat(), stat); } return record; } else { // if cache miss, fall back to zk and update cache try { cache.lockWrite(); record = _baseAccessor .get(serverPath, stat, options | AccessOption.THROW_EXCEPTION_IFNOTEXIST); cache.update(serverPath, record, stat); } catch (ZkNoNodeException e) { if (AccessOption.isThrowExceptionIfNotExist(options)) { throw e; } } finally { cache.unlockWrite(); } return record; } } // no cache return _baseAccessor.get(serverPath, stat, options); }
Example 2
Source File: ZkBaseDataAccessor.java From helix with Apache License 2.0 | 5 votes |
/** * sync get */ @Override public T get(String path, Stat stat, int options) { T data = null; try { data = (T) _zkClient.readData(path, stat); } catch (ZkNoNodeException e) { if (AccessOption.isThrowExceptionIfNotExist(options)) { throw e; } } return data; }