本文整理了Java中com.orbitz.consul.model.kv.Value.getValueAsString()
方法的一些代码示例,展示了Value.getValueAsString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Value.getValueAsString()
方法的具体详情如下:
包路径:com.orbitz.consul.model.kv.Value
类名称:Value
方法名:getValueAsString
暂无
代码示例来源:origin: rickfast/consul-client
/**
* {@inheritDoc}
* <p>
* Returns a lazily initialized value of the {@link Value#getValueAsString() valueAsString} attribute.
* Initialized once and only once and stored for subsequent access with proper synchronization.
* @return A lazily initialized value of the {@code l.name} attribute
*/
@Override
public Optional<String> getValueAsString() {
if ((lazyInitBitmap & VALUE_AS_STRING_LAZY_INIT_BIT) == 0) {
synchronized (this) {
if ((lazyInitBitmap & VALUE_AS_STRING_LAZY_INIT_BIT) == 0) {
this.valueAsString = Preconditions.checkNotNull(super.getValueAsString(), "valueAsString");
lazyInitBitmap |= VALUE_AS_STRING_LAZY_INIT_BIT;
}
}
}
return valueAsString;
}
代码示例来源:origin: rickfast/consul-client
@JsonIgnore
@org.immutables.value.Value.Lazy
public Optional<String> getValueAsString() {
return getValueAsString(Charset.defaultCharset());
}
代码示例来源:origin: rickfast/consul-client
/**
* Retrieves a string value for a specific key from the key/value store.
*
* GET /v1/kv/{key}
*
* @param key The key to retrieve.
* @param charset The charset of the value
* @return An {@link Optional} containing the value as a string or
* {@link Optional#empty()}
*/
public Optional<String> getValueAsString(String key, Charset charset) {
return getValue(key).flatMap(v -> v.getValueAsString(charset));
}
代码示例来源:origin: couchbase/couchbase-elasticsearch-connector
private static Function<ConsulResponse<Value>, String> valueAsString() {
return value -> value.getResponse().getValueAsString(UTF_8).orElse("");
}
代码示例来源:origin: rickfast/consul-client
/**
* Retrieves a list of string values for a specific key from the key/value
* store.
*
* GET /v1/kv/{key}?recurse
*
* @param key The key to retrieve.
* @param charset The charset of the value
* @return A list of zero to many string values.
*/
public List<String> getValuesAsString(String key, Charset charset) {
List<String> result = new ArrayList<>();
for(Value value : getValues(key)) {
value.getValueAsString(charset).ifPresent(result::add);
}
return result;
}
代码示例来源: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: rickfast/consul-client
public Optional<String> getLeaderInfoForService(final String serviceName) {
String key = getServiceKey(serviceName);
Optional<Value> value = client.keyValueClient().getValue(key);
return value.flatMap(val -> {
if(val.getSession().isPresent()) {
return val.getValueAsString();
}
return Optional.empty();
});
}
代码示例来源:origin: streampipes/streampipes-ce
@Override
public void run() {
Consul consulThread = Consul.builder().build(); // connect to Consul on localhost
KeyValueClient kvClientThread = consulThread.keyValueClient();
while (true) {
configProps.keySet().forEach((s) -> {
Optional<Value> te = kvClientThread.getValue(addSn(s));
if (!te.get().getValueAsString().get().equals(configProps.get(s))) {
callback.onChange();
configProps.put(s, te.get().getValueAsString().get());
}
});
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
代码示例来源: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: 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: couchbase/couchbase-elasticsearch-connector
private static void atomicUpdate(KeyValueClient kv, String key, Function<String, String> mutator) throws IOException {
while (true) {
final ConsulResponse<Value> r = kv.getConsulResponseWithValue(key).orElse(null);
if (r == null) {
// Don't automatically create the document, because it might need to be associated with another node's session.
// For example, an RPC endpoint doc is updated by both client and server, but is tied to the server session.
throw new IOException("Can't update non-existent document: " + key);
}
final BigInteger index = r.getIndex();
final String oldValue = r.getResponse().getValueAsString(UTF_8).orElse(missingDocumentValue);
final String newValue = mutator.apply(oldValue);
if (Objects.equals(newValue, oldValue)) {
return;
}
final PutOptions options = ImmutablePutOptions.builder().cas(index.longValue()).build();
boolean success = kv.putValue(key, newValue, 0, options, UTF_8);
if (success) {
return;
}
// todo truncated exponential backoff, please! Die if timeout!
//MILLISECONDS.sleep(100);
}
}
代码示例来源:origin: couchbase/couchbase-elasticsearch-connector
LOGGER.debug("Long poll timed out, polling again for {}", key);
} else {
final String valueAsString = response.getResponse().getValueAsString(UTF_8).orElse(null);
final T mappedValue = mapper.apply(valueAsString);
if (condition.test(mappedValue)) {
代码示例来源:origin: couchbase/couchbase-elasticsearch-connector
.getValueAsString(UTF_8)
.orElseThrow(() -> new ConfigException("missing value for Consul key: " + configLocation));
代码示例来源:origin: couchbase/couchbase-elasticsearch-connector
final String json = response.getResponse().getValueAsString(UTF_8).orElse("{}");
final EndpointDocument initialEndpoint = mapper.readValue(json, EndpointDocument.class);
内容来源于网络,如有侵权,请联系作者删除!