use of com.tencent.polaris.client.pojo.ServiceRuleByProto in project polaris-java by polarismesh.
the class CircuitBreakCacheHandler method messageToCacheValue.
@Override
public RegistryCacheValue messageToCacheValue(RegistryCacheValue oldValue, Object newValue, boolean isCacheLoaded) {
DiscoverResponse discoverResponse = (DiscoverResponse) newValue;
CircuitBreaker circuitBreaker = discoverResponse.getCircuitBreaker();
String revision = "";
if (null != circuitBreaker) {
revision = circuitBreaker.getRevision().getValue();
}
return new ServiceRuleByProto(circuitBreaker, revision, isCacheLoaded, getTargetEventType());
}
use of com.tencent.polaris.client.pojo.ServiceRuleByProto in project polaris-java by polarismesh.
the class RateLimitingCacheHandler method messageToCacheValue.
@Override
public RegistryCacheValue messageToCacheValue(RegistryCacheValue oldValue, Object newValue, boolean isCacheLoaded) {
DiscoverResponse discoverResponse = (DiscoverResponse) newValue;
RateLimit rateLimit = discoverResponse.getRateLimit();
String revision = getRevision(discoverResponse);
List<Rule> rulesList = rateLimit.getRulesList();
// 需要做一次排序,PB中的数据不可变,需要单独构建一份
List<Rule> sortedRules = new ArrayList<>(rulesList);
sortedRules.sort((o1, o2) -> {
if (o1.getPriority().getValue() != o2.getPriority().getValue()) {
return o1.getPriority().getValue() - o2.getPriority().getValue();
}
return o1.getId().getValue().compareTo(o2.getId().getValue());
});
RateLimit newRateLimit = RateLimit.newBuilder().addAllRules(sortedRules).setRevision(StringValue.newBuilder().setValue(revision).build()).build();
return new ServiceRuleByProto(newRateLimit, revision, isCacheLoaded, getTargetEventType());
}
use of com.tencent.polaris.client.pojo.ServiceRuleByProto in project polaris-java by polarismesh.
the class RoutingCacheHandler method messageToCacheValue.
@Override
public RegistryCacheValue messageToCacheValue(RegistryCacheValue oldValue, Object newValue, boolean isCacheLoaded) {
DiscoverResponse discoverResponse = (DiscoverResponse) newValue;
Routing routing = discoverResponse.getRouting();
String revision = "";
if (null != routing) {
revision = routing.getRevision().getValue();
}
return new ServiceRuleByProto(routing, revision, isCacheLoaded, getTargetEventType());
}
Aggregations