All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nepxion.aquarius.limit.redis.impl.RedisLimitDelegateImpl Maven / Gradle / Ivy

Go to download

Nepxion Aquarius is a list of distribution components based on Redis + Zookeeper with Nepxion Matrix AOP framework

There is a newer version: 2.0.13
Show newest version
package com.nepxion.aquarius.limit.redis.impl;

/**
 * 

Title: Nepxion Aquarius

*

Description: Nepxion Aquarius

*

Copyright: Copyright (c) 2017-2050

*

Company: Nepxion

* @author Haojun Ren * @version 1.0 */ import org.aopalliance.intercept.MethodInvocation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import com.nepxion.aquarius.common.exception.AquariusException; import com.nepxion.aquarius.limit.LimitDelegate; import com.nepxion.aquarius.limit.LimitExecutor; import com.nepxion.aquarius.limit.constant.LimitConstant; public class RedisLimitDelegateImpl implements LimitDelegate { private static final Logger LOG = LoggerFactory.getLogger(RedisLimitDelegateImpl.class); @Autowired private LimitExecutor limitExecutor; @Value("${" + LimitConstant.LIMIT_AOP_EXCEPTION_IGNORE + ":true}") private Boolean limitAopExceptionIgnore; @Override public Object invoke(MethodInvocation invocation, String key, int limitPeriod, int limitCount) throws Throwable { boolean status = true; try { status = limitExecutor.tryAccess(key, limitPeriod, limitCount); } catch (Exception e) { if (limitAopExceptionIgnore) { LOG.error("Redis exception occurs while Limit", e); return invocation.proceed(); } else { throw e; } } if (status) { return invocation.proceed(); } else { throw new AquariusException("Reach max limited access count=" + limitCount + " within period=" + limitPeriod + " seconds"); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy