use of com.recurly.v3.QueryParams in project incubator-shenyu by apache.
the class ShenyuConsulConfigWatch method watchConfigKeyValues.
private void watchConfigKeyValues() {
if (this.running.get()) {
for (String context : this.consulIndexes.keySet()) {
try {
Long currentIndex = this.consulIndexes.get(context);
if (currentIndex == null) {
currentIndex = -1L;
}
Response<List<GetValue>> response = this.consul.getKVValues(context, null, new QueryParams(waitTime, currentIndex));
if (response.getValue() != null && !response.getValue().isEmpty()) {
Long newIndex = response.getConsulIndex();
if (Objects.nonNull(newIndex) && !newIndex.equals(currentIndex)) {
if (!this.consulIndexes.containsValue(newIndex) && !currentIndex.equals(-1L)) {
LOGGER.trace("Context {} has new index {}", context, newIndex);
Map<String, GetValue> valueMap = extractGetValue(response);
publisher.publishEvent(new ConsulConfigChangedEvent(this, newIndex, valueMap));
} else if (LOGGER.isTraceEnabled()) {
LOGGER.info("Event for index already published for context {}", context);
}
this.consulIndexes.put(context, newIndex);
} else if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Same index for context {}", context);
}
} else if (LOGGER.isTraceEnabled()) {
LOGGER.trace("No value for context {}", context);
}
} catch (Exception e) {
LOGGER.warn("Error querying consul Key/Values for context '{}'. Message: {}", context, e.getMessage());
}
}
}
}
use of com.recurly.v3.QueryParams in project incubator-shenyu by apache.
the class ConsulSyncDataService method watchConfigKeyValues.
private void watchConfigKeyValues() {
if (this.running.get()) {
for (String context : this.consulIndexes.keySet()) {
try {
Long currentIndex = this.consulIndexes.get(context);
if (Objects.isNull(currentIndex)) {
currentIndex = ConsulConstants.INIT_CONFIG_VERSION_INDEX;
}
Response<List<GetValue>> response = this.consulClient.getKVValues(context, null, new QueryParams(consulConfig.getWaitTime(), currentIndex));
if (Objects.isNull(response.getValue()) || response.getValue().isEmpty()) {
if (LOG.isTraceEnabled()) {
LOG.trace("No value for context " + context);
}
continue;
}
Long newIndex = response.getConsulIndex();
if (Objects.isNull(newIndex) || Objects.equals(newIndex, currentIndex)) {
if (LOG.isTraceEnabled()) {
LOG.trace("Same index for context " + context);
}
continue;
}
if (!this.consulIndexes.containsValue(newIndex) && !currentIndex.equals(ConsulConstants.INIT_CONFIG_VERSION_INDEX)) {
if (LOG.isTraceEnabled()) {
LOG.trace("Context " + context + " has new index " + newIndex);
}
final Long lastIndex = currentIndex;
response.getValue().forEach(data -> {
if (data.getModifyIndex() == lastIndex) {
// data has not changed
return;
}
groupMap.get(data.getKey()).change(data.getDecodedValue());
});
} else if (LOG.isTraceEnabled()) {
LOG.info("Event for index already published for context " + context);
}
this.consulIndexes.put(context, newIndex);
} catch (Exception e) {
LOG.warn("Error querying consul Key/Values for context '" + context + "'. Message: " + e.getMessage());
}
}
}
}
use of com.recurly.v3.QueryParams in project recurly-client-java by recurly.
the class MockClient method listResources.
public Pager<MyResource> listResources(QueryParams queryParams) {
final String url = "/resources";
final HashMap<String, String> urlParams = new HashMap<String, String>();
if (queryParams == null)
queryParams = new QueryParams();
final HashMap<String, Object> paramsMap = queryParams.getParams();
final String path = this.interpolatePath(url, urlParams);
Type parameterizedType = TypeToken.getParameterized(Pager.class, MyResource.class).getType();
return new Pager<>(path, paramsMap, this, parameterizedType);
}
use of com.recurly.v3.QueryParams in project polaris-java by polarismesh.
the class ConsulAPIConnector method syncGetServiceInstances.
@Override
public List<DefaultInstance> syncGetServiceInstances(ServiceUpdateTask serviceUpdateTask) {
List<DefaultInstance> instanceList = new ArrayList<>();
try {
HealthServicesRequest request = HealthServicesRequest.newBuilder().setQueryParams(new QueryParams(ConsistencyMode.DEFAULT)).build();
Response<List<HealthService>> response = this.consulClient.getHealthServices(serviceUpdateTask.getServiceEventKey().getService(), request);
if (response.getValue() == null || response.getValue().isEmpty()) {
return Collections.emptyList();
}
for (HealthService service : response.getValue()) {
DefaultInstance instance = new DefaultInstance();
instance.setId(service.getService().getId());
instance.setService(service.getService().getService());
instance.setHost(service.getService().getAddress());
instance.setPort(service.getService().getPort());
instanceList.add(instance);
}
} catch (ConsulException e) {
throw ServerErrorResponseException.build(ErrorCode.SERVER_USER_ERROR.ordinal(), String.format("Get service instances of %s sync failed.", serviceUpdateTask.getServiceEventKey().getServiceKey()));
}
return instanceList;
}
Aggregations