本文整理汇总了Java中com.orbitz.consul.option.QueryOptions类的典型用法代码示例。如果您正苦于以下问题:Java QueryOptions类的具体用法?Java QueryOptions怎么用?Java QueryOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryOptions类属于com.orbitz.consul.option包,在下文中一共展示了QueryOptions类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValue
import com.orbitz.consul.option.QueryOptions; //导入依赖的package包/类
@InvokeOnHeader(ConsulKeyValueActions.GET_VALUE)
protected void getValue(Message message) throws Exception {
Object result;
if (isValueAsString(message)) {
result = getClient().getValueAsString(
getMandatoryKey(message)
).orNull();
} else {
result = getClient().getValue(
getMandatoryKey(message),
getOption(message, QueryOptions.BLANK, QueryOptions.class)
).orNull();
}
setBodyAndResult(message, result);
}
示例2: getValues
import com.orbitz.consul.option.QueryOptions; //导入依赖的package包/类
@InvokeOnHeader(ConsulKeyValueActions.GET_VALUES)
protected void getValues(Message message) throws Exception {
Object result;
if (isValueAsString(message)) {
result = getClient().getValuesAsString(
getMandatoryKey(message)
);
} else {
result = getClient().getValues(
getMandatoryKey(message),
getOption(message, QueryOptions.BLANK, QueryOptions.class)
);
}
setBodyAndResult(message, result);
}
示例3: watch
import com.orbitz.consul.option.QueryOptions; //导入依赖的package包/类
@Override
public void watch(EventClient client) {
client.listEvents(
key,
QueryOptions.blockSeconds(configuration.getBlockSeconds(), index.get()).build(),
this
);
}
示例4: list
import com.orbitz.consul.option.QueryOptions; //导入依赖的package包/类
@InvokeOnHeader(ConsulEventActions.LIST)
protected void list(Message message) throws Exception {
setBodyAndResult(
message,
getClient().listEvents(
getKey(message),
getOption(message, QueryOptions.BLANK, QueryOptions.class)
)
);
}
示例5: run
import com.orbitz.consul.option.QueryOptions; //导入依赖的package包/类
@Override
public void run() {
if (isRunAllowed()) {
// Refresh session
sessionClient.renewSession(sessionId);
keyValueClient.getValue(
servicePath,
QueryOptions.blockSeconds(ttl / 3, index.get()).build(),
this);
}
}
示例6: getAclToken
import com.orbitz.consul.option.QueryOptions; //导入依赖的package包/类
/**
* Method to build an ACL token in a query option.
*
* @param token
* @return QueryOption
*/
public static QueryOptions getAclToken(String token){
if(token == null || token.trim().isEmpty()){
return ImmutableQueryOptions.BLANK;
}
//ACL token for registering as a service on consul, check health and get service catalog
ImmutableQueryOptions.Builder optionBuilder = ImmutableQueryOptions.builder().token(token);
return optionBuilder.build();
}
示例7: queryOptions
import com.orbitz.consul.option.QueryOptions; //导入依赖的package包/类
protected QueryOptions queryOptions() {
return QueryOptions.blockSeconds(configuration.getBlockSeconds(), index.get()).build();
}
示例8: blockingCallTest
import com.orbitz.consul.option.QueryOptions; //导入依赖的package包/类
@Test
public void blockingCallTest() throws InterruptedException {
injects();
keyValueClient.putValue(KEY, VALUE);
final StringBuilder builder = new StringBuilder();
final ConsulResponseCallback<Optional<Value>> callback = new ConsulResponseCallback<Optional<Value>>() {
final AtomicReference<BigInteger> index = new AtomicReference<BigInteger>(null);
@Override
public void onComplete(final ConsulResponse<Optional<Value>> consulResponse) {
if (consulResponse.getResponse().isPresent()) {
final Value v = consulResponse.getResponse().get();
builder.setLength(0);
builder.append(v.getValueAsString().get());
}
index.set(consulResponse.getIndex());
watch();
}
void watch() {
keyValueClient.getValue(KEY, QueryOptions.blockMinutes(5, index.get()).build(), this);
}
@Override
public void onFailure(final Throwable throwable) {
LOGGER.error("Error encountered", throwable);
watch();
}
};
keyValueClient.getValue(KEY, QueryOptions.blockMinutes(5, new BigInteger("0")).build(), callback);
Thread.sleep(1000);
keyValueClient.putValue(KEY, NEW_VALUE);
Thread.sleep(500);
Assert.assertEquals(builder.toString(), NEW_VALUE);
keyValueClient.deleteKey(KEY);
final String delValue = keyValueClient.getValueAsString(KEY).or(DELETED);
Assert.assertEquals(delValue, DELETED);
}