Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 17115 invoked from network); 16 Jan 2006 02:47:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 16 Jan 2006 02:47:31 -0000 Received: (qmail 87248 invoked by uid 500); 16 Jan 2006 02:47:31 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 87101 invoked by uid 500); 16 Jan 2006 02:47:30 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 87090 invoked by uid 99); 16 Jan 2006 02:47:30 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Jan 2006 18:47:30 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 15 Jan 2006 18:47:29 -0800 Received: (qmail 16888 invoked by uid 65534); 16 Jan 2006 02:47:09 -0000 Message-ID: <20060116024709.16886.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: scm@geronimo.apache.org From: jstrachan@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 @@ + + + + + +

+Some optional utilities for working with remote sessions such as the strategy for deciding whether to +redirect, proxy or move. +

+ + +