@Override
    public void accept(final String bucketId, final RateBucketPeriod period, final long limit,
            final long increment, final IAsyncResultHandler<RateLimitResponse> handler) {
        final String id = id(bucketId);

        try {
            Get get = new Get.Builder(getIndexName(), id).type("rateBucket").build(); //$NON-NLS-1$
            JestResult result = getClient().execute(get);
            RateLimiterBucket bucket;
            long version;
            if (result.isSucceeded()) {
                // use the existing bucket
                version = result.getJsonObject().get("_version").getAsLong(); //$NON-NLS-1$
                bucket = result.getSourceAsObject(RateLimiterBucket.class);
            } else {
                // make a new bucket
                version = 0;
                bucket = new RateLimiterBucket();
            }
            bucket.resetIfNecessary(period);

            final RateLimitResponse rlr = new RateLimitResponse();
            if (bucket.getCount() > limit) {
                rlr.setAccepted(false);
            } else {
                rlr.setAccepted(bucket.getCount() < limit);
                bucket.setCount(bucket.getCount() + increment);
                bucket.setLast(System.currentTimeMillis());
            }
            int reset = (int) (bucket.getResetMillis(period) / 1000L);
            rlr.setReset(reset);
            rlr.setRemaining(limit - bucket.getCount());
            updateBucketAndReturn(id, bucket, rlr, version, bucketId, period, limit, increment, handler);
        } catch (Throwable e) {
            handler.handle(AsyncResultImpl.create(e, RateLimitResponse.class));
        }
    }
@ Override public void accept ( final String bucketId , final RateBucketPeriod period , final long limit , final long increment , final IAsyncResultHandler < RateLimitResponse > handler ) { final String id = id ( bucketId ) ; try { Get get = new Get . Builder ( getIndexName ( ) , id ) . type ( "rateBucket" ) . build ( ) ; JestResult result = getClient ( ) . execute ( get ) ; RateLimiterBucket bucket ; long version ; if ( result . isSucceeded ( ) ) { version = result . getJsonObject ( ) . get ( "_version" ) . getAsLong ( ) ; bucket = result . getSourceAsObject ( RateLimiterBucket . class ) ; } else { version = 0 ; bucket = new RateLimiterBucket ( ) ; } bucket . resetIfNecessary ( period ) ; final RateLimitResponse rlr = new RateLimitResponse ( ) ; if ( bucket . getCount ( ) > limit ) { rlr . setAccepted ( false ) ; } else { rlr . setAccepted ( bucket . getCount ( ) < limit ) ; bucket . setCount ( bucket . getCount ( ) + increment ) ; bucket . setLast ( System . currentTimeMillis ( ) ) ; } int reset = ( int ) ( bucket . getResetMillis ( period ) / 1000L ) ; rlr . setReset ( reset ) ; rlr . setRemaining ( limit - bucket . getCount ( ) ) ; updateBucketAndReturn ( id , bucket , rlr , version , bucketId , period , limit , increment , handler ) ; } catch ( Throwable e ) { handler . handle ( AsyncResultImpl . create ( e , RateLimitResponse . class ) ) ; } }
@see io.apiman.gateway.engine.components.IRateLimiterComponent#accept(java.lang.String, io.apiman.gateway.engine.rates.RateBucketPeriod, long, long, io.apiman.gateway.engine.async.IAsyncResultHandler)