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]);
}
}
}
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]);
}
}
}
Aggregations