本文整理了Java中com.addthis.hydra.job.store.ZookeeperDataStore
类的一些代码示例,展示了ZookeeperDataStore
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZookeeperDataStore
类的具体详情如下:
包路径:com.addthis.hydra.job.store.ZookeeperDataStore
类名称:ZookeeperDataStore
[英]A class for persisting key-value data within zookeeper.
[中]用于在zookeeper中持久化键值数据的类。
代码示例来源:origin: addthis/hydra
@Override
/**
* Get the contents of a certain child beneath a parent node. As with putAsChild, this is simple in zookeeper but
* needs to be handled specially in PriamDataStore.
*/
public String getChild(String parent, String childId) throws Exception {
return get(parent + "/" + childId);
}
代码示例来源:origin: addthis/hydra
@Override
public Map<String, String> getAllChildren(String path) {
Map<String, String> rv = new HashMap<>();
List<String> children = getChildrenNames(path);
if (children != null) {
for (String child : children) {
try {
rv.put(child, getChild(path, child));
} catch (Exception ex) {
log.warn("Failed to fetch child " + child + " of " + path + ": " + ex, ex);
}
}
}
return rv;
}
代码示例来源:origin: addthis/hydra
/**
* Write some children to a specified location. Make sure their respective data is held intact, and that the list
* of children updates correctly after nodes are added or deleted.
*/
@Test public void crudChildren() throws Exception {
String savePath = "/other/path";
try {
String c1 = "child1";
String c2 = "child2";
spawnDataStore.delete(savePath);
spawnDataStore.putAsChild(savePath, c1, "data1");
spawnDataStore.putAsChild(savePath, c1, "data1_updated");
spawnDataStore.putAsChild(savePath, c2, "data2");
Set<String> bothChildren = Sets.newHashSet(spawnDataStore.getChildrenNames(savePath));
assertEquals("should get correct children", bothChildren, Sets.newHashSet(c1, c2));
assertEquals("should get updated value for c1", "data1_updated", spawnDataStore.getChild(savePath, c1));
spawnDataStore.deleteChild(savePath, c2);
Set<String> oneChild = Sets.newHashSet(spawnDataStore.getChildrenNames(savePath));
assertEquals("should get new correct children", oneChild, Sets.newHashSet(c1));
assertEquals("c1 should be intact", "data1_updated", spawnDataStore.getChild(savePath, c1));
spawnDataStore.delete(savePath);
assertNull("should get no children", spawnDataStore.getChildrenNames(savePath));
} finally {
spawnDataStore.delete(savePath);
}
}
}
代码示例来源:origin: addthis/hydra
@Test public void simplePutGet() throws Exception {
String savePath = "/some/path";
try {
spawnDataStore.delete(savePath);
spawnDataStore.put(savePath, "someval");
assertEquals("should get inserted value", "someval", spawnDataStore.get(savePath));
spawnDataStore.delete(savePath);
assertNull("should get null value after deletion", spawnDataStore.get(savePath));
} finally {
spawnDataStore.delete(savePath);
}
}
代码示例来源:origin: addthis/hydra
public static SpawnDataStore makeSpawnDataStore(DataStoreType type) throws Exception {
Properties properties = new Properties();
if (sqlUser != null) {
properties.put("user", sqlUser);
properties.put("password", sqlPassword);
}
switch (type) {
case FS: return new FilesystemDataStore(new File(fsDataStoreFileRoot));
case ZK: return new ZookeeperDataStore(null);
case MYSQL:
return new MysqlDataStore("jdbc:mysql:thin://" + sqlHostName + ":" + sqlPort + "/", sqlDbName, sqlTableName, properties);
case POSTGRES:
return new PostgresDataStore("jdbc:postgres://" + sqlHostName + ":" + sqlPort + "/", sqlDbName, sqlTableName, properties);
default: throw new IllegalArgumentException("Unexpected DataStoreType " + type);
}
}
代码示例来源:origin: addthis/hydra
@Before
public void createSpawnDataStore() {
spawnDataStore = new ZookeeperDataStore(zkClient);
}
代码示例来源:origin: addthis/hydra
@Before
public void setUp() throws Exception {
spawnDataStore = new ZookeeperDataStore(zkClient);
jcm = setUpSampleState();
qcw = new QueryConfigWatcher(spawnDataStore);
}
代码示例来源:origin: addthis/hydra
@Override
public Map<String, String> get(String[] paths) {
Map<String, String> rv = new HashMap<>();
for (String path : paths) {
String val = get(path);
if (val != null) {
rv.put(path, val);
}
}
return rv;
}
内容来源于网络,如有侵权,请联系作者删除!