[wsas-java-dev] svn commit r9372 - branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle

svn at wso2.org svn at wso2.org
Thu Nov 1 02:07:10 PDT 2007


Author: indika
Date: Thu Nov  1 02:06:49 2007
New Revision: 9372

Added:
   branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ConcurrentAccessController.java
Log:
add missig file 


Added: branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ConcurrentAccessController.java
==============================================================================
--- (empty file)
+++ branches/wsas/java/2.1/commons/throttle/src/main/java/org/wso2/throttle/ConcurrentAccessController.java	Thu Nov  1 02:06:49 2007
@@ -0,0 +1,63 @@
+/*
+*  Licensed to the Apache Software Foundation (ASF) under one
+*  or more contributor license agreements.  See the NOTICE file
+*  distributed with this work for additional information
+*  regarding copyright ownership.  The ASF licenses this file
+*  to you under the Apache License, Version 2.0 (the
+*  "License"); you may not use this file except in compliance
+*  with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing,
+*  software distributed under the License is distributed on an
+*   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*  KIND, either express or implied.  See the License for the
+*  specific language governing permissions and limitations
+*  under the License.
+*/
+package org.wso2.throttle;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ *
+ */
+
+public class ConcurrentAccessController {
+
+    private static Log log = LogFactory.getLog(ConcurrentAccessController.class.getName());
+
+    private final int limit;
+    private final AtomicInteger counter;
+
+    public ConcurrentAccessController(int limit) {
+        this.limit = limit;
+        counter = new AtomicInteger(limit);
+    }
+
+    public int getAndDecrement() {
+        int ret = counter.getAndDecrement();
+        if (ret <= 0) {
+            counter.incrementAndGet();
+            return 0;
+        } else {
+            return ret;
+        }
+    }
+
+    public int incrementAndGet() {
+        int ret = counter.incrementAndGet();
+        if (ret < 0) {
+            return 0;
+        }
+        return ret;
+    }
+
+    public int getLimit() {
+        return limit;
+    }
+}




More information about the Wsas-java-dev mailing list