use of lucee.runtime.type.scope.LocalImpl in project Lucee by lucee.
the class ChildThreadImpl method execute.
public PageException execute(Config config) {
PageContext oldPc = ThreadLocalPageContext.get();
Page p = page;
PageContextImpl pc = null;
try {
// deamon
if (this.pc != null) {
pc = this.pc;
ThreadLocalPageContext.register(pc);
} else // task
{
ConfigWebImpl cwi;
try {
cwi = (ConfigWebImpl) config;
DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
pc = ThreadUtil.createPageContext(cwi, os, serverName, requestURI, queryString, SerializableCookie.toCookies(cookies), headers, null, parameters, attributes, true, -1);
pc.setRequestTimeout(requestTimeout);
p = PageSourceImpl.loadPage(pc, cwi.getPageSources(oldPc == null ? pc : oldPc, null, template, false, false, true));
// p=cwi.getPageSources(oldPc,null, template, false,false,true).loadPage(cwi);
} catch (PageException e) {
return e;
}
pc.addPageSource(p.getPageSource(), true);
}
threadScope = pc.getThreadScope(KeyConstants._cfthread, null);
pc.setCurrentThreadScope(new ThreadsImpl(this));
pc.setThread(Thread.currentThread());
// String encodings = pc.getHttpServletRequest().getHeader("Accept-Encoding");
Undefined undefined = pc.us();
Argument newArgs = new ArgumentThreadImpl((Struct) Duplicator.duplicate(attrs, false));
LocalImpl newLocal = pc.getScopeFactory().getLocalInstance();
// Key[] keys = attrs.keys();
Iterator<Entry<Key, Object>> it = attrs.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
newArgs.setEL(e.getKey(), e.getValue());
}
newLocal.setEL(KEY_ATTRIBUTES, newArgs);
Argument oldArgs = pc.argumentsScope();
Local oldLocal = pc.localScope();
int oldMode = undefined.setMode(Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
pc.setFunctionScopes(newLocal, newArgs);
try {
p.threadCall(pc, threadIndex);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
if (!Abort.isSilentAbort(t)) {
ConfigWeb c = pc.getConfig();
if (c instanceof ConfigImpl) {
ConfigImpl ci = (ConfigImpl) c;
Log log = ci.getLog("thread");
if (log != null)
LogUtil.log(log, Log.LEVEL_ERROR, this.getName(), t);
}
PageException pe = Caster.toPageException(t);
if (!serializable)
catchBlock = pe.getCatchBlock(pc.getConfig());
return pe;
}
} finally {
completed = true;
pc.setFunctionScopes(oldLocal, oldArgs);
undefined.setMode(oldMode);
// pc.getScopeFactory().recycle(newArgs);
pc.getScopeFactory().recycle(pc, newLocal);
if (pc.getHttpServletResponse() instanceof HttpServletResponseDummy) {
HttpServletResponseDummy rsp = (HttpServletResponseDummy) pc.getHttpServletResponse();
pc.flush();
contentType = rsp.getContentType();
Pair<String, Object>[] _headers = rsp.getHeaders();
if (_headers != null)
for (int i = 0; i < _headers.length; i++) {
if (_headers[i].getName().equalsIgnoreCase("Content-Encoding"))
contentEncoding = Caster.toString(_headers[i].getValue(), null);
}
}
}
} finally {
pc.getConfig().getFactory().releaseLuceePageContext(pc, true);
pc = null;
if (oldPc != null)
ThreadLocalPageContext.register(oldPc);
}
return null;
}
use of lucee.runtime.type.scope.LocalImpl in project Lucee by lucee.
the class UDFImpl method _call.
private Object _call(PageContext pc, Collection.Key calledName, Object[] args, Struct values, boolean doIncludePath) throws PageException {
// print.out(count++);
PageContextImpl pci = (PageContextImpl) pc;
Argument newArgs = pci.getScopeFactory().getArgumentInstance();
newArgs.setFunctionArgumentNames(properties.getArgumentsSet());
LocalImpl newLocal = pci.getScopeFactory().getLocalInstance();
Undefined undefined = pc.undefinedScope();
Argument oldArgs = pc.argumentsScope();
Local oldLocal = pc.localScope();
Collection.Key oldCalledName = pci.getActiveUDFCalledName();
pc.setFunctionScopes(newLocal, newArgs);
pci.setActiveUDFCalledName(calledName);
int oldCheckArgs = undefined.setMode(pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML ? (properties.getLocalMode() == null ? pc.getApplicationContext().getLocalMode() : properties.getLocalMode().intValue()) : Undefined.MODE_LOCAL_OR_ARGUMENTS_ALWAYS);
PageSource ps = null;
PageSource psInc = null;
try {
ps = properties.getPageSource();
if (doIncludePath)
psInc = ps;
if (doIncludePath && getOwnerComponent() != null) {
psInc = ComponentUtil.getPageSource(getOwnerComponent());
if (psInc == pci.getCurrentTemplatePageSource()) {
psInc = null;
}
}
if (ps != null)
pci.addPageSource(ps, psInc);
pci.addUDF(this);
// ////////////////////////////////////////
BodyContent bc = null;
Boolean wasSilent = null;
boolean bufferOutput = getBufferOutput(pci);
if (!getOutput()) {
if (bufferOutput)
bc = pci.pushBody();
else
wasSilent = pc.setSilent() ? Boolean.TRUE : Boolean.FALSE;
}
UDF parent = null;
if (ownerComponent != null) {
parent = pci.getActiveUDF();
pci.setActiveUDF(this);
}
Object returnValue = null;
try {
if (args != null)
defineArguments(pc, getFunctionArguments(), args, newArgs);
else
defineArguments(pc, getFunctionArguments(), values, newArgs);
returnValue = implementation(pci);
if (ownerComponent != null)
pci.setActiveUDF(parent);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
if (ownerComponent != null)
pci.setActiveUDF(parent);
if (!getOutput()) {
if (bufferOutput)
BodyContentUtil.flushAndPop(pc, bc);
else if (!wasSilent)
pc.unsetSilent();
}
// BodyContentUtil.flushAndPop(pc,bc);
throw Caster.toPageException(t);
}
if (!getOutput()) {
if (bufferOutput)
BodyContentUtil.clearAndPop(pc, bc);
else if (!wasSilent)
pc.unsetSilent();
}
if (returnValue == null && pc.getConfig().getFullNullSupport())
return returnValue;
if (properties.getReturnType() == CFTypes.TYPE_ANY || !((PageContextImpl) pc).getTypeChecking())
return returnValue;
if (Decision.isCastableTo(properties.getReturnTypeAsString(), returnValue, false, false, -1))
return returnValue;
throw new UDFCasterException(this, properties.getReturnTypeAsString(), returnValue);
// REALCAST return Caster.castTo(pageContext,returnType,returnValue,false);
// ////////////////////////////////////////
} finally {
if (ps != null)
pc.removeLastPageSource(psInc != null);
pci.removeUDF();
pci.setFunctionScopes(oldLocal, oldArgs);
pci.setActiveUDFCalledName(oldCalledName);
undefined.setMode(oldCheckArgs);
pci.getScopeFactory().recycle(pci, newArgs);
pci.getScopeFactory().recycle(pci, newLocal);
}
}
Aggregations