public APIThrottleHandler() { this.accessController = new AccessRateController(); this.roleBasedAccessController = new RoleBasedAccessRateController(); this.applicationRoleBasedAccessController = new RoleBasedAccessRateController(); }
/** * To replicates the states of the already exist caller * * @param callerContext The states of the caller * @param id The id of the remote caller */ public void flushCallerContext(CallerContext callerContext, String id) { if (dataHolder != null && callerContext != null && id != null) { String key = keyPrefix + id; dataHolder.addCallerContext(key, callerContext); // have to do ,because we always gets // any property as non-replicable replicateCaller(id); } }
public void updateCounter(boolean isIncrement) { if (isIncrement) { incrementAndGet(); } else { getAndDecrement(); } } }
/** * Init the access for a particular caller , caller will registered with context * * @param configuration -The Configuration for this caller * @param throttleContext -The Throttle Context * @param currentTime -The system current time in milliseconds */ private void initAccess(CallerConfiguration configuration, ThrottleContext throttleContext, long currentTime) { this.unitTime = configuration.getUnitTime(); this.firstAccessTime = currentTime; this.nextTimeWindow = this.firstAccessTime + this.unitTime; this.roleId = configuration.getID(); //Also we need to pick counter value associated with time window. throttleContext.addCallerContext(this, this.id); throttleContext.replicateTimeWindow(this.id); }
protected AccessInformation getAccessInformation(ThrottleContext hardThrottleContext, String throttleKey, String productionHardLimit) throws ThrottleException { return roleBasedAccessController.canAccess(hardThrottleContext, throttleKey, productionHardLimit); }
public static ThrottleServiceDataHolder getInstance() { if (thisInstance != null && thisInstance.getThrottleProperties() == null) { thisInstance.setThrottleProperties( ThrottleUtil.loadThrottlePropertiesFromConfigurations()); } return thisInstance; }
/** * Removes the caller and destroy shared params of caller * * @param id The Id of the caller */ public void removeAndDestroyShareParamsOfCaller(String id) { if (id != null) { if(log.isDebugEnabled()) { log.info("REMOVE AND DESTROY OF SHARED PARAM OF CALLER WITH ID " + id); } removeCaller(id); SharedParamManager.removeTimestamp(id); SharedParamManager.removeCounter(id); } }
/** * To add the caller and replicates the states of the given caller * * @param callerContext The states of the caller * @param id The id of the caller */ public void addAndFlushCallerContext(CallerContext callerContext, String id) { if (callerContext != null && id != null) { addCaller(callerContext, id); replicateCaller(id); } }
/** * Abstraction for processing service policy assertion and create a throttle based on it * * @param policy Throttle policy * @return Throttle instance , if there any service policy assertion , otherwise null * @throws ThrottleException */ public static Throttle createServiceThrottle(Policy policy) throws ThrottleException { return createThrottle(policy, ThrottleConstants.SERVICE_THROTTLE_ASSERTION_QNAME); }
/** * setting callerContext - put callersMap against time and * put time against remote caller id (ip/domain) * * @param callerContext - The remote caller's runtime data. * @param id - The id of the remote caller */ public void addCallerContext(CallerContext callerContext, String id) { if (callerContext != null && id != null) { addCaller(callerContext, id); } }
public void setConfigurationContext(ConfigurationContext configurationContext) { this.configctx = configurationContext; if (dataHolder == null) { initDataHolder(); } }
@Override public int getType() { return CallerContext.this.getType(); } };
/** * The Constructor with all configuration data * * @param unitTime - long value which represents Unit Time Window * @param maximumRequest - int value which represents Maximum Request * @param prohibitTimePeriod - long value which represents Prohibit Time after Max request came * @param ID - String value which represents ID */ protected CallerConfiguration(long unitTime, int maximumRequest, long prohibitTimePeriod, String ID) { this(); this.unitTime = unitTime; this.maximumRequest = maximumRequest; this.prohibitTimePeriod = prohibitTimePeriod; setID(ID); }
/** * Helper method to handle exception * * @param message Debug message * @throws ThrottleException */ private static void handleException(String message) throws ThrottleException { String msg = "Error was occurred during throttle policy processing " + message; log.error(msg); throw new ThrottleException(msg); }
public static ThrottleContext getApplicationThrottleContext(MessageContext synCtx, ThrottleDataHolder dataHolder, String applicationId, String policyKeyApplication) { synchronized (lock) { Object throttleContext = dataHolder.getThrottleContext(applicationId); if(throttleContext == null){ return createThrottleContext(synCtx, dataHolder, applicationId, policyKeyApplication); } return (ThrottleContext)throttleContext; } }
public APIThrottleHandler() { this.accessController = new AccessRateController(); this.roleBasedAccessController = new RoleBasedAccessRateController(); this.applicationRoleBasedAccessController = new RoleBasedAccessRateController(); }
/** * Abstraction for processing module policy assertion and create a throttle based on it * * @param policy Throttle policy * @return Throttle instance , if there any module policy assertion , otherwise null * @throws ThrottleException */ public static Throttle createModuleThrottle(Policy policy) throws ThrottleException { return createThrottle(policy, ThrottleConstants.MODULE_THROTTLE_ASSERTION_QNAME); }
public ThrottleHandler() { this.debugOn = log.isDebugEnabled(); this.accessRateController = new AccessRateController(); this.roleBasedAccessController = new RoleBasedAccessRateController(); }
/** * Abstraction for processing mediator policy assertion and create a throttle based on it * * @param policy Throttle policy * @return Throttle instance , if there any mediator policy assertion , otherwise null * @throws ThrottleException */ public static Throttle createMediatorThrottle(Policy policy) throws ThrottleException { return createThrottle(policy, ThrottleConstants.MEDIATOR_THROTTLE_ASSERTION_QNAME); }
/** * Abstraction for processing operation policy assertion and create a throttle based on it * * @param policy Throttle policy * @return Throttle instance , if there any operation policy assertion , otherwise null * @throws ThrottleException */ public static Throttle createOperationThrottle(Policy policy) throws ThrottleException { return createThrottle(policy, ThrottleConstants.OPERATION_THROTTLE_ASSERTION_QNAME); }