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.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<SessionData> reference = new AtomicReference<SessionData>();
final AtomicReference<Exception> exception = new AtomicReference<Exception>();
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();
}
/**