[wsas-java-dev] svn commit r10400 - in branches/wsas/java/2.1/commons/throttle/modules: core/src/main/java/org/wso2/throttle core/src/main/java/org/wso2/throttle/factory 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

svn at wso2.org svn at wso2.org
Sun Dec 2 22:32:18 PST 2007


Author: indika
Date: Sun Dec  2 22:31:57 2007
New Revision: 10400

Modified:
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/AccessRateController.java
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/CallerConfiguration.java
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/Throttle.java
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottleConfiguration.java
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottleContext.java
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/CallerConfigurationFactory.java
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/CallerContextFactory.java
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/ThrottleConfigurationFactory.java
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/ThrottleContextFactory.java
   branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseCallerConfiguration.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/ipbase/IPBaseThrottleConfiguration.java
   branches/wsas/java/2.1/commons/throttle/modules/mar/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java
Log:
logs improvement + some fixes 


Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/AccessRateController.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/AccessRateController.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/AccessRateController.java	Sun Dec  2 22:31:57 2007
@@ -58,7 +58,7 @@
      * @throws ThrottleException 
      */
     public boolean canAccess(ThrottleContext throttleContext,
-                             Object callerID, int callerType) throws ThrottleException {
+                             String callerID, int callerType) throws ThrottleException {
 
         String type = ThrottleConstants.IP_BASE == callerType ? "IP address" : "domain";
 
@@ -71,26 +71,18 @@
             return true;
         }
 
-        String id = null;
-        if (callerID instanceof String) {
-            id = (String) callerID;
-        } else {
-            if (debugOn) {
-                log.debug("Caller ID should instance of String for Throttle");
-            }
-        }
-        if (id == null) {
+        if (callerID == null) {
             if (debugOn) {
                 log.debug("Caller host or ip  couldn't find !! - Access will be denied ");
             }
             return false;
         }
-
+        
         CallerConfiguration configuration =
-            throttleConfigurationBean.getCallerConfiguration(id);
+            throttleConfigurationBean.getCallerConfiguration(callerID);
         if (configuration == null) {
             if (debugOn) {
-                log.debug("Caller configuration couldn't find for " + type + " and for caller " + id);
+                log.debug("Caller configuration couldn't find for " + type + " and for caller " + callerID);
             }
             return true;
         }
@@ -101,11 +93,11 @@
             return true;
         } else if (configuration.getAccessState() == ThrottleConstants.ACCESS_CONTROLLED) {
             synchronized (lock) {
-                CallerContext caller = throttleContext.getCallerContext(id);
+                CallerContext caller = throttleContext.getCallerContext(callerID);
                 if (caller == null) {
                     //if caller has not already registered ,then create new caller description and
                     //set it in throttle
-                    caller = CallerContextFactory.createCaller(callerType, id);
+                    caller = CallerContextFactory.createCaller(callerType, callerID);
                 }
                 if (caller != null) {
                     long currentTime = System.currentTimeMillis();
@@ -117,13 +109,13 @@
                         return false;
                     } else {
                         if (debugOn) {
-                            log.debug("Access  from " + type + " " + id + " is successful.");
+                            log.debug("Access  from " + type + " " + callerID + " is successful.");
                         }
                         return true;
                     }
                 } else {
                     if (debugOn) {
-                        log.debug("Caller " + type + " not found! " + id);
+                        log.debug("Caller " + type + " not found! " + callerID);
                     }
                     return true;
                 }

Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/CallerConfiguration.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/CallerConfiguration.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/CallerConfiguration.java	Sun Dec  2 22:31:57 2007
@@ -136,7 +136,7 @@
     /**
      * To get ID
      *
-     * @return Object value of ID
+     * @return String value of ID
      */
     public abstract String getID();
 

Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/Throttle.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/Throttle.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/Throttle.java	Sun Dec  2 22:31:57 2007
@@ -22,9 +22,11 @@
 import java.util.Map;
 
 /**
- *The representation for Throttle-hold both runtime and static data.
- *There is a one to one relationship between configuration and context.
- *There may be a concurrent access controller,if the throttle policy has defined  maximum concurrent access .
+ *The representation for Throttle - holds the both of runtime and static data.
+ *There is a one to one relationship between each throttle configuration and context.
+ *Currently support two type of throttle configuration. One is remote caller IP based and
+ *other one is remote caller domain name based.There may be a concurrent access controller,
+ *if the throttle policy has defined the maximum concurrent access .
  */
 
 public class Throttle {
@@ -32,10 +34,10 @@
     /* Holder for ThrottleContext - keeps all runtime data */
     private Map throttleContexts;
 
-    /* Holder for ThrottleConfigurations - keeps all static data (data that have extracted from throttle policy) */
+    /* Holder for ThrottleConfigurations - keeps all static data (data that have extracted from the throttle policy) */
     private Map throttleConfigurations;
 
-    /* ConcurrentAccessController insatnce- this is common to all remote callers - controls the concurrent access */
+    /* ConcurrentAccessController insatnce- This is common to all remote callers - controls the concurrent access through this throttle*/
     private ConcurrentAccessController controller;
     /* unique identifier for each throttle */
     private String id;
@@ -62,7 +64,7 @@
      * Adds a ThrotleContext with the given key - context holds all runtime data for registered callers
      *
      * @param key             - corresponding key for throttle type.This key has one-one relationship with key of configurations
-     * @param throttleContext - holds runtime data - ex: all callers state
+     * @param throttleContext - holds runtime data - ex: all callers states
      */
     public void addThrottleContext(String key, ThrottleContext throttleContext) {
         this.throttleContexts.put(key, throttleContext);

Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottleConfiguration.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottleConfiguration.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottleConfiguration.java	Sun Dec  2 22:31:57 2007
@@ -26,28 +26,28 @@
 public interface ThrottleConfiguration {
 
     /**
-     * To add a CallerConfiguration
+     * To add a CallerConfiguration - The controlling policy for a caller
      *
      * @param callerConfiguration The caller configuration data
      */
     public void addCallerConfiguration(CallerConfiguration callerConfiguration);
 
     /**
-     * To get a CallerConfiguration
+     * To get a CallerConfiguration - The controlling policy for a caller
      *
      * @param ID The ID of the caller (ip/domain name)
      * @return CallerConfiguration
      */
-    public CallerConfiguration getCallerConfiguration(Object ID);
+    public CallerConfiguration getCallerConfiguration(String ID);
 
     /**
-     * To get a access key for caller (In the case of group ID)
+     * To get a access key for a caller (In the case of group ID)
      *
      * @param callerID - The ID of the caller (ip/domain name)
-     * @return Object  -The pre-define key with in policy
+     * @return String  -The pre-define key with in policy
      */
 
-    public Object getConfigurationKeyOfCaller(Object callerID);
+    public String getConfigurationKeyOfCaller(String callerID);
 
     /**
      * To get the type of the throttle

Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottleContext.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottleContext.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/ThrottleContext.java	Sun Dec  2 22:31:57 2007
@@ -84,7 +84,7 @@
      * @param ID the remote caller id ex: domain , ip
      * @return Returns the CallerContext which holds runtime state of a remote caller
      */
-    public CallerContext getCallerContext(Object ID) {
+    public CallerContext getCallerContext(String ID) {
 
         String key = (String) throttleConfiguration.getConfigurationKeyOfCaller(ID);
         if (key != null) {
@@ -190,8 +190,8 @@
     public void removeCallerContext(Object ID) {
         if (ID instanceof Long) {
             removeCaller((Long) ID);
-        } else {
-            String key = (String) throttleConfiguration.getConfigurationKeyOfCaller(ID);
+        } else if (ID instanceof String) {
+            String key = throttleConfiguration.getConfigurationKeyOfCaller((String) ID);
             Long time;
             if (key != null) {
                 time = (Long) keyToTimeStampMap.get(key);

Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/CallerConfigurationFactory.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/CallerConfigurationFactory.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/CallerConfigurationFactory.java	Sun Dec  2 22:31:57 2007
@@ -22,7 +22,7 @@
 import org.wso2.throttle.impl.ipbase.IPBaseCallerConfiguration;
 
 /**
- * Factory for creating CallerConfigurations 
+ * Factory for creating a CallerConfiguration
  *
  */
 

Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/CallerContextFactory.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/CallerContextFactory.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/CallerContextFactory.java	Sun Dec  2 22:31:57 2007
@@ -22,26 +22,26 @@
 import org.wso2.throttle.impl.ipbase.IPBaseCallerContext;
 
 /**
- * Factory for creating CallerContexts
+ * Factory for creating a CallerContext
  *
  */
 
 public class CallerContextFactory {
 
     /**
-     * To create a CallerContext(run time data holder for a remote caller) for the given throttle type.
-     * Needs to provide the ID of the remote caller (ip/domain accoding to the policy)
+     * To create a CallerContext(the run time data holder for a remote caller) for the given throttle type.
+     * Needs to provide the ID(ip | domain) of the remote caller (ip/domain accoding to the policy)
      *
      * @param throttletype  - The type of the throttle
      * @param id            - The id of the caller
      * @return caller       - The corresponding caller context for the given throttle type
      * @throws ThrottleException - Throws for if the throttle type is unknown
      */
-    public static CallerContext createCaller(int throttletype, Object id) throws ThrottleException {
+    public static CallerContext createCaller(int throttletype, String id) throws ThrottleException {
         if (ThrottleConstants.IP_BASE == throttletype) {
-            return new IPBaseCallerContext((String) id);
+            return new IPBaseCallerContext(id);
         } else if (ThrottleConstants.DOMAIN_BASE == throttletype) {
-            return new DomainBaseCallerContext((String) id);
+            return new DomainBaseCallerContext(id);
         } else {
             throw new ThrottleException("unknown throttle type");
         }

Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/ThrottleConfigurationFactory.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/ThrottleConfigurationFactory.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/ThrottleConfigurationFactory.java	Sun Dec  2 22:31:57 2007
@@ -22,7 +22,7 @@
 import org.wso2.throttle.impl.ipbase.IPBaseThrottleConfiguration;
 
 /**
- *Factory for creating ThrottleConfigurations - holds all callers controle parameters
+ *Factory for creating a ThrottleConfiguration - holds all callers controle parameters
  *
  */
 

Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/ThrottleContextFactory.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/ThrottleContextFactory.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/factory/ThrottleContextFactory.java	Sun Dec  2 22:31:57 2007
@@ -23,7 +23,7 @@
 import org.wso2.throttle.impl.ipbase.IPBaseThrottleContext;
 
 /**
- *Factory for creating ThrottleContexts - hold all callers runtime data - current state
+ *Factory for creating a ThrottleContext - holds all callers runtime data - the current state
  *
  */
 
@@ -31,7 +31,7 @@
 
     /**
      * To create a ThrottleContext for the given throttle type
-     * Needs to provide throttle configuration
+     * Needs to provide a throttle configuration
      *
      * @param throttletype  - The type of the throttle
      * @param configuration - The throttle configuration

Modified: branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseCallerConfiguration.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseCallerConfiguration.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/modules/core/src/main/java/org/wso2/throttle/impl/domainbase/DomainBaseCallerConfiguration.java	Sun Dec  2 22:31:57 2007
@@ -26,7 +26,7 @@
  */
 
 public class DomainBaseCallerConfiguration extends CallerConfiguration {
-
+    /* The id - domain name */
     private String id;
 
     public String getID() {

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	Sun Dec  2 22:31:57 2007
@@ -57,12 +57,12 @@
      * @param ID - The Remote caller id (domain name)
      * @return Returns the corresponding configuration for the caller with given ID
      */
-    public CallerConfiguration getCallerConfiguration(Object ID) {
+    public CallerConfiguration getCallerConfiguration(String ID) {
 
         if (ID.equals(ThrottleConstants.KEY_OF_DEFAULT_CONFIGURATION_FOR_OTHER)) {
             return defaultCallerConfiguration;
         } else {
-            String key = (String) getConfigurationKeyOfCaller(ID);
+            String key = getConfigurationKeyOfCaller(ID);
             if (key != null) {
                 if (key.equals(ThrottleConstants.KEY_OF_DEFAULT_CONFIGURATION_FOR_OTHER)) {
                     return defaultCallerConfiguration;
@@ -95,23 +95,27 @@
      * To get key for caller configuration
      * if there is a configuration with callerID , it returns
      * otherwise ,
-     * on the first (if ID is a.a.a), check pattern *.a.a and a.a
-     * then *.*.a or *.a or a
+     * on the first the ID contains one or more "." ,then recursively try to find the nearest root callerID.
+     * else if the ID doesn't contains ".", try to find a key with *.{ID} .
+     * Note : For valid ID , it should contain only  zero or more  "*."  as a prefix.
+     * example:
+     * (if ID is a.a.a), check pattern *.a.a and a.a
+     *     then *.*.a or *.a or a  )
+     * if ID a then check start with *.a
      *
-     * @param callerID The id of the remote caller (domain name)
-     * @return Object-String representation of  corrected epr-key for get configuration
+     * @param callerID The id of the remote caller (callerID name)
+     * @return String value -String representation of  corrected epr-key for get configuration
      */
-    public Object getConfigurationKeyOfCaller(Object callerID) {
+    public String getConfigurationKeyOfCaller(String callerID) {
 
         if (callerID != null) {
-            String domain = (String) callerID;
             //if there is a unique Domain
-            if (configurationsMap.containsKey(domain)) {
-                return domain;
+            if (configurationsMap.containsKey(callerID)) {
+                return callerID;
             } else {
-                int index = domain.indexOf(".");
+                int index = callerID.indexOf(".");
                 if (index > 0) {
-                    String rootDomain = domain.substring(index + 1, domain.length());
+                    String rootDomain = callerID.substring(index + 1, callerID.length());
                     if (rootDomain != null) {
                         String all = "*." + rootDomain;
                         Set keyset = configurationsMap.keySet();
@@ -125,6 +129,17 @@
                         }
                         return getConfigurationKeyOfCaller(rootDomain);
                     }
+                } else {
+                    String all = "*." + callerID;
+                    Set keyset = configurationsMap.keySet();
+                    if (keyset != null && !keyset.isEmpty()) {
+                        for (Iterator iter = keyset.iterator(); iter.hasNext();) {
+                            String key = (String) iter.next();
+                            if (key != null && key.endsWith(all)) {
+                                return key;
+                            }
+                        }
+                    }
                 }
             }
         }

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	Sun Dec  2 22:31:57 2007
@@ -53,12 +53,12 @@
      * @param ID - The Remote caller id (IP)
      * @return Returns the corresponding configuration for the caller with given ID
      */
-    public CallerConfiguration getCallerConfiguration(Object ID) {
+    public CallerConfiguration getCallerConfiguration(String ID) {
 
         if (ID.equals(ThrottleConstants.KEY_OF_DEFAULT_CONFIGURATION_FOR_OTHER)) {
             return defaultCallerConfiguration;
         } else {
-            String key = (String) getConfigurationKeyOfCaller(ID);
+            String key = getConfigurationKeyOfCaller(ID);
             if (key != null) {
                 if (key.equals(ThrottleConstants.KEY_OF_DEFAULT_CONFIGURATION_FOR_OTHER)) {
                     return defaultCallerConfiguration;
@@ -95,18 +95,17 @@
      * @param callerID The remote caller id (ip)
      * @return Object-String representation of  corrected epr-key for get configuration
      */
-    public Object getConfigurationKeyOfCaller(Object callerID) {
+    public String getConfigurationKeyOfCaller(String callerID) {
 
         if (callerID != null) {
-            String ip = (String) callerID;
             //if there is a unique IP
-            if (configurationsMap.containsKey(ip)) {
-                return ip;
+            if (configurationsMap.containsKey(callerID)) {
+                return callerID;
             } else {
-                int index = ip.lastIndexOf(".");
+                int index = callerID.lastIndexOf(".");
                 if (index > 0) {
-                    String net = ip.substring(0, index);     // get the network portion
-                    String host = ip.substring(index + 1, ip.length()); //get the host portion
+                    String net = callerID.substring(0, index);     // get the network portion
+                    String host = callerID.substring(index + 1, callerID.length()); //get the host portion
                     if (net != null && host != null) {
                         Set keys = configurationsMap.keySet();
                         if (keys != null && !keys.isEmpty()) {

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	Sun Dec  2 22:31:57 2007
@@ -183,7 +183,7 @@
 
                 // Domain name based throttling
                 //check whether a configuration has been defined for this domain name or not
-                Object callerId = null;
+                String callerId = null;
                 if (domain != null) {
                     //loads the ThrottleContext
                     ThrottleContext context =




More information about the Wsas-java-dev mailing list