* @return cf session matching the context
* @throws PageException
*/
private synchronized Session getCFSessionScope(PageContext pc, RefBoolean isNew) throws PageException {
ApplicationContext appContext = pc.getApplicationContext();
// get Context
Map<String, Scope> context = getSubMap(cfSessionContextes,appContext.getName());
// get Session
boolean isMemory=false;
String storage = appContext.getSessionstorage();
if(StringUtil.isEmpty(storage,true)){
storage=ConfigImpl.DEFAULT_STORAGE_SESSION;
isMemory=true;
}
else if("ram".equalsIgnoreCase(storage)) {
storage="memory";
isMemory=true;
}
else if("registry".equalsIgnoreCase(storage)) {
storage="file";
}
else {
storage=storage.toLowerCase();
if("memory".equals(storage))isMemory=true;
}
final boolean doMemory=isMemory || !appContext.getSessionCluster();
Session session=doMemory?appContext.getSessionCluster()?null:(Session) context.get(pc.getCFID()):null;
if(!(session instanceof StorageScope) || session.isExpired() || !((StorageScope)session).getStorage().equalsIgnoreCase(storage)) {
if(isMemory){
session=SessionMemory.getInstance(pc,isNew,getLog());
}
else if("file".equals(storage)){
session=SessionFile.getInstance(appContext.getName(),pc,getLog());
}
else if("cookie".equals(storage))
session=SessionCookie.getInstance(appContext.getName(),pc,getLog());
else{
DataSource ds = ((PageContextImpl)pc).getDataSource(storage,null);
if(ds!=null && ds.isStorage())session=SessionDatasource.getInstance(storage,pc,getLog(),null);
else session=SessionCache.getInstance(storage,appContext.getName(),pc,getLog(),null);
if(session==null){
// datasource not enabled for storage
if(ds!=null)
throw new ApplicationException(
"datasource ["+storage+"] is not enabled to be used as session/client storage, " +
"you have to enable it in the railo administrator or define key \"storage=true\" for datasources defined in Application.cfc .");
CacheConnection cc = Util.getCacheConnection(pc.getConfig(),storage,null);
if(cc!=null)
throw new ApplicationException("cache ["+storage+"] is not enabled to be used as a session/client storage, you have to enable it in the railo administrator.");
throw new ApplicationException("there is no cache or datasource with name ["+storage+"] defined.");
}
}
((StorageScope)session).setStorage(storage);
if(doMemory)context.put(pc.getCFID(),session);
isNew.setValue(true);
}
else {
getLog().info("scope-context", "use existing session scope for "+appContext.getName()+"/"+pc.getCFID()+" from storage "+storage);
}
session.touchBeforeRequest(pc);
return session;
}