From e5df5d82ee7d7a02a5eb2d8b2fbd953b818f6fdc Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 22 Oct 2010 23:11:50 +0000 Subject: [PATCH] 328306 JDBC Session Manager uses ContextHandler.handle(Runnable) to load contexts git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2387 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../server/session/JDBCSessionManager.java | 99 ++++++++++++------- 1 file changed, 62 insertions(+), 37 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionManager.java index f53fdffd834..1fbcd70a9b4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionManager.java @@ -29,6 +29,8 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Exchanger; +import java.util.concurrent.atomic.AtomicReference; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSessionEvent; @@ -834,49 +836,72 @@ public class JDBCSessionManager extends AbstractSessionManager * @return the session data that was loaded * @throws Exception */ - protected SessionData loadSession (String id, String canonicalContextPath, String vhost) + protected SessionData loadSession (final String id, final String canonicalContextPath, final String vhost) throws Exception { - SessionData data = null; - Connection connection = getConnection(); - PreparedStatement statement = null; - try + final AtomicReference reference = new AtomicReference(); + final AtomicReference exception = new AtomicReference(); + Runnable load = new Runnable() { - statement = connection.prepareStatement(__selectSession); - statement.setString(1, id); - statement.setString(2, canonicalContextPath); - statement.setString(3, vhost); - ResultSet result = statement.executeQuery(); - if (result.next()) + public void run() { - data = new SessionData(id); - data.setRowId(result.getString(__sessionTableRowId)); - data.setCookieSet(result.getLong("cookieTime")); - data.setLastAccessed(result.getLong("lastAccessTime")); - data.setAccessed (result.getLong("accessTime")); - data.setCreated(result.getLong("createTime")); - data.setLastNode(result.getString("lastNode")); - data.setLastSaved(result.getLong("lastSavedTime")); - data.setExpiryTime(result.getLong("expiryTime")); - data.setCanonicalContext(result.getString("contextPath")); - data.setVirtualHost(result.getString("virtualHost")); + SessionData data = null; + Connection connection=null; + PreparedStatement statement = null; + try + { + connection = getConnection(); + statement = connection.prepareStatement(__selectSession); + statement.setString(1, id); + statement.setString(2, canonicalContextPath); + statement.setString(3, vhost); + ResultSet result = statement.executeQuery(); + if (result.next()) + { + data = new SessionData(id); + data.setRowId(result.getString(__sessionTableRowId)); + data.setCookieSet(result.getLong("cookieTime")); + data.setLastAccessed(result.getLong("lastAccessTime")); + data.setAccessed (result.getLong("accessTime")); + data.setCreated(result.getLong("createTime")); + data.setLastNode(result.getString("lastNode")); + data.setLastSaved(result.getLong("lastSavedTime")); + data.setExpiryTime(result.getLong("expiryTime")); + data.setCanonicalContext(result.getString("contextPath")); + data.setVirtualHost(result.getString("virtualHost")); - InputStream is = ((JDBCSessionIdManager)getIdManager())._dbAdaptor.getBlobInputStream(result, "map"); - ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream (is); - Object o = ois.readObject(); - data.setAttributeMap((ConcurrentHashMap)o); - ois.close(); - - if (Log.isDebugEnabled()) - Log.debug("LOADED session "+data); + InputStream is = ((JDBCSessionIdManager)getIdManager())._dbAdaptor.getBlobInputStream(result, "map"); + ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream (is); + Object o = ois.readObject(); + data.setAttributeMap((ConcurrentHashMap)o); + ois.close(); + + if (Log.isDebugEnabled()) + Log.debug("LOADED session "+data); + } + reference.set(data); + } + catch (Exception e) + { + exception.set(e); + } + finally + { + if (connection!=null) + { + try { connection.close();} + catch(Exception e) { Log.warn(e); } + } + } } - return data; - } - finally - { - if (connection!=null) - connection.close(); - } + }; + + if (_context==null) + load.run(); + else + _context.getContextHandler().handle(load); + + return reference.get(); } /**