Search in sources :

Example 1 with RateLimitingProbeResponse

use of io.apiman.gateway.engine.policies.probe.RateLimitingProbeResponse in project apiman by apiman.

the class RateLimitingPolicy method probe.

@Override
public void probe(RateLimitingProbeConfig probeRequest, RateLimitingConfig policyConfig, ProbeContext probeContext, IPolicyContext context, IAsyncResultHandler<IPolicyProbeResponse> resultHandler) {
    String bucketId = bucketFactory.bucketId(probeRequest, probeContext, policyConfig);
    IRateLimiterComponent rateLimiter = context.getComponent(IRateLimiterComponent.class);
    // Ask for rate limit, but don't actually decrement the counter.
    rateLimiter.accept(bucketId, bucketFactory.getPeriod(policyConfig), policyConfig.getLimit(), 0, rateLimResult -> {
        RateLimitResponse remaining = rateLimResult.getResult();
        var probeResult = new RateLimitingProbeResponse().setStatus(remaining).setConfig(policyConfig);
        resultHandler.handle(AsyncResultImpl.create(probeResult));
    });
}
Also used : IRateLimiterComponent(io.apiman.gateway.engine.components.IRateLimiterComponent) RateLimitingProbeResponse(io.apiman.gateway.engine.policies.probe.RateLimitingProbeResponse) RateLimitResponse(io.apiman.gateway.engine.components.rate.RateLimitResponse)

Aggregations

IRateLimiterComponent (io.apiman.gateway.engine.components.IRateLimiterComponent)1 RateLimitResponse (io.apiman.gateway.engine.components.rate.RateLimitResponse)1 RateLimitingProbeResponse (io.apiman.gateway.engine.policies.probe.RateLimitingProbeResponse)1