本文整理汇总了Java中mousio.etcd4j.responses.EtcdKeysResponse类的典型用法代码示例。如果您正苦于以下问题:Java EtcdKeysResponse类的具体用法?Java EtcdKeysResponse怎么用?Java EtcdKeysResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EtcdKeysResponse类属于mousio.etcd4j.responses包,在下文中一共展示了EtcdKeysResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: readDir
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
public ConcurrentMap<String, String> readDir(
final String path,
final boolean shiftted) {
return Fn.getJvm(new ConcurrentHashMap<>(), () -> {
final EtcdKeysResponse.EtcdNode node = readNode(path, this.client::getDir);
return Fn.getJvm(new ConcurrentHashMap<>(), () -> {
final ConcurrentMap<String, String> result = new ConcurrentHashMap<>();
/** Nodes **/
final List<EtcdKeysResponse.EtcdNode> nodes = node.getNodes();
for (final EtcdKeysResponse.EtcdNode nodeItem : nodes) {
String key = nodeItem.getKey();
if (shiftted) {
key = key.substring(key.lastIndexOf(Strings.SLASH) + Values.ONE);
}
result.put(key, nodeItem.getValue());
}
return result;
}, node);
}, path);
}
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:21,代码来源:EtcdData.java
示例2: write
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
public <T> JsonObject write(final String path, final T data, final int ttl) {
return Fn.getJvm(null, () -> {
final EtcdKeyPutRequest request = this.client.put(path,
Fn.getSemi(data instanceof JsonObject || data instanceof JsonArray,
LOGGER,
() -> Instance.invoke(data, "encode"),
data::toString));
if (Values.ZERO != ttl) {
request.ttl(ttl);
}
/** Timeout **/
if (-1 != this.timeout) {
request.timeout(this.timeout, TimeUnit.SECONDS);
}
final EtcdResponsePromise<EtcdKeysResponse> promise = request.send();
final EtcdKeysResponse response = promise.get();
return Jackson.serializeJson(response.getNode());
}, path, data);
}
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:20,代码来源:EtcdData.java
示例3: handleEtcdWatchErrors
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
/**
* Handles watch issues with watching. See Etcd docs:
*
* @see <a href="https://github.com/coreos/etcd/blob/master/Documentation/api.md">Docs</a>
*/
private EtcdKeysResponse handleEtcdWatchErrors(EtcdException exception) {
//
if (exception.errorCode == ETCD_EVENT_INDEX_CLEARED_CODE) {
// If our watching failed due to index, re-read everything because we might have missed
// something. The lastKnownFlagzModificationIndex will be reset in fetchAllFlagzNodes.
initialSetAllFlagz();
return null;
} else if (exception.errorCode == ETCD_WATCHER_CLEARED_CODE) {
// This means that etcd is recovering from a problem.
try {
Thread.sleep(reelectionBackoffMs.get());
} catch (InterruptedException e1) {
// ignore
}
return null;
} else {
throw new EtcdFlagFieldUpdaterException.EtcdFetchingFailed(exception);
}
}
开发者ID:mwitkow,项目名称:java-flagz,代码行数:25,代码来源:EtcdFlagFieldUpdater.java
示例4: tryTakeLeadership
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
private boolean tryTakeLeadership() throws Exception {
boolean result = false;
try {
EtcdKeysResponse response = getClient()
.put(servicePath, serviceName)
.prevExist(false)
.ttl(ttl)
.send()
.get();
result = ObjectHelper.equal(serviceName, response.node.value);
setIndex(response);
} catch (EtcdException e) {
if (!e.isErrorCode(EtcdErrorCode.NodeExist)) {
throw e;
}
}
return result;
}
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:EtcdRoutePolicy.java
示例5: getAsJson
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
/**
* Gets the content of the key recursively as a JsonObject
* @param path root path (i.e. /path1/path2)
* @param etcdClient EtcdClient
* @return JsonNode
*/
public static JsonNode getAsJson(String path, EtcdClient etcdClient)
throws IOException, EtcdAuthenticationException, TimeoutException, EtcdException {
EtcdKeyGetRequest etcdKeyGetRequest = etcdClient.get(path).recursive();
EtcdKeysResponse dataTree = etcdKeyGetRequest.send().get();
ObjectNode jNode = JsonNodeFactory.instance.objectNode();
if (dataTree.getNode().getNodes().isEmpty()) {
iterateOverNodes(jNode, dataTree.getNode());
} else {
for (EtcdNode node : dataTree.getNode().getNodes()) {
iterateOverNodes(jNode, node);
}
}
return dotNotationToStandardJson(jNode.at(path));
}
开发者ID:jurmous,项目名称:etcd4j,代码行数:25,代码来源:EtcdUtil.java
示例6: testSuccessWithoutRetrying
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
@Test
public void testSuccessWithoutRetrying() throws Exception {
whenHttp(server)
.match(get("/v2/keys/foo"))
.then(SUCCESS);
try (EtcdClient etcd = new EtcdClient(serverURI)) {
EtcdResponsePromise<EtcdKeysResponse> promise = etcd.get("foo")
.setRetryPolicy(new RetryNTimes(1, 10))
.send();
EtcdKeysResponse resp = promise.get();
assertThat(resp.node.value).isEqualTo("bar");
assertThat(promise.getException()).isNull();
}
verifyHttp(server).once(
method(Method.GET),
uri("/v2/keys/foo")
);
}
开发者ID:jurmous,项目名称:etcd4j,代码行数:26,代码来源:EtcdClientRetryPolicyTest.java
示例7: testSuccessAfterRetrying
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
@Test
public void testSuccessAfterRetrying() throws Exception {
whenHttp(server)
.match(get("/v2/keys/foo"))
.then(sequence(FAILURE, SUCCESS));
try (EtcdClient etcd = new EtcdClient(serverURI)) {
EtcdResponsePromise<EtcdKeysResponse> promise = etcd.get("foo")
.setRetryPolicy(new RetryNTimes(1, 10))
.send();
EtcdKeysResponse resp = promise.get();
assertThat(resp.node.value).isEqualTo("bar");
assertThat(promise.getException()).isNull();
}
verifyHttp(server).times(2,
method(Method.GET),
uri("/v2/keys/foo")
);
}
开发者ID:jurmous,项目名称:etcd4j,代码行数:26,代码来源:EtcdClientRetryPolicyTest.java
示例8: testDir
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
/**
* Directory tests
*/
@Test
public void testDir() throws IOException, EtcdException, EtcdAuthenticationException, TimeoutException {
EtcdKeysResponse r = etcd.putDir("etcd4j_test/foo_dir").send().get();
assertEquals(r.action, EtcdKeyAction.set);
r = etcd.getDir("etcd4j_test/foo_dir").consistent().send().get();
assertEquals(r.action, EtcdKeyAction.get);
// Test slash before key
r = etcd.getDir("/etcd4j_test/foo_dir").send().get();
assertEquals(r.action, EtcdKeyAction.get);
r = etcd.put("etcd4j_test/foo_dir/foo", "bar").send().get();
assertEquals(r.node.value, "bar");
r = etcd.putDir("etcd4j_test/foo_dir/foo_subdir").ttl(20).send().get();
assertEquals(r.action, EtcdKeyAction.set);
assertNotNull(r.node.expiration);
r = etcd.deleteDir("etcd4j_test/foo_dir").recursive().send().get();
assertEquals(r.action, EtcdKeyAction.delete);
}
开发者ID:jurmous,项目名称:etcd4j,代码行数:26,代码来源:TestFunctionality.java
示例9: testRecursive
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
/**
* Recursive
*/
@Test
public void testRecursive() throws IOException, EtcdException, EtcdAuthenticationException, TimeoutException {
etcd.put("etcd4j_test/nested/root/key-1", "key1").send().get();
etcd.put("etcd4j_test/nested/root/node-1/key-2", "key2").send().get();
etcd.put("etcd4j_test/nested/root/node-1/child/key-3", "key3").send().get();
etcd.put("etcd4j_test/nested/root/node-2/key-4", "key4").send().get();
EtcdKeysResponse r;
r = etcd.get("etcd4j_test/nested").recursive().timeout(10, TimeUnit.SECONDS).send().get();
assertEquals(1, r.node.nodes.size());
assertEquals(3, r.node.nodes.get(0).nodes.size());
r = etcd.getDir("etcd4j_test/nested").recursive().timeout(10, TimeUnit.SECONDS).send().get();
assertEquals(1, r.node.nodes.size());
assertEquals(3, r.node.nodes.get(0).nodes.size());
r = etcd.deleteDir("etcd4j_test/nested").recursive().send().get();
assertEquals(r.action, EtcdKeyAction.delete);
}
开发者ID:jurmous,项目名称:etcd4j,代码行数:24,代码来源:TestFunctionality.java
示例10: testInOrderKeys
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
/**
* In order key tests
*/
@Test
public void testInOrderKeys() throws IOException, EtcdException, EtcdAuthenticationException, TimeoutException {
EtcdKeysResponse r = etcd.post("etcd4j_test/queue", "Job1").send().get();
assertEquals(r.action, EtcdKeyAction.create);
r = etcd.post("etcd4j_test/queue", "Job2").ttl(20).send().get();
assertEquals(r.action, EtcdKeyAction.create);
r = etcd.get(r.node.key).consistent().send().get();
assertTrue(r.node.key.endsWith(r.node.createdIndex+""));
assertEquals(r.node.value, "Job2");
r = etcd.get("etcd4j_test/queue").consistent().recursive().sorted().send().get();
assertEquals(2, r.node.nodes.size());
assertEquals("Job2", r.node.nodes.get(1).value);
r = etcd.deleteDir("etcd4j_test/queue").recursive().send().get();
assertEquals(r.action, EtcdKeyAction.delete);
}
开发者ID:jurmous,项目名称:etcd4j,代码行数:23,代码来源:TestFunctionality.java
示例11: testWait
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
/**
* In order key tests
*/
@Test
public void testWait() throws IOException, EtcdException, EtcdAuthenticationException, InterruptedException, TimeoutException {
EtcdResponsePromise<EtcdKeysResponse> p = etcd.get("etcd4j_test/test").waitForChange().send();
// Ensure the change is received after the listen command is received.
new Timer().schedule(new TimerTask() {
@Override
public void run() {
try {
etcd.put("etcd4j_test/test", "changed").send().get();
} catch (IOException | EtcdException | EtcdAuthenticationException | TimeoutException e) {
fail();
}
}
}, 20);
EtcdKeysResponse r = p.get();
assertEquals("changed", r.node.value);
}
开发者ID:jurmous,项目名称:etcd4j,代码行数:23,代码来源:TestFunctionality.java
示例12: testIfCleanClose
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
@Test
public void testIfCleanClose() throws IOException, EtcdException, EtcdAuthenticationException, TimeoutException {
EtcdClient client = new EtcdClient();
client.setRetryHandler(new RetryWithExponentialBackOff(20, 4, 1000));
EtcdResponsePromise<EtcdKeysResponse> p = client.get("etcd4j_test/test").waitForChange().send();
client.close();
try {
p.get();
fail();
} catch (IOException e){
// should be catched because connection was canceled
if (!(e.getCause() instanceof CancellationException)) {
fail();
}
}
}
开发者ID:jurmous,项目名称:etcd4j,代码行数:19,代码来源:TestFunctionality.java
示例13: 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());
}
开发者ID:jurmous,项目名称:etcd4j,代码行数:27,代码来源:TestFunctionality.java
示例14: 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());
}
开发者ID:jurmous,项目名称:etcd4j,代码行数:20,代码来源:TestFunctionality.java
示例15: 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);
}
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:15,代码来源:EtcdData.java
示例16: delete
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
public boolean delete(final String path) {
return Fn.getJvm(Boolean.FALSE, () -> {
final EtcdKeyDeleteRequest request = this.client.delete(path);
final EtcdResponsePromise<EtcdKeysResponse> promise = request.send();
final EtcdKeysResponse response = promise.get();
return null != response.getNode();
}, path);
}
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:9,代码来源:EtcdData.java
示例17: putFileInEtcd
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
private static void putFileInEtcd(String path, String content) {
try(EtcdClient etcd = new EtcdClient(URI.create(getEtcdUrl()))){
EtcdKeysResponse etcdKeysResponse = etcd.put(directory + path, content).send().get();
String config = etcdKeysResponse.getNode().getValue();
assertThat(config).isEqualTo(content);
} catch (Exception e) {
throw new RuntimeException("Unknown exception while fetching configuration from etcd", e);
}
}
开发者ID:conf4j,项目名称:conf4j,代码行数:10,代码来源:EtcdFileConfigurationSourceTest.java
示例18: getChildren
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
@Override
public List<DiscoveryStoredNode> getChildren() {
return etcdNode.getNodes()
.stream()
.filter(EtcdKeysResponse.EtcdNode::isDir)
.map(DiscoveryStoredEtcdNode::new)
.collect(Collectors.toList());
}
开发者ID:INAETICS,项目名称:Drones-Simulator,代码行数:9,代码来源:DiscoveryStoredEtcdNode.java
示例19: 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);
}
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:9,代码来源:EtcdClientWrapper.java
示例20: set
import mousio.etcd4j.responses.EtcdKeysResponse; //导入依赖的package包/类
@Override
public KvNode set(String key, String value) {
try {
EtcdResponsePromise<EtcdKeysResponse> send = etcd.put(key, value).send();
EtcdKeysResponse resp = send.get();
log.debug("set value {} for key {}", resp.node.value, resp.node.key);
return toNode(resp);
} catch (Exception e) {
throw Throwables.asRuntime(e);
}
}
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:12,代码来源:EtcdClientWrapper.java
注:本文中的mousio.etcd4j.responses.EtcdKeysResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论