Search in sources :

Example 81 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class QueryExecute method call.

// name is set by evaluator
public static Object call(PageContext pc, String sql, Object params, Struct options, String name) throws PageException {
    PageContextImpl pci = (PageContextImpl) pc;
    lucee.runtime.tag.Query qry = (lucee.runtime.tag.Query) pci.use(lucee.runtime.tag.Query.class.getName(), "cfquery", TagLibTag.ATTRIBUTE_TYPE_FIXED);
    try {
        try {
            // set attributes
            qry.setReturnVariable(true);
            qry.setName(StringUtil.isEmpty(name) ? "QueryExecute" : name);
            if (options != null)
                TagUtil.setAttributeCollection(pc, qry, null, options, TagLibTag.ATTRIBUTE_TYPE_FIXED);
            qry.setParams(params);
            int res = qry.doStartTag();
            pc.initBody(qry, res);
            pc.forceWrite(sql);
            qry.doAfterBody();
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            try {
                qry.doCatch(t);
            } catch (Throwable t2) {
                ExceptionUtil.rethrowIfNecessary(t);
                throw Caster.toPageException(t2);
            }
        } finally {
            pc.popBody();
            qry.doFinally();
        }
        qry.doEndTag();
        return qry.getReturnVariable();
    } finally {
        pci.reuse(qry);
    }
}
Also used : PageContextImpl(lucee.runtime.PageContextImpl)

Example 82 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class ResourceLockImpl method _read.

private void _read(String path) {
    long start = -1, now;
    Thread t;
    do {
        if ((t = resources.get(path)) == null) {
            // print.ln("read ok");
            return;
        }
        if (t == Thread.currentThread()) {
            // aprint.err(path);
            Config config = ThreadLocalPageContext.getConfig();
            if (config != null)
                SystemOut.printDate(config.getErrWriter(), "conflict in same thread: on " + path);
            // SystemOut.printDate(config.getErrWriter(),"conflict in same thread: on "+path+"\nStacktrace:\n"+StringUtil.replace(ExceptionUtil.getStacktrace(new Throwable(), false),"java.lang.Throwable\n","",true));
            return;
        }
        // bugfix when lock von totem thread, wird es ignoriert
        if (!t.isAlive()) {
            resources.remove(path);
            return;
        }
        if (start == -1)
            start = System.currentTimeMillis();
        try {
            token.wait(lockTimeout);
            now = System.currentTimeMillis();
            if ((start + lockTimeout) <= now) {
                Config config = ThreadLocalPageContext.getConfig();
                if (config != null) {
                    PageContextImpl pc = null;
                    String add = "";
                    if (config instanceof ConfigWeb) {
                        CFMLFactory factory = ((ConfigWeb) config).getFactory();
                        if (factory instanceof CFMLFactoryImpl) {
                            Map<Integer, PageContextImpl> pcs = ((CFMLFactoryImpl) factory).getActivePageContexts();
                            Iterator<PageContextImpl> it = pcs.values().iterator();
                            PageContextImpl tmp;
                            while (it.hasNext()) {
                                tmp = it.next();
                                if (t == tmp.getThread()) {
                                    pc = tmp;
                                    break;
                                }
                            }
                        }
                    }
                    if (pc != null) {
                        add = " The file is locked by a request on the following URL " + ReqRspUtil.getRequestURL(pc.getHttpServletRequest(), true) + ", that request started " + (System.currentTimeMillis() - pc.getStartTime()) + "ms ago.";
                    }
                    SystemOut.printDate(config.getErrWriter(), "timeout after " + (now - start) + " ms (" + (lockTimeout) + " ms) occured while accessing file [" + path + "]." + add);
                } else
                    SystemOut.printDate("timeout (" + (lockTimeout) + " ms) occured while accessing file [" + path + "].");
                return;
            }
        } catch (InterruptedException e) {
        }
    } while (true);
}
Also used : CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) Config(lucee.runtime.config.Config) CFMLFactory(lucee.runtime.CFMLFactory) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb)

Example 83 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class LocaleCalendarThreadLocal method toString.

@Override
public String toString(PageContext pc, DateTime dt, TimeZone tz, Boolean addTimeZoneOffset) {
    Calendar c = _getThreadCalendar(pc, tz);
    c.setTimeInMillis(dt.getTime());
    // "HH:mm:ss"
    StringBuilder sb = new StringBuilder();
    sb.append("{ts '");
    toString(sb, c.get(Calendar.YEAR), 4);
    sb.append("-");
    toString(sb, c.get(Calendar.MONTH) + 1, 2);
    sb.append("-");
    toString(sb, c.get(Calendar.DATE), 2);
    sb.append(" ");
    toString(sb, c.get(Calendar.HOUR_OF_DAY), 2);
    sb.append(":");
    toString(sb, c.get(Calendar.MINUTE), 2);
    sb.append(":");
    toString(sb, c.get(Calendar.SECOND), 2);
    if (addTimeZoneOffset != Boolean.FALSE) {
        if (addTimeZoneOffset == null && pc != null)
            addTimeZoneOffset = ((PageContextImpl) pc).getTimestampWithTSOffset();
        if (addTimeZoneOffset == Boolean.TRUE)
            addTimeZoneOffset(c, sb);
    }
    sb.append("'}");
    return sb.toString();
}
Also used : Calendar(java.util.Calendar) PageContextImpl(lucee.runtime.PageContextImpl)

Example 84 with PageContextImpl

use of lucee.runtime.PageContextImpl in project Lucee by lucee.

the class MacAddressWrap method run.

public void run() {
    PageContextImpl pci = (PageContextImpl) pc;
    Thread thread = pc.getThread();
    if (thread == null)
        return;
    if (thread.isAlive()) {
        pci.setTimeoutStackTrace();
        thread.stop();
    }
}
Also used : PageContextImpl(lucee.runtime.PageContextImpl)

Aggregations

PageContextImpl (lucee.runtime.PageContextImpl)84 PageSource (lucee.runtime.PageSource)19 Resource (lucee.commons.io.res.Resource)17 Key (lucee.runtime.type.Collection.Key)15 Struct (lucee.runtime.type.Struct)15 StructImpl (lucee.runtime.type.StructImpl)14 IOException (java.io.IOException)12 ApplicationException (lucee.runtime.exp.ApplicationException)10 PageException (lucee.runtime.exp.PageException)10 Component (lucee.runtime.Component)9 ConfigWeb (lucee.runtime.config.ConfigWeb)9 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)9 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ArrayList (java.util.ArrayList)6 Mapping (lucee.runtime.Mapping)6 PageContext (lucee.runtime.PageContext)6 ConfigImpl (lucee.runtime.config.ConfigImpl)6 ExpressionException (lucee.runtime.exp.ExpressionException)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5