本文整理汇总了Java中mousio.etcd4j.responses.EtcdKeysResponse.EtcdNode方法的典型用法代码示例。如果您正苦于以下问题:Java EtcdKeysResponse.EtcdNode方法的具体用法?Java EtcdKeysResponse.EtcdNode怎么用?Java EtcdKeysResponse.EtcdNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mousio.etcd4j.responses.EtcdKeysResponse
的用法示例。
在下文中一共展示了EtcdKeysResponse.EtcdNode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetAll
import mousio.etcd4j.responses.EtcdKeysResponse; //导入方法依赖的package包/类
@Test
public void testGetAll() throws IOException, EtcdException, EtcdAuthenticationException, TimeoutException {
EtcdKeysResponse.EtcdNode root;
List<EtcdKeysResponse.EtcdNode> nodes;
EtcdClient client = new EtcdClient();
root = client.getAll().timeout(30, TimeUnit.SECONDS).send().get().getNode();
nodes = root.getNodes();
LOGGER.info("Nodes (1) {}", nodes);
assertNotNull(nodes);
assertTrue(root.isDir());
client.put("etcd4j_testGetAll_1/foo1", "bar").prevExist(false).send().get();
client.put("etcd4j_testGetAll_2/foo1", "bar").prevExist(false).send().get();
root = client.getAll().timeout(30, TimeUnit.SECONDS).send().get().getNode();
nodes = root.getNodes();
LOGGER.info("Nodes (2) {}", nodes);
assertNotNull(nodes);
assertEquals(2, nodes.size());
}
示例2: testGetHugeDir
import mousio.etcd4j.responses.EtcdKeysResponse; //导入方法依赖的package包/类
@Test
public void testGetHugeDir() throws IOException, EtcdException, EtcdAuthenticationException, TimeoutException {
EtcdNettyConfig config = new EtcdNettyConfig();
config.setMaxFrameSize(1024 * 1024); // Desired max size
EtcdNettyClient nettyClient = new EtcdNettyClient(config, URI.create("http://localhost:4001"));
EtcdClient client = new EtcdClient(nettyClient);
for (int i = 0; i < 2000; i++) {
client.put("/etcd4j_test/huge-dir/node-" + i, "bar").send().get();
}
List<EtcdKeysResponse.EtcdNode> nodes;
nodes = client.getDir("/etcd4j_test/huge-dir/").send().get().getNode().getNodes();
assertNotNull(nodes);
assertEquals(2000, nodes.size());
}
示例3: readNode
import mousio.etcd4j.responses.EtcdKeysResponse; //导入方法依赖的package包/类
private EtcdKeysResponse.EtcdNode readNode(
final String path,
final Function<String, EtcdKeyGetRequest> executor) {
return Fn.getJvm(null, () -> {
final EtcdKeyGetRequest request = executor.apply(path);
/** Timeout **/
if (-1 != this.timeout) {
request.timeout(this.timeout, TimeUnit.SECONDS);
}
final EtcdResponsePromise<EtcdKeysResponse> promise = request.send();
final EtcdKeysResponse response = promise.get();
return response.getNode();
}, path);
}
示例4: toNode
import mousio.etcd4j.responses.EtcdKeysResponse; //导入方法依赖的package包/类
private KvNode toNode(EtcdKeysResponse resp) {
EtcdKeysResponse.EtcdNode node = resp.node;
if(node.dir) {
// we must not return dir value
return KvNode.dir(node.modifiedIndex);
}
return KvNode.leaf(node.modifiedIndex, node.value);
}
示例5: cleanup
import mousio.etcd4j.responses.EtcdKeysResponse; //导入方法依赖的package包/类
protected void cleanup(EtcdClient etcd) {
try {
for (EtcdKeysResponse.EtcdNode node: etcd.getAll().send().get().getNode().getNodes()) {
if (node.isDir()) {
etcd.deleteDir(node.key).recursive().send().get();
} else {
etcd.delete(node.key).send().get();
}
}
} catch (Exception e) {}
}
示例6: cleanup
import mousio.etcd4j.responses.EtcdKeysResponse; //导入方法依赖的package包/类
protected void cleanup() {
try {
for (EtcdKeysResponse.EtcdNode node: etcd.getAll().send().get().getNode().getNodes()) {
if (node.isDir()) {
LOGGER.info("Delete dir {}", node.key);
etcd.deleteDir(node.key).recursive().send().get();
} else {
LOGGER.info("Delete entry {}", node.key);
etcd.delete(node.key).send().get();
}
}
} catch (Exception e) {
}
}
示例7: cleanup
import mousio.etcd4j.responses.EtcdKeysResponse; //导入方法依赖的package包/类
protected void cleanup() {
try {
for (EtcdKeysResponse.EtcdNode node: etcd.getAll().send().get().getNode().getNodes()) {
if (node.isDir()) {
LOGGER.info("Delete dir {}", node.key);
etcd.deleteDir(node.key).recursive().send().get();
} else {
LOGGER.info("Delete entry {}", node.key);
etcd.delete(node.key).send().get();
}
}
} catch (Exception e) {
}
}
示例8: read
import mousio.etcd4j.responses.EtcdKeysResponse; //导入方法依赖的package包/类
public String read(final String path) {
final EtcdKeysResponse.EtcdNode node = readNode(path, this.client::get);
return null == node ? null : node.getValue();
}
示例9: run
import mousio.etcd4j.responses.EtcdKeysResponse; //导入方法依赖的package包/类
/**
* Gets the etcd state and then waits for changes in etcd before updating the tree.
*/
@Override
public void run() {
// Run once to get currentstate
DiscoveryStoredNode storedRoot;
EtcdKeysResponse.EtcdNode etcdNode;
Tuple<EtcdKeysResponse.EtcdNode, Long> discovererData;
Logger.getLogger(EtcdChangeHandler.class).info("Starting EtcdChangeHandler...");
discovererData = discoverer.getFromRoot(null, false);
if(discovererData != null) {
etcdNode = discovererData.getT1();
if(etcdNode != null) {
nextModifiedIndex = discovererData.getT2();
storedRoot = new DiscoveryStoredEtcdNode(etcdNode);
synchronized (this) {
cachedRoot.updateTree(storedRoot);
}
}
}
Logger.getLogger(EtcdChangeHandler.class).info("Started EtcdChangeHandler!");
while(!this.isInterrupted()) {
discovererData = discoverer.getFromRoot(nextModifiedIndex, true);
if(discovererData != null) {
etcdNode = discovererData.getT1();
if(etcdNode != null) {
storedRoot = new DiscoveryStoredEtcdNode(etcdNode);
nextModifiedIndex = discovererData.getT2();
synchronized (this) {
cachedRoot.updateTree(storedRoot);
}
}
}
}
Logger.getLogger(EtcdChangeHandler.class).info("Stopped EtcdChangeHandler!");
}
示例10: DiscoveryStoredEtcdNode
import mousio.etcd4j.responses.EtcdKeysResponse; //导入方法依赖的package包/类
/**
* Instantiates a new node using the given etcd node.
* @param etcdNode The etcd node.
*/
public DiscoveryStoredEtcdNode(EtcdKeysResponse.EtcdNode etcdNode) {
this.etcdNode = etcdNode;
}