Search in sources :

Example 1 with TransferQuotaProbeResponse

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

the class TransferQuotaPolicy method probe.

@Override
public void probe(RateLimitingProbeConfig probeRequest, TransferQuotaConfig policyConfig, ProbeContext probeContext, IPolicyContext context, IAsyncResultHandler<IPolicyProbeResponse> resultHandler) {
    String bucketId = 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 TransferQuotaProbeResponse().setStatus(remaining).setConfig(policyConfig);
        resultHandler.handle(AsyncResultImpl.create(probeResult));
    });
}
Also used : IRateLimiterComponent(io.apiman.gateway.engine.components.IRateLimiterComponent) RateLimitResponse(io.apiman.gateway.engine.components.rate.RateLimitResponse) TransferQuotaProbeResponse(io.apiman.gateway.engine.policies.probe.TransferQuotaProbeResponse)

Aggregations

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