Search in sources :

Example 1 with MemoryScope

use of lucee.runtime.type.scope.storage.MemoryScope in project Lucee by lucee.

the class ScopeContext method clearUnusedMemoryScope.

/**
 * @param cfmlFactory
 */
private void clearUnusedMemoryScope(CFMLFactoryImpl cfmlFactory, int type) {
    Map<String, Map<String, Scope>> contexts = type == Scope.SCOPE_CLIENT ? cfClientContexts : cfSessionContexts;
    if (contexts.size() == 0)
        return;
    Object[] arrContexts = contexts.keySet().toArray();
    ApplicationListener listener = cfmlFactory.getConfig().getApplicationListener();
    Object applicationName, cfid, o;
    Map<String, Scope> fhm;
    for (int i = 0; i < arrContexts.length; i++) {
        applicationName = arrContexts[i];
        fhm = contexts.get(applicationName);
        if (fhm.size() > 0) {
            Object[] cfids = fhm.keySet().toArray();
            int count = cfids.length;
            for (int y = 0; y < cfids.length; y++) {
                cfid = cfids[y];
                o = fhm.get(cfid);
                if (!(o instanceof MemoryScope))
                    continue;
                MemoryScope scope = (MemoryScope) o;
                // close
                if (scope.isExpired()) {
                    // TODO macht das sinn? ist das nicht kopierleiche?
                    ApplicationImpl application = (ApplicationImpl) applicationContexts.get(applicationName);
                    long appLastAccess = 0;
                    if (application != null) {
                        appLastAccess = application.getLastAccess();
                        application.touch();
                    }
                    scope.touch();
                    try {
                        if (type == Scope.SCOPE_SESSION)
                            listener.onSessionEnd(cfmlFactory, (String) applicationName, (String) cfid);
                    } catch (Throwable t) {
                        ExceptionUtil.rethrowIfNecessary(t);
                        ExceptionHandler.log(cfmlFactory.getConfig(), Caster.toPageException(t));
                    } finally {
                        if (application != null)
                            application.setLastAccess(appLastAccess);
                        fhm.remove(cfids[y]);
                        scope.release(ThreadLocalPageContext.get());
                        getLog().log(Log.LEVEL_INFO, "scope-context", "remove memory based " + VariableInterpreter.scopeInt2String(type) + " scope for " + applicationName + "/" + cfid);
                        count--;
                    }
                }
            }
            if (count == 0)
                contexts.remove(arrContexts[i]);
        }
    }
}
Also used : StorageScope(lucee.runtime.type.scope.storage.StorageScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope) ApplicationListener(lucee.runtime.listener.ApplicationListener) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope) Map(java.util.Map)

Example 2 with MemoryScope

use of lucee.runtime.type.scope.storage.MemoryScope in project Lucee by lucee.

the class ScopeContext method storeUnusedStorageScope.

private void storeUnusedStorageScope(CFMLFactoryImpl cfmlFactory, int type) {
    Map<String, Map<String, Scope>> contexts = type == Scope.SCOPE_CLIENT ? cfClientContexts : cfSessionContexts;
    long timespan = type == Scope.SCOPE_CLIENT ? CLIENT_MEMORY_TIMESPAN : SESSION_MEMORY_TIMESPAN;
    String strType = VariableInterpreter.scopeInt2String(type);
    if (contexts.size() == 0)
        return;
    long now = System.currentTimeMillis();
    Object[] arrContexts = contexts.keySet().toArray();
    Object applicationName, cfid, o;
    Map<String, Scope> fhm;
    for (int i = 0; i < arrContexts.length; i++) {
        applicationName = arrContexts[i];
        fhm = contexts.get(applicationName);
        if (fhm.size() > 0) {
            Object[] arrClients = fhm.keySet().toArray();
            int count = arrClients.length;
            for (int y = 0; y < arrClients.length; y++) {
                cfid = arrClients[y];
                o = fhm.get(cfid);
                if (!(o instanceof StorageScope))
                    continue;
                StorageScope scope = (StorageScope) o;
                if (scope.lastVisit() + timespan < now && !(scope instanceof MemoryScope)) {
                    getLog().log(Log.LEVEL_INFO, "scope-context", "remove from memory " + strType + " scope for " + applicationName + "/" + cfid + " from storage " + scope.getStorage());
                    fhm.remove(arrClients[y]);
                    count--;
                }
            }
            if (count == 0)
                contexts.remove(arrContexts[i]);
        }
    }
}
Also used : StorageScope(lucee.runtime.type.scope.storage.StorageScope) StorageScope(lucee.runtime.type.scope.storage.StorageScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope) Map(java.util.Map)

Aggregations

Map (java.util.Map)2 MemoryScope (lucee.runtime.type.scope.storage.MemoryScope)2 StorageScope (lucee.runtime.type.scope.storage.StorageScope)2 ApplicationListener (lucee.runtime.listener.ApplicationListener)1