}
public Client getClientScope(PageContext pc) throws PageException {
Client client=null;
ApplicationContext appContext = pc.getApplicationContext();
// get Context
Map<String, Scope> context = getSubMap(cfClientContextes,appContext.getName());
// get Client
boolean isMemory=false;
String storage = appContext.getClientstorage();
if(StringUtil.isEmpty(storage,true)){
storage=ConfigImpl.DEFAULT_STORAGE_CLIENT;
}
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.getClientCluster();
client=doMemory?(Client) context.get(pc.getCFID()):null;
if(client==null || client.isExpired() || !client.getStorage().equalsIgnoreCase(storage)) {
if("file".equals(storage)){
client=ClientFile.getInstance(appContext.getName(),pc,getLog());
}
else if("cookie".equals(storage))
client=ClientCookie.getInstance(appContext.getName(),pc,getLog());
else if("memory".equals(storage)){
client=ClientMemory.getInstance(pc,getLog());
}
else{
DataSource ds = ((PageContextImpl)pc).getDataSource(storage,null);
if(ds!=null)client=ClientDatasource.getInstance(storage,pc,getLog());
else client=ClientCache.getInstance(storage,appContext.getName(),pc,getLog(),null);
if(client==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.");
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.");
}
}
client.setStorage(storage);
if(doMemory)context.put(pc.getCFID(),client);
}
else
getLog().info("scope-context", "use existing client scope for "+appContext.getName()+"/"+pc.getCFID()+" from storage "+storage);
client.touchBeforeRequest(pc);
return client;
}