Search in sources :

Example 1 with ServiceRuleByProto

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());
}
Also used : CircuitBreaker(com.tencent.polaris.client.pb.CircuitBreakerProto.CircuitBreaker) DiscoverResponse(com.tencent.polaris.client.pb.ResponseProto.DiscoverResponse) ServiceRuleByProto(com.tencent.polaris.client.pojo.ServiceRuleByProto)

Example 2 with ServiceRuleByProto

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());
}
Also used : RateLimit(com.tencent.polaris.client.pb.RateLimitProto.RateLimit) ArrayList(java.util.ArrayList) DiscoverResponse(com.tencent.polaris.client.pb.ResponseProto.DiscoverResponse) Rule(com.tencent.polaris.client.pb.RateLimitProto.Rule) ServiceRuleByProto(com.tencent.polaris.client.pojo.ServiceRuleByProto)

Example 3 with ServiceRuleByProto

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());
}
Also used : Routing(com.tencent.polaris.client.pb.RoutingProto.Routing) DiscoverResponse(com.tencent.polaris.client.pb.ResponseProto.DiscoverResponse) ServiceRuleByProto(com.tencent.polaris.client.pojo.ServiceRuleByProto)

Aggregations

DiscoverResponse (com.tencent.polaris.client.pb.ResponseProto.DiscoverResponse)3 ServiceRuleByProto (com.tencent.polaris.client.pojo.ServiceRuleByProto)3 CircuitBreaker (com.tencent.polaris.client.pb.CircuitBreakerProto.CircuitBreaker)1 RateLimit (com.tencent.polaris.client.pb.RateLimitProto.RateLimit)1 Rule (com.tencent.polaris.client.pb.RateLimitProto.Rule)1 Routing (com.tencent.polaris.client.pb.RoutingProto.Routing)1 ArrayList (java.util.ArrayList)1