本文整理了Java中com.orbitz.consul.model.kv.Value.getKey()
方法的一些代码示例,展示了Value.getKey()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Value.getKey()
方法的具体详情如下:
包路径:com.orbitz.consul.model.kv.Value
类名称:Value
方法名:getKey
暂无
代码示例来源:origin: rickfast/consul-client
@VisibleForTesting
static Function<Value, String> getKeyExtractorFunction(final String rootPath) {
return input -> {
Preconditions.checkNotNull(input, "Input to key extractor is null");
Preconditions.checkNotNull(input.getKey(), "Input to key extractor has no key");
if (rootPath.equals(input.getKey())) {
return "";
}
int lastSlashIndex = rootPath.lastIndexOf("/");
if (lastSlashIndex >= 0) {
return input.getKey().substring(lastSlashIndex+1);
}
return input.getKey();
};
}
代码示例来源:origin: stackoverflow.com
List<Value> values = new ArrayList<Values>();
// .. add values
values.add(new Value(key, data1, data2, etc..));
Comparator<Value> compValue = new Comparator<Value>() {
public int compare(Value v1, Value v2) {
return v1.getKey()>v2.getKey();
}
}
Collections.sort(values, compValue);
// now we can search on key
int index = Collections.binarySearch(values, new Value(keyTofind), valueComp);
Value foundValue = null; // value with the key may not be in the list
if (index>=0)
foundValue = values.get(index);
// we can also update the list
Value newValue = new Value(key, data, data2, etc...);
int insert = Collections.binarySearch(values, newValue, valueComp);
// insert will be negative
values.add((-insert)-1, newValue);
代码示例来源:origin: cfg4j/cfg4j
private void reload() {
Map<String, String> newConsulValues = new HashMap<>();
List<Value> valueList;
try {
LOG.debug("Reloading configuration from Consuls' K-V store");
valueList = kvClient.getValues("/");
} catch (Exception e) {
throw new SourceCommunicationException("Can't get values from k-v store", e);
}
for (Value value : valueList) {
String val = "";
if (value.getValueAsString().isPresent()) {
val = value.getValueAsString().get();
}
LOG.trace("Consul provided configuration key: " + value.getKey() + " with value: " + val);
newConsulValues.put(value.getKey(), val);
}
consulValues = newConsulValues;
}
代码示例来源:origin: liaokailin/springcloud
/**
* 获取values
*/
@Test
public void getValues(){
Consul consul = Consul.builder().withHostAndPort(HostAndPort.fromParts("127.0.0.1", 8500)).build();
KeyValueClient keyValueClient = consul.keyValueClient();
List<Value> values = keyValueClient.getValues("/web");
for(Value value : values){
System.out.println(value.getKey()+","+ new String(Base64.decodeBase64(value.getValue().get())) );
}
}
代码示例来源:origin: org.apache.camel/camel-consul
protected void onValue(Value value) {
final Exchange exchange = endpoint.createExchange();
final Message message = exchange.getIn();
message.setHeader(ConsulConstants.CONSUL_KEY, value.getKey());
message.setHeader(ConsulConstants.CONSUL_RESULT, true);
message.setHeader(ConsulConstants.CONSUL_FLAGS, value.getFlags());
message.setHeader(ConsulConstants.CONSUL_CREATE_INDEX, value.getCreateIndex());
message.setHeader(ConsulConstants.CONSUL_LOCK_INDEX, value.getLockIndex());
message.setHeader(ConsulConstants.CONSUL_MODIFY_INDEX, value.getModifyIndex());
if (value.getSession().isPresent()) {
message.setHeader(ConsulConstants.CONSUL_SESSION, value.getSession().get());
}
message.setBody(configuration.isValueAsString() ? value.getValueAsString().orElse(null) : value.getValue().orElse(null));
try {
getProcessor().process(exchange);
} catch (Exception e) {
getExceptionHandler().handleException("Error processing exchange", exchange, e);
}
}
代码示例来源:origin: couchbase/couchbase-elasticsearch-connector
public static void atomicUpdate(KeyValueClient kv, ConsulResponse<Value> initialResponse, Function<String, String> mutator) throws IOException {
final Value v = initialResponse.getResponse();
final String key = v.getKey();
LOGGER.debug("Updating key {}", key);
final String oldValue = v.getValueAsString(UTF_8).orElse(missingDocumentValue);
final String newValue = mutator.apply(oldValue);
if (Objects.equals(newValue, oldValue)) {
return;
}
final long index = initialResponse.getIndex().longValue();
final PutOptions options = ImmutablePutOptions.builder().cas(index).build();
boolean success = kv.putValue(key, newValue, 0, options, UTF_8);
if (!success) {
LOGGER.info("Failed to put new document (optimistic locking failure?); reloading and retrying");
atomicUpdate(kv, key, mutator);
}
}
代码示例来源:origin: streampipes/streampipes-ce
public static Map<String, String> getKeyValue(String route) {
Consul consul = consulInstance();
KeyValueClient keyValueClient = consul.keyValueClient();
Map<String, String> keyValues = new HashMap<>();
ConsulResponse<List<Value>> consulResponseWithValues = keyValueClient.getConsulResponseWithValues(route);
if(consulResponseWithValues.getResponse() != null) {
for (Value value: consulResponseWithValues.getResponse()) {
String key = value.getKey();
String v = "";
if(value.getValueAsString().isPresent()) {
v = value.getValueAsString().get();
}
LOG.info("Load key: " + route + " value: " + v);
keyValues.put(key, v);
}
}
return keyValues;
}
代码示例来源:origin: rickfast/consul-client
/**
* Fill a builder with attribute values from the provided {@code Value} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(Value instance) {
Preconditions.checkNotNull(instance, "instance");
createIndex(instance.getCreateIndex());
modifyIndex(instance.getModifyIndex());
lockIndex(instance.getLockIndex());
key(instance.getKey());
flags(instance.getFlags());
Optional<String> valueOptional = instance.getValue();
if (valueOptional.isPresent()) {
value(valueOptional);
}
Optional<String> sessionOptional = instance.getSession();
if (sessionOptional.isPresent()) {
session(sessionOptional);
}
return this;
}
内容来源于网络,如有侵权,请联系作者删除!