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));
});
}
Aggregations