CallerContext callerContext = dataHolder.getCallerContext(key); if (callerContext != null) { callerId = callerContext.getId(); long sharedTimestamp = SharedParamManager.getSharedTimestamp(callerContext.getId()); long sharedNextWindow = sharedTimestamp + callerContext.getUnitTime(); localFirstAccessTime = callerContext.getFirstAccessTime(); callerContext.setFirstAccessTime(sharedTimestamp); callerContext.setNextTimeWindow(sharedNextWindow); callerContext.setGlobalCounter(SharedParamManager.getDistributedCounter(callerId)); if(log.isDebugEnabled()) { log.debug("Setting time windows of caller context when window already set=" + callerId); callerContext.setFirstAccessTime(sharedTimestamp); callerContext.setNextTimeWindow(sharedNextWindow); callerContext.setGlobalCounter(SharedParamManager.getDistributedCounter(callerId)); if (log.isDebugEnabled()) { log.debug("Setting time windows of caller context in intermediate interval=" + callerContext.resetGlobalCounter(); callerContext.setLocalCounter(1);//Local counter will be set to one as new time window starts if (log.isDebugEnabled()) { log.debug("Complete resetting time window of=" + callerId);
if (callerContext.getLocalCounter() > 0 && callerContext.getNextTimeWindow() > System.currentTimeMillis()) { String id = callerContext.getId(); long localCounter = callerContext.getLocalCounter(); callerContext.resetLocalCounter(); Long distributedCounter = SharedParamManager.asyncGetAndAddDistributedCounter(id, localCounter); callerContext.setGlobalCounter(distributedCounter + localCounter); if(log.isDebugEnabled()) { log.debug("Increasing counters of context :" + callerContext.getId() + " " + "Replicated Count After Update : distributedCounter =" +distributedCounter + " localCounter=" + localCounter + " total=" + (distributedCounter + localCounter));
@Override public int getType() { return CallerContext.this.getType(); } };
if (o instanceof CallerContext) { // In the case nextAccessTime is unique CallerContext c = ((CallerContext) o); String key = c.getId(); String role = c.getRoleId(); if (key != null) { if (dataHolder != null && keyPrefix != null) { c.cleanUpCallers( this.throttleConfiguration.getCallerConfiguration(role), this, time); while (ite.hasNext()) { CallerContext c = (CallerContext) ite.next(); String key = c.getId(); String role = c.getRoleId(); if (key != null) { if (dataHolder != null && keyPrefix != null) { c.cleanUpCallers( this.throttleConfiguration.getCallerConfiguration(role), this, time);
initAccess(configuration, throttleContext, currentTime); canAccess = canAccessIfUnitTimeNotOver(configuration, throttleContext, currentTime); } else { canAccess = canAccessIfUnitTimeOver(configuration, throttleContext, currentTime);
for (Iterator it = callers.iterator(); it.hasNext(); ) { CallerContext cc = (CallerContext) it.next(); if (cc != null && id.equals(cc.getId())) { return cc;
long currentTime = System.currentTimeMillis(); if (!caller.canAccess(throttleContext, configuration, currentTime)) {
Long time = new Long(callerContext.getNextTimeWindow()); if (!callersMap.containsKey(time)) { callersMap.put(time, callerContext);
if (o instanceof CallerContext) { // In the case nextAccessTime is unique CallerContext c = ((CallerContext) o); String key = c.getId(); String role = c.getRoleId(); if (key != null) { if (dataHolder != null && keyPrefix != null) { c.cleanUpCallers( this.throttleConfiguration.getCallerConfiguration(role) , this for (Iterator ite = callers.iterator(); ite.hasNext(); ) { CallerContext c = (CallerContext) ite.next(); String key = c.getId(); String role = c.getRoleId(); if (key != null) { if (dataHolder != null && keyPrefix != null) { c.cleanUpCallers( this.throttleConfiguration.getCallerConfiguration(role) , this
log.debug("CallerContext Checking access if unit time over next time window>> Access allowed=" + maxRequest + " available=" + (maxRequest - (this.globalCount.get() + this.localCount.get())) + " key=" + this.getId()+ " currentGlobalCount=" + globalCount + " currentTime=" + currentTime + " nextTimeWindow=" + this.nextTimeWindow +" currentLocalCount=" + localCount + " Tier=" + configuration.getID() + " nextAccessTime="+ this.nextAccessTime); if (log.isDebugEnabled()) { log.debug("CallerContext Checking access if unit time over>> Access allowed=" + maxRequest + " available=" + (maxRequest - (this.globalCount.get() + this.localCount.get())) + " key=" + this.getId() + " currentGlobalCount=" + globalCount + " currentTime=" + currentTime + " nextTimeWindow=" + this.nextTimeWindow + " currentLocalCount=" + localCount + " Tier=" + configuration.getID() + " nextAccessTime=" log.debug("Caller=" + this.getId() + " has reset counters and added for replication when unit " + "time is over");
long currentTime = System.currentTimeMillis(); if (!caller.canAccess(throttleContext, configuration, currentTime)) {
log.debug("CallerContext Checking access if unit time is not over and less than max count>> Access " + "allowed=" + maxRequest + " available="+ (maxRequest - (this.globalCount.get() + this.localCount.get())) +" key=" + this.getId() + " currentGlobalCount=" + globalCount + " currentTime=" + currentTime + " " + "nextTimeWindow=" + this.nextTimeWindow + " currentLocalCount=" + localCount + " Tier=" + configuration.getID() + " nextAccessTime=" + this.nextAccessTime); + "Access allowed=" + maxRequest + " available=" + (maxRequest - (this.globalCount.get() + this.localCount.get())) + " key=" + this.getId() + " currentGlobalCount=" + globalCount + " currentTime=" + currentTime + " " + "nextTimeWindow=" + this.nextTimeWindow + " currentLocalCount=" + localCount + " " + "Tier=" + configuration.getID() log.debug("Caller=" + this.getId() + " has reset counters and added for replication when unit " + "time is not over");