Search in sources :

Example 1 with KeyLock

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;
}
Also used : PageException(lucee.runtime.exp.PageException) RefBoolean(lucee.commons.lang.types.RefBoolean) RefBooleanImpl(lucee.commons.lang.types.RefBooleanImpl) KeyLock(lucee.commons.lock.KeyLock) ActiveLock(lucee.runtime.debug.ActiveLock) Lock(lucee.commons.lock.Lock)

Aggregations

RefBoolean (lucee.commons.lang.types.RefBoolean)1 RefBooleanImpl (lucee.commons.lang.types.RefBooleanImpl)1 KeyLock (lucee.commons.lock.KeyLock)1 Lock (lucee.commons.lock.Lock)1 ActiveLock (lucee.runtime.debug.ActiveLock)1 PageException (lucee.runtime.exp.PageException)1