use of lucee.commons.lock.KeyLock in project Lucee by lucee.
the class PageContextImpl method initApplicationContext.
/**
* @return return value of method "onApplicationStart" or true
* @throws PageException
*/
public boolean initApplicationContext(ApplicationListener listener) throws PageException {
boolean initSession = false;
// AppListenerSupport listener = (AppListenerSupport) config.get ApplicationListener();
KeyLock<String> lock = config.getContextLock();
String name = StringUtil.emptyIfNull(applicationContext.getName());
String token = name + ":" + getCFID();
Lock tokenLock = lock.lock(token, getRequestTimeout());
// print.o("outer-lock :"+token);
try {
// check session before executing any code
initSession = applicationContext.isSetSessionManagement() && listener.hasOnSessionStart(this) && !scopeContext.hasExistingSessionScope(this);
// init application
Lock nameLock = lock.lock(name, getRequestTimeout());
// print.o("inner-lock :"+token);
try {
RefBoolean isNew = new RefBooleanImpl(false);
// this is needed that the application scope is initilized
application = scopeContext.getApplicationScope(this, isNew);
if (isNew.toBooleanValue()) {
try {
if (!listener.onApplicationStart(this)) {
scopeContext.removeApplicationScope(this);
return false;
}
} catch (PageException pe) {
scopeContext.removeApplicationScope(this);
throw pe;
}
}
} finally {
// print.o("inner-unlock:"+token);
lock.unlock(nameLock);
}
// init session
if (initSession) {
// this is needed that the session scope is initilized
scopeContext.getSessionScope(this, DUMMY_BOOL);
listener.onSessionStart(this);
}
} finally {
// print.o("outer-unlock:"+token);
lock.unlock(tokenLock);
}
return true;
}
Aggregations