[wsas-java-dev] svn commit r9776 - 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/handler
mar/src/main/resources/META-INF
mar/src/main/resources/resources/policy
svn at wso2.org
svn at wso2.org
Wed Nov 14 21:05:13 PST 2007
Author: indika
Date: Wed Nov 14 21:04:54 2007
New Revision: 9776
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/ThrottleConstants.java
branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseThrottleConfiguration.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/IPBaseThrottleConfiguration.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/handler/ThrottleHandler.java
branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/resources/META-INF/module.xml
branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/resources/resources/policy/default_module_policy.xml
Log:
fixed NPE when throttle in cluster (due to trancient lock object)
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 21:04:54 2007
@@ -111,7 +111,7 @@
if (caller != null) {
long currentTime = System.currentTimeMillis();
- if (!caller.canAccess(throttleContext,configuration, currentTime)) {
+ if (!caller.canAccess(throttleContext, configuration, currentTime)) {
//if current caller cannot access , then perform cleaning
log.info(ACCESS_DENIED_TEMPORALLY);
throttleContext.processCleanList(currentTime);
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 21:04:54 2007
@@ -98,7 +98,7 @@
*/
public boolean canAccessIfUnitTimeNotOver(CallerConfiguration configurationIPBased, ThrottleContext throttleContext, long currentTime) throws ThrottleException {
boolean canAcess = false;
- int maxRequest =configurationIPBased.getMaximumRequestPerUnitTime();
+ int maxRequest = configurationIPBased.getMaximumRequestPerUnitTime();
if (!(maxRequest == 0)) {
if (count <= maxRequest - 1) {
if (log.isDebugEnabled()) {
@@ -120,7 +120,7 @@
} else {
//if there is a prohibit time period in configuartion ,then
//set it as prohibit period
- this.nextAccessTime = currentTime +prohititTime;
+ this.nextAccessTime = currentTime + prohititTime;
}
if (log.isDebugEnabled()) {
String type = ThrottleConstants.IP_BASE == configurationIPBased.getType() ? "IP address" : "domain";
Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottleConstants.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottleConstants.java (original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottleConstants.java Wed Nov 14 21:04:54 2007
@@ -22,7 +22,7 @@
public final class ThrottleConstants {
public static final int IP_BASE = 0;
-
+
public static final int DOMAIN_BASE = 1;
public static final int GLOBAL_THROTTLE = 0;
Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseThrottleConfiguration.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseThrottleConfiguration.java (original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseThrottleConfiguration.java Wed Nov 14 21:04:54 2007
@@ -33,113 +33,113 @@
public class DomainBaseThrottleConfiguration implements Serializable, ThrottleConfiguration {
- /**
- * Log for this class
- */
- private static Log log = LogFactory.getLog(DomainBaseThrottleConfiguration.class.getName());
- /**
- * The key for Other configuration
- */
- private String keyOfOther;
- /**
- * The default configuration for a throttle and this will apply to callersMap that have not a custom configuration
- */
- private CallerConfiguration defaultCallerConfiguration;
- /**
- * To hold configurations
- */
- private TreeMap configurationsMap;
- private static final long serialVersionUID = -6548042636191873581L;
-
- /**
- * The Deault Constructor for Throttle Bean
- */
- public DomainBaseThrottleConfiguration() {
- this.configurationsMap = new TreeMap();
- }
-
- /**
- * To get a DomainBaseCallerConfiguration
- *
- * @param ID
- * @return DomainBaseCallerConfiguration
- */
- public CallerConfiguration getCallerConfiguration(Object ID) {
-
- if (ID.equals(ThrottleConstants.KEY_OF_DEFAULT_CONFIGURATION_FOR_OTHER)) {
- return defaultCallerConfiguration;
- } else {
- String key = (String) getConfigurationKeyOfCaller(ID);
- if (key != null) {
- if (key.equals(ThrottleConstants.KEY_OF_DEFAULT_CONFIGURATION_FOR_OTHER)) {
- return defaultCallerConfiguration;
- }
- return (CallerConfiguration) configurationsMap.get(key);
- }
- }
- return null;
- }
-
- /**
- * To get map of configurations
- *
- * @return TreeMap
- */
- public TreeMap getConfigurations() {
- return this.configurationsMap;
- }
-
-
- /**
- * To set map of configurations
- *
- * @param map
- */
- public void setConfigurations(TreeMap map) {
- this.configurationsMap = map;
- }
-
- /**
- * To add a DomainBaseCallerConfiguration
- *
- * @param configuration
- */
- public void addCallerConfiguration(CallerConfiguration configuration) {
- String key = configuration.getID();
- if (key.equals(ThrottleConstants.KEY_OF_DEFAULT_CONFIGURATION_FOR_OTHER)) {
- keyOfOther = ThrottleConstants.KEY_OF_DEFAULT_CONFIGURATION_FOR_OTHER;
- defaultCallerConfiguration = configuration;
- } else {
- configurationsMap.put(key, configuration);
- }
- }
-
- /**
- * To get key for access configuration
- *
- * @param callerID
- * @return Object-String representation of corrected epr-key for get configuration
- */
- public Object getConfigurationKeyOfCaller(Object callerID) {
-
- if (callerID != null) {
- String domain = (String) callerID;
- //if there is a unique Domain
- if (configurationsMap.containsKey(domain)) {
- return domain;
- } else {
- int index = domain.indexOf(".");
- if (index > 0) {
- String rootDomain = domain.substring(index + 1, domain.length());
- return getConfigurationKeyOfCaller(rootDomain);
- }
- }
- }
- return keyOfOther;
- }
-
- public int getType() {
- return ThrottleConstants.DOMAIN_BASE;
- }
+ /**
+ * Log for this class
+ */
+ private static Log log = LogFactory.getLog(DomainBaseThrottleConfiguration.class.getName());
+ /**
+ * The key for Other configuration
+ */
+ private String keyOfOther;
+ /**
+ * The default configuration for a throttle and this will apply to callersMap that have not a custom configuration
+ */
+ private CallerConfiguration defaultCallerConfiguration;
+ /**
+ * To hold configurations
+ */
+ private TreeMap configurationsMap;
+ private static final long serialVersionUID = -6548042636191873581L;
+
+ /**
+ * The Deault Constructor for Throttle Bean
+ */
+ public DomainBaseThrottleConfiguration() {
+ this.configurationsMap = new TreeMap();
+ }
+
+ /**
+ * To get a DomainBaseCallerConfiguration
+ *
+ * @param ID
+ * @return DomainBaseCallerConfiguration
+ */
+ public CallerConfiguration getCallerConfiguration(Object ID) {
+
+ if (ID.equals(ThrottleConstants.KEY_OF_DEFAULT_CONFIGURATION_FOR_OTHER)) {
+ return defaultCallerConfiguration;
+ } else {
+ String key = (String) getConfigurationKeyOfCaller(ID);
+ if (key != null) {
+ if (key.equals(ThrottleConstants.KEY_OF_DEFAULT_CONFIGURATION_FOR_OTHER)) {
+ return defaultCallerConfiguration;
+ }
+ return (CallerConfiguration) configurationsMap.get(key);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * To get map of configurations
+ *
+ * @return TreeMap
+ */
+ public TreeMap getConfigurations() {
+ return this.configurationsMap;
+ }
+
+
+ /**
+ * To set map of configurations
+ *
+ * @param map
+ */
+ public void setConfigurations(TreeMap map) {
+ this.configurationsMap = map;
+ }
+
+ /**
+ * To add a DomainBaseCallerConfiguration
+ *
+ * @param configuration
+ */
+ public void addCallerConfiguration(CallerConfiguration configuration) {
+ String key = configuration.getID();
+ if (key.equals(ThrottleConstants.KEY_OF_DEFAULT_CONFIGURATION_FOR_OTHER)) {
+ keyOfOther = ThrottleConstants.KEY_OF_DEFAULT_CONFIGURATION_FOR_OTHER;
+ defaultCallerConfiguration = configuration;
+ } else {
+ configurationsMap.put(key, configuration);
+ }
+ }
+
+ /**
+ * To get key for access configuration
+ *
+ * @param callerID
+ * @return Object-String representation of corrected epr-key for get configuration
+ */
+ public Object getConfigurationKeyOfCaller(Object callerID) {
+
+ if (callerID != null) {
+ String domain = (String) callerID;
+ //if there is a unique Domain
+ if (configurationsMap.containsKey(domain)) {
+ return domain;
+ } else {
+ int index = domain.indexOf(".");
+ if (index > 0) {
+ String rootDomain = domain.substring(index + 1, domain.length());
+ return getConfigurationKeyOfCaller(rootDomain);
+ }
+ }
+ }
+ return keyOfOther;
+ }
+
+ public int getType() {
+ return ThrottleConstants.DOMAIN_BASE;
+ }
}
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 21:04:54 2007
@@ -48,14 +48,10 @@
*/
private long nextCleanTime;
/**
- * The Object for used to lock in synchronizing
- */
- private final transient Object lock = new Object();
- /**
* The configuration of a throtle
*/
private ThrottleConfiguration throttleConfiguration;
-
+
private static final long serialVersionUID = -7765899274408287393L;
/**
@@ -89,30 +85,27 @@
* @param ID
* @return CallerDomain
*/
- public Caller getCaller(Object ID) {
+ public synchronized Caller getCaller(Object ID) {
String keyOfConfiguration = (String) throttleConfiguration.getConfigurationKeyOfCaller(ID);
if (keyOfConfiguration != null) {
- synchronized (lock) {
- Long timeKeyOfCallerContext = (Long) keyToTimeStampMap.get(keyOfConfiguration);
- if (timeKeyOfCallerContext != null) {
- Object callerObject = callersMap.get(timeKeyOfCallerContext);
- if (callerObject != null) {
- if (callerObject instanceof Caller) {
- return (Caller) callerObject;
- } else if (callerObject instanceof LinkedList) {
- LinkedList callersWithSameTimeStampList = (LinkedList) callerObject;
- for (Iterator iterator = callersWithSameTimeStampList.iterator(); iterator.hasNext();)
- {
- Caller caller = (Caller) iterator.next();
- if (caller != null && keyOfConfiguration.equals(throttleConfiguration.getConfigurationKeyOfCaller(caller.getID()))) {
- return caller;
- }
+ Long timeKeyOfCallerContext = (Long) keyToTimeStampMap.get(keyOfConfiguration);
+ if (timeKeyOfCallerContext != null) {
+ Object callerObject = callersMap.get(timeKeyOfCallerContext);
+ if (callerObject != null) {
+ if (callerObject instanceof Caller) {
+ return (Caller) callerObject;
+ } else if (callerObject instanceof LinkedList) {
+ LinkedList callersWithSameTimeStampList = (LinkedList) callerObject;
+ for (Iterator iterator = callersWithSameTimeStampList.iterator(); iterator.hasNext();)
+ {
+ Caller caller = (Caller) iterator.next();
+ if (caller != null && keyOfConfiguration.equals(throttleConfiguration.getConfigurationKeyOfCaller(caller.getID()))) {
+ return caller;
}
-
}
+
}
}
-
}
}
return null;
@@ -124,6 +117,9 @@
* @param throttleConfiguration
*/
public void setThrottleConfiguration(ThrottleConfiguration throttleConfiguration) {
+ if (throttleConfiguration == null) {
+ throw new IllegalArgumentException("Throttle Configuration cann't be null");
+ }
this.throttleConfiguration = throttleConfiguration;
}
@@ -132,12 +128,12 @@
*
* @param caller
*/
- public void addCaller(Caller caller) {
- if(caller != null){
- String keyOfConfiguration = (String) throttleConfiguration.getConfigurationKeyOfCaller(caller.getID());
- if (keyOfConfiguration != null) {
- setCaller(caller, keyOfConfiguration);
- }
+ public synchronized void addCaller(Caller caller) {
+ if (caller != null) {
+ String keyOfConfiguration = (String) throttleConfiguration.getConfigurationKeyOfCaller(caller.getID());
+ if (keyOfConfiguration != null) {
+ setCaller(caller, keyOfConfiguration);
+ }
}
}
@@ -149,32 +145,29 @@
*/
private void setCaller(Caller caller, String keyOfConfiguration) {
Long time = new Long(caller.getNextTimeWindow());
- synchronized (lock) {
- if (!callersMap.containsKey(time)) {
- callersMap.put(time, caller);
- } else {
- //if there are callersMap with same timewindow ,then use linkedList to hold those
- LinkedList callersWithSameTimeStampList = null;
- Object callerObject = callersMap.get(time);
- if (callerObject != null) {
- if (callerObject instanceof Caller) {
- callersWithSameTimeStampList = new LinkedList();
- callersWithSameTimeStampList.add(callerObject);
- callersWithSameTimeStampList.add(caller);
- callersMap.remove(time);
- } else if (callerObject instanceof LinkedList) {
- callersWithSameTimeStampList = (LinkedList) callerObject;
- callersWithSameTimeStampList.add(caller);
- }
- if (callersWithSameTimeStampList != null) {
- callersMap.put(time, callersWithSameTimeStampList);
- }
+ if (!callersMap.containsKey(time)) {
+ callersMap.put(time, caller);
+ } else {
+ //if there are callersMap with same timewindow ,then use linkedList to hold those
+ LinkedList callersWithSameTimeStampList = null;
+ Object callerObject = callersMap.get(time);
+ if (callerObject != null) {
+ if (callerObject instanceof Caller) {
+ callersWithSameTimeStampList = new LinkedList();
+ callersWithSameTimeStampList.add(callerObject);
+ callersWithSameTimeStampList.add(caller);
+ callersMap.remove(time);
+ } else if (callerObject instanceof LinkedList) {
+ callersWithSameTimeStampList = (LinkedList) callerObject;
+ callersWithSameTimeStampList.add(caller);
+ }
+ if (callersWithSameTimeStampList != null) {
+ callersMap.put(time, callersWithSameTimeStampList);
}
}
- //set Time Vs key
- keyToTimeStampMap.put(keyOfConfiguration, time);
-
}
+ //set Time Vs key
+ keyToTimeStampMap.put(keyOfConfiguration, time);
}
/**
@@ -182,7 +175,7 @@
*
* @param ID
*/
- public void removeCaller(Object ID) {
+ public synchronized void removeCaller(Object ID) {
if (ID instanceof Long) {
removeCaller((Long) ID);
} else {
@@ -202,9 +195,7 @@
* @param key
*/
private void removeCaller(Long key) {
- synchronized (lock) {
- callersMap.remove(key);
- }
+ callersMap.remove(key);
}
/**
@@ -212,36 +203,35 @@
*
* @param currentTime - Current System Time
* @throws org.wso2.throttle.ThrottleException
+ *
*/
- public void processCleanList(long currentTime) throws ThrottleException {
- synchronized (lock) {
- if (currentTime > nextCleanTime) {
- SortedMap sortedMap = callersMap.headMap(new Long(currentTime));
- if (sortedMap != null && sortedMap.size() > 0) {
- for (Iterator callersIterator = sortedMap.values().iterator(); callersIterator.hasNext();)
- {
- Object callerObject = callersIterator.next();
- if (callerObject != null) {
- if (callerObject instanceof Caller) { // In the case nextAccessTime is unique for the caller
- Caller caller = ((Caller) callerObject);
- 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;
- for (Iterator iterator = callersWithSameTimeStampList.iterator(); iterator.hasNext();)
- {
- Caller caller = (Caller) iterator.next();
- if (caller != null) {
- caller.canAccessIfUnitTimeOver(this.throttleConfiguration.getCallerConfiguration(caller.getID()), this, currentTime);
- }
+ public synchronized void processCleanList(long currentTime) throws ThrottleException {
+ if (currentTime > nextCleanTime) {
+ SortedMap sortedMap = callersMap.headMap(new Long(currentTime));
+ if (sortedMap != null && sortedMap.size() > 0) {
+ for (Iterator callersIterator = sortedMap.values().iterator(); callersIterator.hasNext();)
+ {
+ Object callerObject = callersIterator.next();
+ if (callerObject != null) {
+ if (callerObject instanceof Caller) { // In the case nextAccessTime is unique for the caller
+ Caller caller = ((Caller) callerObject);
+ 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;
+ for (Iterator iterator = callersWithSameTimeStampList.iterator(); iterator.hasNext();)
+ {
+ Caller caller = (Caller) iterator.next();
+ if (caller != null) {
+ caller.canAccessIfUnitTimeOver(this.throttleConfiguration.getCallerConfiguration(caller.getID()), this, currentTime);
}
}
}
}
}
- nextCleanTime = currentTime + ThrottleConstants.DEFAULT_THROTTLE_CLEAN_PERIOD;
}
+ nextCleanTime = currentTime + ThrottleConstants.DEFAULT_THROTTLE_CLEAN_PERIOD;
}
}
Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleConfiguration.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleConfiguration.java (original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleConfiguration.java Wed Nov 14 21:04:54 2007
@@ -47,7 +47,7 @@
* To hold configurations
*/
private TreeMap configurationsMap;
-
+
private static final long serialVersionUID = -8660015469066052414L;
/**
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 21:04:54 2007
@@ -49,10 +49,6 @@
*/
private long nextCleanTime;
/**
- * The Object for used to lock in synchronizing
- */
- private final transient Object lock = new Object();
- /**
* The configuration of a throtle
*/
private ThrottleConfiguration throttleConfiguration;
@@ -85,30 +81,28 @@
* @param ID
* @return CallerIP
*/
- public Caller getCaller(Object ID) {
+ public synchronized Caller getCaller(Object ID) {
String keyOfConfiguration = (String) throttleConfiguration.getConfigurationKeyOfCaller(ID);
if (keyOfConfiguration != null) {
- synchronized (lock) {
- Long timeKeyOfCallerContext = (Long) keyToTimeStampMap.get(keyOfConfiguration);
- if (timeKeyOfCallerContext != null) {
- Object callerObject = callersMap.get(timeKeyOfCallerContext);
- if (callerObject != null) {
- if (callerObject instanceof Caller) {
- return (Caller) callerObject;
- } else if (callerObject instanceof LinkedList) {
- LinkedList callersWithSameTimeStampList = (LinkedList) callerObject;
- for (Iterator iterator = callersWithSameTimeStampList.iterator(); iterator.hasNext();)
- {
- Caller caller = (Caller) iterator.next();
- if (caller != null && keyOfConfiguration.equals(throttleConfiguration.getConfigurationKeyOfCaller(caller.getID()))) {
- return caller;
- }
+ Long timeKeyOfCallerContext = (Long) keyToTimeStampMap.get(keyOfConfiguration);
+ if (timeKeyOfCallerContext != null) {
+ Object callerObject = callersMap.get(timeKeyOfCallerContext);
+ if (callerObject != null) {
+ if (callerObject instanceof Caller) {
+ return (Caller) callerObject;
+ } else if (callerObject instanceof LinkedList) {
+ LinkedList callersWithSameTimeStampList = (LinkedList) callerObject;
+ for (Iterator iterator = callersWithSameTimeStampList.iterator(); iterator.hasNext();)
+ {
+ Caller caller = (Caller) iterator.next();
+ if (caller != null && keyOfConfiguration.equals(throttleConfiguration.getConfigurationKeyOfCaller(caller.getID()))) {
+ return caller;
}
}
}
}
-
}
+
}
return null;
}
@@ -127,7 +121,7 @@
*
* @param caller
*/
- public void addCaller(Caller caller) {
+ public synchronized void addCaller(Caller caller) {
String keyOfConfiguration = (String) throttleConfiguration.getConfigurationKeyOfCaller(caller.getID());
if (keyOfConfiguration != null) {
@@ -143,32 +137,30 @@
*/
private void setCaller(Caller caller, String keyOfConfiguration) {
Long time = new Long(caller.getNextTimeWindow());
- synchronized (lock) {
- if (!callersMap.containsKey(time)) {
- callersMap.put(time, caller);
- } else {
- //if there are callersMap with same timewindow ,then use linkedList to hold those
- LinkedList callersWithSameTimeStampList = null;
- Object callerObject = callersMap.get(time);
- if (callerObject != null) {
- if (callerObject instanceof Caller) {
- callersWithSameTimeStampList = new LinkedList();
- callersWithSameTimeStampList.add(callerObject);
- callersWithSameTimeStampList.add(caller);
- callersMap.remove(time);
- } else if (callerObject instanceof LinkedList) {
- callersWithSameTimeStampList = (LinkedList) callerObject;
- callersWithSameTimeStampList.add(caller);
- }
- if (callersWithSameTimeStampList != null) {
- callersMap.put(time, callersWithSameTimeStampList);
- }
+ if (!callersMap.containsKey(time)) {
+ callersMap.put(time, caller);
+ } else {
+ //if there are callersMap with same timewindow ,then use linkedList to hold those
+ LinkedList callersWithSameTimeStampList = null;
+ Object callerObject = callersMap.get(time);
+ if (callerObject != null) {
+ if (callerObject instanceof Caller) {
+ callersWithSameTimeStampList = new LinkedList();
+ callersWithSameTimeStampList.add(callerObject);
+ callersWithSameTimeStampList.add(caller);
+ callersMap.remove(time);
+ } else if (callerObject instanceof LinkedList) {
+ callersWithSameTimeStampList = (LinkedList) callerObject;
+ callersWithSameTimeStampList.add(caller);
+ }
+ if (callersWithSameTimeStampList != null) {
+ callersMap.put(time, callersWithSameTimeStampList);
}
}
- //set Time Vs key
- keyToTimeStampMap.put(keyOfConfiguration, time);
-
}
+ //set Time Vs key
+ keyToTimeStampMap.put(keyOfConfiguration, time);
+
}
/**
@@ -176,7 +168,7 @@
*
* @param ID
*/
- public void removeCaller(Object ID) {
+ public synchronized void removeCaller(Object ID) {
if (ID instanceof Long) {
removeCaller((Long) ID);
} else {
@@ -196,9 +188,7 @@
* @param key
*/
private void removeCaller(Long key) {
- synchronized (lock) {
- callersMap.remove(key);
- }
+ callersMap.remove(key);
}
/**
@@ -208,34 +198,32 @@
* @throws ThrottleException
*/
- public void processCleanList(long currentTime) throws ThrottleException {
- synchronized (lock) {
- if (currentTime > nextCleanTime) {
- SortedMap sortedMap = callersMap.headMap(new Long(currentTime));
- if (sortedMap != null && sortedMap.size() > 0) {
- for (Iterator callersIterator = sortedMap.values().iterator(); callersIterator.hasNext();)
- {
- Object callerObject = callersIterator.next();
- if (callerObject != null) {
- if (callerObject instanceof Caller) { // In the case nextAccessTime is unique for the caller
- Caller caller = ((Caller) callerObject);
- 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;
- for (Iterator iterator = callersWithSameTimeStampList.iterator(); iterator.hasNext();)
- {
- Caller caller = (Caller) iterator.next();
- if (caller != null) {
- caller.canAccessIfUnitTimeOver(this.throttleConfiguration.getCallerConfiguration(caller.getID()), this, currentTime);
- }
+ public synchronized void processCleanList(long currentTime) throws ThrottleException {
+ if (currentTime > nextCleanTime) {
+ SortedMap sortedMap = callersMap.headMap(new Long(currentTime));
+ if (sortedMap != null && sortedMap.size() > 0) {
+ for (Iterator callersIterator = sortedMap.values().iterator(); callersIterator.hasNext();)
+ {
+ Object callerObject = callersIterator.next();
+ if (callerObject != null) {
+ if (callerObject instanceof Caller) { // In the case nextAccessTime is unique for the caller
+ Caller caller = ((Caller) callerObject);
+ 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;
+ for (Iterator iterator = callersWithSameTimeStampList.iterator(); iterator.hasNext();)
+ {
+ Caller caller = (Caller) iterator.next();
+ if (caller != null) {
+ caller.canAccessIfUnitTimeOver(this.throttleConfiguration.getCallerConfiguration(caller.getID()), this, currentTime);
}
}
}
}
}
- nextCleanTime = currentTime + ThrottleConstants.DEFAULT_THROTTLE_CLEAN_PERIOD;
}
+ nextCleanTime = currentTime + ThrottleConstants.DEFAULT_THROTTLE_CLEAN_PERIOD;
}
}
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 21:04:54 2007
@@ -20,14 +20,14 @@
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.clustering.context.Replicator;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.throttle.*;
@@ -67,7 +67,7 @@
public Throttle loadThrottle(MessageContext messageContext,
int throttleType) throws AxisFault, ThrottleException {
- Throttle throttle = null ;
+ Throttle throttle = null;
ConfigurationContext configContext = messageContext.getConfigurationContext();
//the Parameter which hold throttle ipbase object
// to get thottles map from the configuration context
Modified: branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/resources/META-INF/module.xml
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/resources/META-INF/module.xml (original)
+++ branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/resources/META-INF/module.xml Wed Nov 14 21:04:54 2007
@@ -33,20 +33,20 @@
</OutFlow>
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
- xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
- <throttle:ThrottleAssertion>
- <wsp:All>
- <throttle:ID throttle:type="IP">Other</throttle:ID>
- <wsp:ExactlyOne>
- <throttle:IsAllow>true</throttle:IsAllow>
- </wsp:ExactlyOne>
- </wsp:All>
- <wsp:All>
- <throttle:ID throttle:type="DOMAIN">Other</throttle:ID>
- <wsp:ExactlyOne>
- <throttle:IsAllow>true</throttle:IsAllow>
- </wsp:ExactlyOne>
- </wsp:All>
- </throttle:ThrottleAssertion>
+ xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
+ <throttle:ThrottleAssertion>
+ <wsp:All>
+ <throttle:ID throttle:type="IP">Other</throttle:ID>
+ <wsp:ExactlyOne>
+ <throttle:IsAllow>true</throttle:IsAllow>
+ </wsp:ExactlyOne>
+ </wsp:All>
+ <wsp:All>
+ <throttle:ID throttle:type="DOMAIN">Other</throttle:ID>
+ <wsp:ExactlyOne>
+ <throttle:IsAllow>true</throttle:IsAllow>
+ </wsp:ExactlyOne>
+ </wsp:All>
+ </throttle:ThrottleAssertion>
</wsp:Policy>
</module>
\ No newline at end of file
Modified: branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/resources/resources/policy/default_module_policy.xml
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/resources/resources/policy/default_module_policy.xml (original)
+++ branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/resources/resources/policy/default_module_policy.xml Wed Nov 14 21:04:54 2007
@@ -1,17 +1,17 @@
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
- xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
- <throttle:ThrottleAssertion>
- <wsp:All>
- <throttle:ID throttle:type="IP">Other</throttle:ID>
- <wsp:ExactlyOne>
- <throttle:IsAllow>true</throttle:IsAllow>
- </wsp:ExactlyOne>
- </wsp:All>
- <wsp:All>
- <throttle:ID throttle:type="DOMAIN">Other</throttle:ID>
- <wsp:ExactlyOne>
- <throttle:IsAllow>true</throttle:IsAllow>
- </wsp:ExactlyOne>
- </wsp:All>
- </throttle:ThrottleAssertion>
+ xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
+ <throttle:ThrottleAssertion>
+ <wsp:All>
+ <throttle:ID throttle:type="IP">Other</throttle:ID>
+ <wsp:ExactlyOne>
+ <throttle:IsAllow>true</throttle:IsAllow>
+ </wsp:ExactlyOne>
+ </wsp:All>
+ <wsp:All>
+ <throttle:ID throttle:type="DOMAIN">Other</throttle:ID>
+ <wsp:ExactlyOne>
+ <throttle:IsAllow>true</throttle:IsAllow>
+ </wsp:ExactlyOne>
+ </wsp:All>
+ </throttle:ThrottleAssertion>
</wsp:Policy>
\ No newline at end of file
More information about the Wsas-java-dev
mailing list