[wsas-java-dev] svn commit r9757 - in
branches/wsas/java/2.1/commons/throttle/modules:
core/src/main/java/org/wso2/throttle
core/src/main/java/org/wso2/throttle/impl/domainbase
core/src/main/java/org/wso2/throttle/impl/ipbase
mar/src/main/java/org/wso2/throttle/module
mar/src/main/java/org/wso2/throttle/module/handler
svn at wso2.org
svn at wso2.org
Wed Nov 14 03:39:59 PST 2007
Author: indika
Date: Wed Nov 14 03:39:46 2007
New Revision: 9757
Modified:
branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/AccessController.java
branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/Caller.java
branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseThrottleContext.java
branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleContext.java
branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/ThrottleModule.java
branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java
Log:
some improvements and fixes ..need more clean up
Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/AccessController.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/AccessController.java (original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/AccessController.java Wed Nov 14 03:39:46 2007
@@ -56,7 +56,7 @@
Object callerID, int callerType) throws ThrottleException {
boolean debugOn = log.isDebugEnabled(); //is debug enable
- String type = ThrottleConstants.IP_BASE == callerType ? "IP address" : "Domain";
+ String type = ThrottleConstants.IP_BASE == callerType ? "IP address" : "domain";
ThrottleConfiguration throttleConfigurationBean = throttleContext.getThrottleConfiguration();
if (throttleConfigurationBean == null) {
@@ -115,7 +115,7 @@
return false;
} else {
if (debugOn) {
- log.debug("Access from " + type + " " + remoteIP + "is successful.");
+ log.debug("Access from " + type + " " + remoteIP + " is successful.");
}
return true;
}
Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/Caller.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/Caller.java (original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/Caller.java Wed Nov 14 03:39:46 2007
@@ -118,7 +118,10 @@
this.nextAccessTime = currentTime +
configurationIPBased.getProhibitTimePeriod();
}
- log.debug("Maximum Number of requests are reached :IP-" + ID);
+ if (log.isDebugEnabled()) {
+ String type = ThrottleConstants.IP_BASE == configurationIPBased.getType() ? "IP address" : "domain";
+ log.debug("Maximum Number of requests are reached for caller with " + type + "-" + ID);
+ }
} else {
// else , if the caller has already prohabit and prohabit
@@ -129,13 +132,15 @@
canAcess = true;
count = 1;
this.firstAccessTime = currentTime;
- if (this.nextTimeWindow != 0) {
- throttleContext.removeCaller(new Long(nextTimeWindow));
- }
+// if (this.nextTimeWindow != 0) {
+// throttleContext.removeCaller(new Long(nextTimeWindow));
+// }
this.nextTimeWindow = currentTime + configurationIPBased.getUnitTimeInMiliSecond();
} else {
- log.debug("Prohibit period is not yet over :IP- " + ID);
-
+ if (log.isDebugEnabled()) {
+ String type = ThrottleConstants.IP_BASE == configurationIPBased.getType() ? "IP address" : "domain";
+ log.debug("Prohibit period is not yet over for caller with " + type + "- " + ID);
+ }
}
}
}
@@ -157,13 +162,13 @@
boolean canAcess = false;
// if number of access for a unit time is less than MAX and
// if the unit time period (session time) has just overed
- if (!(configurationIPBased.getMaximumRequestPerUnitTime() == 0)) {
- if (this.count <= configurationIPBased.getMaximumRequestPerUnitTime() - 1) {
+ int maxRequest = configurationIPBased.getMaximumRequestPerUnitTime();
+ if (!(maxRequest == 0)) {
+ if (this.count <= maxRequest - 1) {
if (this.nextTimeWindow != 0) {
throttleContext.removeCaller(new Long(nextTimeWindow));
}
canAcess = true; // this is bounus access
- count = 1;
//next time callers can access as a new one
} else {
// if number of access for a unit time has just been greater than MAX
@@ -176,15 +181,17 @@
canAcess = true;
count = 1;// can access the system and this is same as fristAccess
this.firstAccessTime = currentTime;
- if (this.nextTimeWindow != 0) {
- throttleContext.removeCaller(new Long(nextTimeWindow));
- }
+// if (this.nextTimeWindow != 0) {
+// throttleContext.removeCaller(new Long(nextTimeWindow));
+// }
this.nextTimeWindow = currentTime + configurationIPBased.getUnitTimeInMiliSecond();
} else {
// if caller in prohabit session and prohabit period has not overed
- log.debug("Even unit time has overed , CallerIP in prohibit state :IP -" + ID);
-
+ if (log.isDebugEnabled()) {
+ String type = ThrottleConstants.IP_BASE == configurationIPBased.getType() ? "IP address" : "domain";
+ log.debug("Even unit time has overed , Caller in prohibit state :" + type + " -" + ID);
+ }
}
}
@@ -200,10 +207,8 @@
* @return boolean -The boolean value which say access will allolw or not
* @throws ThrottleException
*/
- public boolean canAccess(ThrottleContext throttleContext, CallerConfiguration callerConfiguration,long currentTime) throws ThrottleException {
+ public boolean canAccess(ThrottleContext throttleContext, CallerConfiguration callerConfiguration, long currentTime) throws ThrottleException {
boolean canAcess = false;
- ThrottleConfiguration throttleConfiguration = throttleContext.getThrottleConfiguration();
-// CallerConfiguration callerConfiguration = throttleConfiguration.getCallerConfiguration(getID());
if (callerConfiguration == null) {
return false;
}
Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseThrottleContext.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseThrottleContext.java (original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseThrottleContext.java Wed Nov 14 03:39:46 2007
@@ -220,7 +220,7 @@
if (callerObject != null) {
if (callerObject instanceof Caller) { // In the case nextAccessTime is unique for the caller
Caller caller = ((Caller) callerObject);
- caller.canAccessIfUnitTimeOver(this.getThrottleConfiguration().getCallerConfiguration(caller.getID()), this, currentTime);
+ caller.canAccessIfUnitTimeOver(this.throttleConfiguration.getCallerConfiguration(caller.getID()), this, currentTime);
} else
if (callerObject instanceof LinkedList) { //In the case nextAccessTime of multDomainle callers are same
LinkedList callersWithSameTimeStampList = (LinkedList) callerObject;
@@ -228,7 +228,7 @@
{
Caller caller = (Caller) iterator.next();
if (caller != null) {
- caller.canAccessIfUnitTimeOver(this.getThrottleConfiguration().getCallerConfiguration(caller.getID()), this, currentTime);
+ caller.canAccessIfUnitTimeOver(this.throttleConfiguration.getCallerConfiguration(caller.getID()), this, currentTime);
}
}
}
Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleContext.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleContext.java (original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleContext.java Wed Nov 14 03:39:46 2007
@@ -220,7 +220,7 @@
if (callerObject != null) {
if (callerObject instanceof Caller) { // In the case nextAccessTime is unique for the caller
Caller caller = ((Caller) callerObject);
- caller.canAccessIfUnitTimeOver(this.getThrottleConfiguration().getCallerConfiguration(caller.getID()), this, currentTime);
+ caller.canAccessIfUnitTimeOver(this.throttleConfiguration.getCallerConfiguration(caller.getID()), this, currentTime);
} else
if (callerObject instanceof LinkedList) { //In the case nextAccessTime of multiple callers are same
LinkedList callersWithSameTimeStampList = (LinkedList) callerObject;
@@ -228,7 +228,7 @@
{
Caller caller = (Caller) iterator.next();
if (caller != null) {
- caller.canAccessIfUnitTimeOver(this.getThrottleConfiguration().getCallerConfiguration(caller.getID()), this, currentTime);
+ caller.canAccessIfUnitTimeOver(this.throttleConfiguration.getCallerConfiguration(caller.getID()), this, currentTime);
}
}
}
Modified: branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/ThrottleModule.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/ThrottleModule.java (original)
+++ branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/ThrottleModule.java Wed Nov 14 03:39:46 2007
@@ -95,23 +95,25 @@
String currentServiceName;
if (axisDescription instanceof AxisService) {
- Throttle throttle;
+ Throttle throttle = null;
AxisService currentService = ((AxisService) axisDescription);
- AxisModule module = currentService.getAxisConfiguration().getModule(this.name);
+// AxisModule module = currentService.getAxisConfiguration().getModule(this.name);
PolicyInclude policyInclude = currentService.getPolicyInclude();
if (policyInclude != null) {
try {
Policy currentPolicy = policyInclude.getPolicy();
if (currentPolicy == null) {
currentPolicy = policyInclude.getEffectivePolicy();
- if (currentPolicy == null) {
- policyInclude = module.getPolicyInclude();
- if (policyInclude != null) {
- currentPolicy = policyInclude.getEffectivePolicy();
- }
- }
+// if (currentPolicy == null) {
+// policyInclude = module.getPolicyInclude();
+// if (policyInclude != null) {
+// currentPolicy = policyInclude.getEffectivePolicy();
+// }
+// }
+ }
+ if (currentPolicy != null) {
+ throttle = ThrottlePolicyProcessor.processPolicy(currentPolicy);
}
- throttle = ThrottlePolicyProcessor.processPolicy(currentPolicy);
}
catch (ThrottleException e) {
@@ -134,24 +136,26 @@
}
} else if (axisDescription instanceof AxisOperation) {
- Throttle throttle;
+ Throttle throttle = null;
AxisOperation currentOperation = ((AxisOperation) axisDescription);
currentServiceName = ((AxisService) currentOperation.getParent()).getName();
- AxisModule module = currentOperation.getAxisConfiguration().getModule(this.name);
+// AxisModule module = currentOperation.getAxisConfiguration().getModule(this.name);
PolicyInclude policyInclude = currentOperation.getPolicyInclude();
if (policyInclude != null) {
try {
Policy currentPolicy = policyInclude.getPolicy();
if (currentPolicy == null) {
currentPolicy = policyInclude.getEffectivePolicy();
- if (currentPolicy == null) {
- policyInclude = module.getPolicyInclude();
- if (policyInclude != null) {
- currentPolicy = policyInclude.getEffectivePolicy();
- }
- }
+// if (currentPolicy == null) {
+// policyInclude = module.getPolicyInclude();
+// if (policyInclude != null) {
+// currentPolicy = policyInclude.getEffectivePolicy();
+// }
+// }
+ }
+ if (currentPolicy != null) {
+ throttle = ThrottlePolicyProcessor.processPolicy(currentPolicy);
}
- throttle = ThrottlePolicyProcessor.processPolicy(currentPolicy);
}
catch (ThrottleException e) {
Modified: branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java (original)
+++ branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java Wed Nov 14 03:39:46 2007
@@ -20,6 +20,8 @@
import org.apache.axis2.AxisFault;
+import org.apache.axis2.clustering.context.Replicator;
+import org.apache.axis2.clustering.ClusteringFault;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
@@ -128,12 +130,10 @@
public void process(Throttle throttle,
MessageContext messageContext) throws ThrottleException, AxisFault {
- boolean canAccess = doConcurrentThrottling(throttle, messageContext);
- if (canAccess) { // if the access is success then
+ ConcurrentAccessController concurrentAccessController = throttle.getConcurrentAccessController();
- if (log.isDebugEnabled()) {
- log.debug("Access success from concurrent throttlling");
- }
+ boolean canAccess = doConcurrentThrottling(concurrentAccessController, messageContext);
+ if (canAccess) { // if the access is success then
if (messageContext.getFLOW() == MessageContext.IN_FLOW) {
// do the normal throttling
@@ -146,36 +146,58 @@
}
ThrottleContext throttleContext = null;
if (domainName != null) {
+
throttleContext =
throttle.getThrottleContext(ThrottleConstants.DOMAIN_BASED_THROTTLE_KEY);
+
if (throttleContext != null) {
- if (!accessController.canAccess(throttleContext, domainName, ThrottleConstants.DOMAIN_BASE)) {
- throw new AxisFault("A caller with domain " + domainName + " cannot access this service since " +
- "the allocated quota have been exceeded.");
+
+ if (!accessController.canAccess(throttleContext, domainName,
+ ThrottleConstants.DOMAIN_BASE)) {
+ if (concurrentAccessController != null) {
+ concurrentAccessController.incrementAndGet();
+ }
+ try {
+ Replicator.replicate(messageContext.getConfigurationContext());
+ } catch (ClusteringFault clusteringFault) {
+ log.error("Error during replicate states ", clusteringFault);
+ }
+ throw new AxisFault("A caller with domain " + domainName +
+ " cannot access this service since the allocated quota have been exceeded.");
}
} else {
if (log.isDebugEnabled()) {
- log.debug("Could not find the Throttle Context for Domain-Based Thottling");
+ log.debug("Could not find the Throttle Context for omain-Based Thottling");
}
}
} else {
if (log.isDebugEnabled()) {
- log.debug("Could not find the Domain of the caller - IP-based throttling may occur");
+ log.debug("Could not find the domain of the caller - IP-based throttling may occur");
}
}
+
if (throttleContext == null) {
String remoteIP = (String) messageContext.getProperty(MessageContext.REMOTE_ADDR);
+
if (remoteIP != null) {
throttleContext =
throttle.getThrottleContext(ThrottleConstants.IP_BASED_THROTTLE_KEY);
+
if (throttleContext != null) {
- ConcurrentAccessController concurrentAccessController = throttle.getConcurrentAccessController();
- if (concurrentAccessController != null) {
- concurrentAccessController.incrementAndGet();
- }
if (!accessController.canAccess(throttleContext, remoteIP, ThrottleConstants.IP_BASE)) {
- throw new AxisFault("A caller with IP " + remoteIP + " cannot access this service since" +
- " the allocated quota have been exceeded.");
+
+ if (concurrentAccessController != null) {
+ concurrentAccessController.incrementAndGet();
+ }
+
+ try {
+ Replicator.replicate(messageContext.getConfigurationContext());
+ } catch (ClusteringFault clusteringFault) {
+ log.error("Error during replicate states ", clusteringFault);
+ }
+
+ throw new AxisFault("A caller with IP " + remoteIP + " " +
+ "cannot access this service since the allocated quota have been exceeded.");
}
} else {
if (log.isDebugEnabled()) {
@@ -186,37 +208,44 @@
if (log.isDebugEnabled()) {
log.debug("Could not find the IP address of the caller - throttling will not occur");
}
-
}
}
}
} else {
- throw new AxisFault("Access deny from concurrent throttlling");
+ try {
+ Replicator.replicate(messageContext.getConfigurationContext());
+ } catch (ClusteringFault clusteringFault) {
+ log.error("Error during replicate states ", clusteringFault);
+ }
+ throw new AxisFault("Access has currently been denied since allowed maximum concurrent access have exceeded");
}
}
- private boolean doConcurrentThrottling(Throttle throttle, MessageContext messageContext) {
+ private boolean doConcurrentThrottling(ConcurrentAccessController concurrentAccessController, MessageContext messageContext) {
- ConcurrentAccessController concurrentAccessController = throttle.getConcurrentAccessController();
boolean canAccess = true;
+ int available = 0;
if (concurrentAccessController != null) {
if (messageContext.getFLOW() == MessageContext.IN_FLOW) {
+ available = concurrentAccessController.getAndDecrement();
+ canAccess = available > 0;
if (log.isDebugEnabled()) {
- log.debug("Incoming message process through the ConcurrentThrottlling");
+ log.debug("Access " + (canAccess ? "allowed" : "denied") +
+ " :: " + available + " of available of " + concurrentAccessController.getLimit() + " connections");
}
- canAccess = concurrentAccessController.getAndDecrement() > 0;
if (log.isDebugEnabled()) {
if (!canAccess) {
- log.debug("Access has currently been denied since allowed maximum concurrent access has exceeded");
+ log.debug("Access has currently been denied since allowed maximum concurrent access have exceeded");
}
}
} else if (messageContext.getFLOW() == MessageContext.OUT_FLOW) {
+ available = concurrentAccessController.incrementAndGet();
if (log.isDebugEnabled()) {
- log.debug("Outcoming message process through the ConcurrentThrottlling");
+ log.debug("Connection returned" +
+ " :: " + available + " of available of " + concurrentAccessController.getLimit() + " connections");
}
- concurrentAccessController.incrementAndGet();
}
}
return canAccess;
@@ -230,10 +259,6 @@
Throttle throttle = loadThrottle(msgContext, getThrottleType());
if (throttle != null) {
process(throttle, msgContext);
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Cannot find throttle configuration. Thottlling will not be occurred");
- }
}
}
catch (ThrottleException e) {
More information about the Wsas-java-dev
mailing list