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
This commit is contained in:
Greg Wilkins 2010-10-22 23:11:50 +00:00
parent 786f0d2299
commit e5df5d82ee
1 changed files with 62 additions and 37 deletions

View File

@ -29,6 +29,8 @@ import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; 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.HttpServletRequest;
import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionEvent;
@ -834,49 +836,72 @@ public class JDBCSessionManager extends AbstractSessionManager
* @return the session data that was loaded * @return the session data that was loaded
* @throws Exception * @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 throws Exception
{ {
SessionData data = null; final AtomicReference<SessionData> reference = new AtomicReference<SessionData>();
Connection connection = getConnection(); final AtomicReference<Exception> exception = new AtomicReference<Exception>();
PreparedStatement statement = null; Runnable load = new Runnable()
try
{ {
statement = connection.prepareStatement(__selectSession); public void run()
statement.setString(1, id);
statement.setString(2, canonicalContextPath);
statement.setString(3, vhost);
ResultSet result = statement.executeQuery();
if (result.next())
{ {
data = new SessionData(id); SessionData data = null;
data.setRowId(result.getString(__sessionTableRowId)); Connection connection=null;
data.setCookieSet(result.getLong("cookieTime")); PreparedStatement statement = null;
data.setLastAccessed(result.getLong("lastAccessTime")); try
data.setAccessed (result.getLong("accessTime")); {
data.setCreated(result.getLong("createTime")); connection = getConnection();
data.setLastNode(result.getString("lastNode")); statement = connection.prepareStatement(__selectSession);
data.setLastSaved(result.getLong("lastSavedTime")); statement.setString(1, id);
data.setExpiryTime(result.getLong("expiryTime")); statement.setString(2, canonicalContextPath);
data.setCanonicalContext(result.getString("contextPath")); statement.setString(3, vhost);
data.setVirtualHost(result.getString("virtualHost")); 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"); InputStream is = ((JDBCSessionIdManager)getIdManager())._dbAdaptor.getBlobInputStream(result, "map");
ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream (is); ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream (is);
Object o = ois.readObject(); Object o = ois.readObject();
data.setAttributeMap((ConcurrentHashMap)o); data.setAttributeMap((ConcurrentHashMap)o);
ois.close(); ois.close();
if (Log.isDebugEnabled()) if (Log.isDebugEnabled())
Log.debug("LOADED session "+data); 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 (_context==null)
{ load.run();
if (connection!=null) else
connection.close(); _context.getContextHandler().handle(load);
}
return reference.get();
} }
/** /**