geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r369319 - in /geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote: DefaultRemoteSessionStrategy.java util/ util/DefaultRemoteSessionStrategy.java util/LRUCache.java util/RemoteSessionStrategy.java util/package.html
Date Mon, 16 Jan 2006 02:47:08 GMT
Author: jstrachan
Date: Sun Jan 15 18:47:07 2006
New Revision: 369319

URL: http://svn.apache.org/viewcvs?rev=369319&view=rev
Log:
added a little helper strategy for deciding whether to redirect, proxy or move when faced
with a remote session

Added:
    geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/
    geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/DefaultRemoteSessionStrategy.java
      - copied, changed from r369313, geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/DefaultRemoteSessionStrategy.java
    geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/LRUCache.java
  (with props)
    geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/RemoteSessionStrategy.java
    geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/package.html
Removed:
    geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/DefaultRemoteSessionStrategy.java

Copied: geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/DefaultRemoteSessionStrategy.java
(from r369313, geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/DefaultRemoteSessionStrategy.java)
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/DefaultRemoteSessionStrategy.java?p2=geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/DefaultRemoteSessionStrategy.java&p1=geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/DefaultRemoteSessionStrategy.java&r1=369313&r2=369319&rev=369319&view=diff
==============================================================================
--- geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/DefaultRemoteSessionStrategy.java
(original)
+++ geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/DefaultRemoteSessionStrategy.java
Sun Jan 15 18:47:07 2006
@@ -13,28 +13,39 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.geronimo.session.remote;
+package org.apache.geronimo.session.remote.util;
 
 import org.apache.geronimo.session.SessionLocation;
 
+import java.util.Map;
+
 /**
+ * A default strategy that uses simple watermarks for deciding when to redirect,
+ * then proxy, then move. Requests will be redirected by default up to a low
+ * watermark, then they will be proxied until they reach the high watermark and
+ * then the session will be moved.
  * 
  * @version $Revision: $
  */
-public class DefaultRemoteSessionStrategy {
-
-    public static final int REDIRECT = 1;
-    public static final int PROXY = 2;
-    public static final int MOVE = 3;
+public class DefaultRemoteSessionStrategy implements RemoteSessionStrategy {
 
-    private boolean redirectSupported;
-    private int redirectWatermark = 5;
+    private final Map cache;
+    private boolean redirectSupported = true;
+    private int proxyWatermark = 5;
     private int moveWatermark = 10;
 
+    public DefaultRemoteSessionStrategy() {
+        this(new LRUCache(4000));
+    }
+
+    public DefaultRemoteSessionStrategy(Map cache) {
+        this.cache = cache;
+    }
+
     public int decide(SessionLocation location) {
         int count = getRecentRequestCount(location.getSessionId());
         if (redirectSupported) {
-            if (count < redirectWatermark) {
+            if (count < proxyWatermark) {
                 return REDIRECT;
             }
         }
@@ -44,7 +55,58 @@
         return MOVE;
     }
 
-    private int getRecentRequestCount(String sessionId) {
-        return 0;
+    // Properties
+    // -------------------------------------------------------------------------
+    public boolean isRedirectSupported() {
+        return redirectSupported;
+    }
+
+    /**
+     * Sets whether or not redirection should be supported at all. It is by
+     * default but you may wish to disable this if you have a non-smart client
+     * which is not capable of redirection.
+     */
+    public void setRedirectSupported(boolean redirectSupported) {
+        this.redirectSupported = redirectSupported;
+    }
+
+    public int getMoveWatermark() {
+        return moveWatermark;
+    }
+
+    /**
+     * Sets the low watermark of requests in the recent history of requests for
+     * the same session Id which will cause the session to be moved locally.
+     */
+    public void setMoveWatermark(int moveWatermark) {
+        this.moveWatermark = moveWatermark;
+    }
+
+    public int getProxyWatermark() {
+        return proxyWatermark;
+    }
+
+    /**
+     * Sets the low watermark of requests in the recent history of requests for
+     * the same session Id which will cause the session to be proxied to the
+     * remote session.
+     */
+    public void setProxyWatermark(int redirectWatermark) {
+        this.proxyWatermark = redirectWatermark;
+    }
+
+    // Implementation methods
+    // -------------------------------------------------------------------------
+    protected synchronized int getRecentRequestCount(String sessionId) {
+        Counter counter = (Counter) cache.get(sessionId);
+        if (counter == null) {
+            counter = new Counter();
+            cache.put(sessionId, counter);
+        }
+        return ++counter.value;
+    }
+
+    protected static class Counter {
+        public int value;
     }
 }

Added: geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/LRUCache.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/LRUCache.java?rev=369319&view=auto
==============================================================================
--- geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/LRUCache.java
(added)
+++ geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/LRUCache.java
Sun Jan 15 18:47:07 2006
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.apache.geronimo.session.remote.util;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * An LRU cache of a fixed size
+ * 
+ * @version $Revision: $
+ */
+public class LRUCache extends LinkedHashMap {
+
+    private static final long serialVersionUID = 8738663503123500067L;
+    
+    protected static final float DEFAULT_LOAD_FACTOR = (float) 0.75;
+    protected static final int DEFAULT_INITIAL_CAPACITY = 1000;
+
+    private int maximumSize;
+
+    public LRUCache(int maximumSize) {
+        this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, true, maximumSize);
+    }
+
+    public LRUCache(int maximumSize, boolean accessOrder) {
+        this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, accessOrder, maximumSize);
+    }
+
+    public LRUCache(int initialCapacity, float loadFactor, boolean accessOrder, int maximumSize)
{
+        super(initialCapacity, loadFactor, accessOrder);
+        this.maximumSize = maximumSize;
+    }
+
+    protected boolean removeEldestEntry(Map.Entry eldest) {
+        return size() > maximumSize;
+    }
+}

Propchange: geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/LRUCache.java
------------------------------------------------------------------------------
    svn:executable = *

Added: geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/RemoteSessionStrategy.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/RemoteSessionStrategy.java?rev=369319&view=auto
==============================================================================
--- geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/RemoteSessionStrategy.java
(added)
+++ geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/RemoteSessionStrategy.java
Sun Jan 15 18:47:07 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.apache.geronimo.session.remote.util;
+
+import org.apache.geronimo.session.SessionLocation;
+
+/**
+ * A strategy for deciding if a client should deal with a remote
+ * session; either redirecting to the remote server, proxying to it
+ * or moving the session locally.
+ * 
+ * @version $Revision: $
+ */
+public interface RemoteSessionStrategy {
+    public static final int REDIRECT = 1;
+    public static final int PROXY = 2;
+    public static final int MOVE = 3;
+
+    public int decide(SessionLocation location);
+
+}

Added: geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/package.html
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/package.html?rev=369319&view=auto
==============================================================================
--- geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/package.html
(added)
+++ geronimo/trunk/modules/session/src/java/org/apache/geronimo/session/remote/util/package.html
Sun Jan 15 18:47:07 2006
@@ -0,0 +1,12 @@
+<html>
+<head>
+</head>
+<body>
+
+<p>
+Some optional utilities for working with remote sessions such as the strategy for deciding
whether to 
+redirect, proxy or move.
+</p>
+
+</body>
+</html>



Mime
View raw message