[wsas-java-dev] svn commit r9710 - in branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle: . factory impl/ipbase module/handler

svn at wso2.org svn at wso2.org
Mon Nov 12 07:23:37 PST 2007


Author: indika
Date: Mon Nov 12 07:23:24 2007
New Revision: 9710

Modified:
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/Caller.java
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/CallerConfiguration.java
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ConcurrentAccessController.java
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/Throttle.java
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ThrottleConfiguration.java
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ThrottleException.java
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/factory/CallerFactory.java
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseAccessController.java
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseCaller.java
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseCallerConfiguration.java
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleConfiguration.java
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleContext.java
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java
Log:
fixed to work in cluster 


Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/Caller.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/Caller.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/Caller.java	Mon Nov 12 07:23:24 2007
@@ -21,35 +21,49 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import java.io.Serializable;
+
 /**
  *
  *
  */
 
-public abstract class Caller {
+public abstract class Caller implements Serializable {
 
-    /** Log for this class    */
+    /**
+     * Log for this class
+     */
     private static Log log = LogFactory.getLog(Caller.class.getName());
-    /** next access time     */
+    /**
+     * next access time
+     */
     private long nextAccessTime = 0;
-    /** frist access time    */
+    /**
+     * frist access time
+     */
     private long firstAccessTime = 0;
-    /** The nextTimeWindow - begining of next unit time period- end of current unit time period  */
+    /**
+     * The nextTimeWindow - begining of next unit time period- end of current unit time period
+     */
     private long nextTimeWindow = 0;
-    /** The count to keep track number of request   */
+    /**
+     * The count to keep track number of request
+     */
     private int count = 0;
-     /** The Id of caller */
-    private Object ID;
+    /**
+     * The Id of caller
+     */
+    private String ID;
+    private static final long serialVersionUID = 1652165180220263492L;
 
-    public Caller(Object ID) {
+    public Caller(String ID) {
         this.ID = ID;
     }
 
     /**
-     *
-     * @return  return Id of caller
+     * @return return Id of caller
      */
-    public Object getID() {
+    public String getID() {
         return ID;
     }
 

Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/CallerConfiguration.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/CallerConfiguration.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/CallerConfiguration.java	Mon Nov 12 07:23:24 2007
@@ -18,21 +18,32 @@
 
 package org.wso2.throttle;
 
+import java.io.Serializable;
+
 /**
  *
  *
  */
 
-public abstract class CallerConfiguration {
+public abstract class CallerConfiguration implements Serializable {
 
-    /** The time window     */
+    /**
+     * The time window
+     */
     private long unitTime;
-    /** The maximum number of Request that should have allowed for caller   */
+    /**
+     * The maximum number of Request that should have allowed for caller
+     */
     private int maximumRequest;
-    /** The Time Period which access of caller should have denied if Maximum Number of Request had reached  */
+    /**
+     * The Time Period which access of caller should have denied if Maximum Number of Request had reached
+     */
     private long prohibitTimePeriod;
-    /** int value that indicate that access is fully denied or allowed or controled for this IP    */
+    /**
+     * int value that indicate that access is fully denied or allowed or controled for this IP
+     */
     private int accessState = ThrottleConstants.ACCESS_CONTROLLED;
+    private static final long serialVersionUID = -3387080157870675918L;
 
     /**
      * The Default Constructor
@@ -50,7 +61,7 @@
      * @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, Object ID) {
+    protected CallerConfiguration(long unitTime, int maximumRequest, long prohibitTimePeriod, String ID) {
         this();
         this.unitTime = unitTime;
         this.maximumRequest = maximumRequest;
@@ -138,7 +149,7 @@
      *
      * @return Object value of ID
      */
-    public abstract Object getID();
+    public abstract String getID();
 
 
     /**
@@ -146,7 +157,7 @@
      *
      * @param ID
      */
-    public abstract void setID(Object ID);
+    public abstract void setID(String ID);
 
     /**
      * To get the type of the throttle

Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ConcurrentAccessController.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ConcurrentAccessController.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ConcurrentAccessController.java	Mon Nov 12 07:23:24 2007
@@ -21,18 +21,20 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import java.io.Serializable;
 import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  *
  */
 
-public class ConcurrentAccessController {
+public class ConcurrentAccessController implements Serializable {
 
     private static Log log = LogFactory.getLog(ConcurrentAccessController.class.getName());
 
     private final int limit;
     private final AtomicInteger counter;
+    private static final long serialVersionUID = -6857325377726757251L;
 
     public ConcurrentAccessController(int limit) {
         this.limit = limit;

Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/Throttle.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/Throttle.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/Throttle.java	Mon Nov 12 07:23:24 2007
@@ -18,6 +18,7 @@
 
 package org.wso2.throttle;
 
+import java.io.Serializable;
 import java.util.HashMap;
 
 /**
@@ -25,14 +26,25 @@
  * There is a one to one releationship between configuration and context
  */
 
-public class Throttle {
+public class Throttle implements Serializable {
 
-    /** Holder for ThrottleContext     */
+//    private static final long serialVersionUID = 4517849288538613640L;
+
+    /**
+     * Holder for ThrottleContext
+     */
     private HashMap throttleContexts;
-    /** Holder for ThrottleConfigurations     */
+    /**
+     * Holder for ThrottleConfigurations
+     */
     private HashMap throttleConfigurations;
-    /** ConcurrentAccessController insatnce- this is common to all remote callers*/
+    /**
+     * ConcurrentAccessController insatnce- this is common to all remote callers
+     */
     private ConcurrentAccessController controller;
+
+    private static final long serialVersionUID = 1937854014424827523L;
+
     /**
      * Default Constructor
      */

Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ThrottleConfiguration.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ThrottleConfiguration.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ThrottleConfiguration.java	Mon Nov 12 07:23:24 2007
@@ -51,6 +51,7 @@
 
     /**
      * To get the type of the throttle
+     *
      * @return the type of the throttle
      */
     public int getType();

Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ThrottleException.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ThrottleException.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ThrottleException.java	Mon Nov 12 07:23:24 2007
@@ -23,6 +23,8 @@
  */
 public class ThrottleException extends Exception {
 
+    private static final long serialVersionUID = -1433310548520145461L;
+
     public ThrottleException() {
         super();
     }

Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/factory/CallerFactory.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/factory/CallerFactory.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/factory/CallerFactory.java	Mon Nov 12 07:23:24 2007
@@ -37,7 +37,7 @@
      */
     public static Caller createCaller(int throttletype, Object id) throws ThrottleException {
         if (ThrottleConstants.IP_BASE == throttletype) {
-            return new IPBaseCaller(id);
+            return new IPBaseCaller((String)id);
         } else {
             throw new ThrottleException("unknown throttle type");
         }

Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseAccessController.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseAccessController.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseAccessController.java	Mon Nov 12 07:23:24 2007
@@ -23,12 +23,14 @@
 import org.wso2.throttle.*;
 import org.wso2.throttle.factory.CallerFactory;
 
+import java.io.Serializable;
+
 /**
  *
  *
  */
 
-public class IPBaseAccessController implements AccessController {
+public class IPBaseAccessController implements AccessController, Serializable {
 
     /**
      * Log for this class
@@ -39,13 +41,14 @@
     /**
      * The Object for used to lock in synchronizing
      */
-    final Object lock = new Object();
+    private final transient Object lock = new Object();
+    private static final long serialVersionUID = -1097669364043443498L;
 
     /**
      * To check wheather caller can access not not
      *
      * @param throttleContext - current states of throttle - RunTime Data
-     * @param callerID - Identifer for remote caller
+     * @param callerID        - Identifer for remote caller
      * @return boolean - true if current remote user can continue access
      * @throws ThrottleException
      */

Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseCaller.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseCaller.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseCaller.java	Mon Nov 12 07:23:24 2007
@@ -21,19 +21,22 @@
 import org.wso2.throttle.Caller;
 import org.wso2.throttle.ThrottleConstants;
 
+import java.io.Serializable;
+
 /**
  *
  *
  */
 
-public class IPBaseCaller extends Caller {
+public class IPBaseCaller extends Caller implements Serializable {
+    private static final long serialVersionUID = 635051645003581667L;
 
     /**
      * The constructor
      *
      * @param ID
      */
-    public IPBaseCaller(Object ID) {
+    public IPBaseCaller(String ID) {
         super(ID);
     }
 

Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseCallerConfiguration.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseCallerConfiguration.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseCallerConfiguration.java	Mon Nov 12 07:23:24 2007
@@ -29,12 +29,19 @@
  */
 public class IPBaseCallerConfiguration extends CallerConfiguration implements Serializable {
 
-    /** The ID of CallerConfiguration     */
-    private Object ID;
-    /** The First part of the iprange -group ip    */
+    /**
+     * The ID of CallerConfiguration
+     */
+    private String ID;
+    /**
+     * The First part of the iprange -group ip
+     */
     private String firstPartOfIPRange;
-    /** The second part of the iprange - group ip  */
+    /**
+     * The second part of the iprange - group ip
+     */
     private String secondPartOfIPRange;
+    private static final long serialVersionUID = -4818099134411420267L;
 
     /**
      * The Default Constructor
@@ -52,8 +59,8 @@
      * @param prohibitTimePeriod - long value which represents Prohibit Time after Max request came
      * @param ipRange            - String value which represents IP Range
      */
-    public IPBaseCallerConfiguration(long unitTime,int maximumRequest,
-                                     long prohibitTimePeriod,String ipRange) {
+    public IPBaseCallerConfiguration(long unitTime, int maximumRequest,
+                                     long prohibitTimePeriod, String ipRange) {
         super(unitTime, maximumRequest, prohibitTimePeriod, ipRange);
     }
 
@@ -62,7 +69,7 @@
      *
      * @return String value of IP Range
      */
-    public Object getID() {
+    public String getID() {
         return ID;
     }
 
@@ -88,25 +95,22 @@
     /**
      * To set IP Range
      *
-     * @param ID
+     * @param iprange
      */
-    public void setID(Object ID) {
-        if (ID instanceof String) {
-            String iprange = (String) ID;
-            String ipParts [] = iprange.trim().split("-");
-            if (ipParts != null) {
-                // if IP Range is unique one IP
-                if (ipParts.length == 1) {
-                    this.firstPartOfIPRange = ipParts[0];
-                }
-                // else if IP Range is group IP
-                else if (ipParts.length == 2) {
-                    this.firstPartOfIPRange = ipParts[0];
-                    this.secondPartOfIPRange = ipParts[1];
-                }
+    public void setID(String iprange) {
+        String ipParts[] = iprange.trim().split("-");
+        if (ipParts != null) {
+            // if IP Range is unique one IP
+            if (ipParts.length == 1) {
+                this.firstPartOfIPRange = ipParts[0];
+            }
+            // else if IP Range is group IP
+            else if (ipParts.length == 2) {
+                this.firstPartOfIPRange = ipParts[0];
+                this.secondPartOfIPRange = ipParts[1];
             }
-            this.ID = ID;
         }
+        this.ID = ID;
     }
 
     public int getType() {

Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleConfiguration.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleConfiguration.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleConfiguration.java	Mon Nov 12 07:23:24 2007
@@ -31,14 +31,24 @@
 
 public class IPBaseThrottleConfiguration implements Serializable, ThrottleConfiguration {
 
-    /** Log for this class   */
+    /**
+     * Log for this class
+     */
     private static Log log = LogFactory.getLog(IPBaseThrottleConfiguration.class.getName());
-    /** The key for Other configuration     */
+    /**
+     * 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   */
+    /**
+     * The default configuration for a throttle and this will apply to callersMap that have not a custom configuration
+     */
     private CallerConfiguration defaultCallerConfiguration;
-    /** To hold configurations   */
+    /**
+     * To hold configurations
+     */
     private TreeMap configurationsMap;
+    private static final long serialVersionUID = -8660015469066052414L;
+
     /**
      * The Deault Constructor for Throttle Bean
      */

Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleContext.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleContext.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/impl/ipbase/IPBaseThrottleContext.java	Mon Nov 12 07:23:24 2007
@@ -22,6 +22,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.wso2.throttle.*;
 
+import java.io.Serializable;
 import java.util.*;
 
 /**
@@ -29,20 +30,33 @@
  *
  */
 
-public class IPBaseThrottleContext implements ThrottleContext {
+public class IPBaseThrottleContext implements ThrottleContext, Serializable {
 
-    /** Log for this class    */
+    /**
+     * Log for this class
+     */
     private static Log log = LogFactory.getLog(IPBaseThrottleContext.class.getName());
-    /** The callersMap that have registered for a particular throttle     */
+    /**
+     * The callersMap that have registered for a particular throttle
+     */
     private TreeMap callersMap;
-    /** For mapping epr to timeStamp   */
+    /**
+     * For mapping epr to timeStamp
+     */
     private HashMap keyToTimeStampMap;
-    /** The Time which next cleaning for this trottle will have to take place       */
+    /**
+     * The Time which next cleaning for this trottle will have to take place
+     */
     private long nextCleanTime;
-    /** The Object for used to lock in synchronizing     */
-    final Object lock = new Object();
-    /** The configuration of a throtle     */
+    /**
+     * 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 = 691325464023192016L;
 
     /**
      * To create a ThrottleContext need to provide a ThrottleConfiguration
@@ -86,8 +100,7 @@
                             for (Iterator iterator = callersWithSameTimeStampList.iterator(); iterator.hasNext();)
                             {
                                 Caller caller = (Caller) iterator.next();
-                                if (keyOfConfiguration.equals(throttleConfiguration.getConfigurationKeyOfCaller(caller.getID())))
-                                {
+                                if (keyOfConfiguration.equals(throttleConfiguration.getConfigurationKeyOfCaller(caller.getID()))) {
                                     return caller;
                                 }
                             }
@@ -205,12 +218,11 @@
                     {
                         Object callerObject = callersIterator.next();
                         if (callerObject != null) {
-                            if (callerObject instanceof Caller)
-                            { // In the case nextAccessTime is unique for the caller
+                            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);
-                            } else if (callerObject instanceof LinkedList)
-                            { //In the case nextAccessTime of multiple callers are same
+                            } 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();)
                                 {

Modified: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java
==============================================================================
--- branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java	(original)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/module/handler/ThrottleHandler.java	Mon Nov 12 07:23:24 2007
@@ -56,6 +56,7 @@
             throw new InstantiationError(msg);
         }
     }
+
     /**
      * Load to throttle metadata for a particular throttle
      *
@@ -141,7 +142,7 @@
 
             if (messageContext.getFLOW() == MessageContext.IN_FLOW) {
                 // do the normal throttling
-                Object remoteIP = messageContext.getProperty(MessageContext.REMOTE_ADDR);
+                String remoteIP = (String) messageContext.getProperty(MessageContext.REMOTE_ADDR);
                 if (remoteIP == null) {
                     throw new AxisFault("Could not find the IP address of the caller - Currently only support caller-IP base access control");
                 } else {




More information about the Wsas-java-dev mailing list