Search in sources :

Example 1 with RequestImpl

use of lucee.runtime.type.scope.RequestImpl in project Lucee by lucee.

the class Lock method doStartTag.

@Override
public int doStartTag() throws PageException {
    if (timeoutInMillis <= 0) {
        TimeSpan remaining = PageContextUtil.remainingTime(pageContext, true);
        this.timeoutInMillis = toInt(remaining.getMillis());
    }
    manager = pageContext.getConfig().getLockManager();
    // check attributes
    if (name != null && scope != SCOPE_NONE) {
        throw new LockException(LockException.OPERATION_CREATE, this.name, "invalid attribute combination", "attribute [name] and [scope] can't be used together");
    }
    if (name == null && scope == SCOPE_NONE) {
        name = "id-" + id;
    }
    String lockType = null;
    if (name == null) {
        String cid = pageContext.getConfig().getIdentification().getId();
        // Session
        if (scope == SCOPE_REQUEST) {
            lockType = "request";
            name = "__request_" + cid + "__" + ((RequestImpl) pageContext.requestScope())._getId();
        } else // Session
        if (scope == SCOPE_SESSION) {
            lockType = "session";
            name = "__session_" + cid + "__" + pageContext.sessionScope()._getId();
        } else // Application
        if (scope == SCOPE_APPLICATION) {
            lockType = "application";
            name = "__application_" + cid + "__" + ((ApplicationImpl) pageContext.applicationScope())._getId();
        } else // Server
        if (scope == SCOPE_SERVER) {
            lockType = "server";
            name = "__server_" + ((ServerImpl) pageContext.serverScope())._getId();
        }
    }
    Struct cflock = new StructImpl();
    cflock.set("succeeded", Boolean.TRUE);
    cflock.set("errortext", "");
    pageContext.setVariable(result, cflock);
    start = System.nanoTime();
    try {
        // this has to be first, otherwise LockTimeoutException has nothing to release
        ((PageContextImpl) pageContext).setActiveLock(new ActiveLock(type, name, timeoutInMillis));
        data = manager.lock(type, name, timeoutInMillis, pageContext.getId());
    } catch (LockTimeoutException e) {
        LockManagerImpl mi = (LockManagerImpl) manager;
        Boolean hasReadLock = mi.isReadLocked(name);
        Boolean hasWriteLock = mi.isWriteLocked(name);
        String msg = LockTimeoutExceptionImpl.createMessage(type, name, lockType, timeoutInMillis, hasReadLock, hasWriteLock);
        _release(pageContext, System.nanoTime() - start);
        name = null;
        cflock.set("succeeded", Boolean.FALSE);
        cflock.set("errortext", msg);
        if (throwontimeout)
            throw new LockException(LockException.OPERATION_TIMEOUT, this.name, msg);
        return SKIP_BODY;
    } catch (InterruptedException e) {
        _release(pageContext, System.nanoTime() - start);
        cflock.set("succeeded", Boolean.FALSE);
        cflock.set("errortext", e.getMessage());
        if (throwontimeout)
            throw Caster.toPageException(e);
        return SKIP_BODY;
    }
    return EVAL_BODY_INCLUDE;
}
Also used : ApplicationImpl(lucee.runtime.type.scope.ApplicationImpl) PageContextImpl(lucee.runtime.PageContextImpl) Struct(lucee.runtime.type.Struct) TimeSpan(lucee.runtime.type.dt.TimeSpan) StructImpl(lucee.runtime.type.StructImpl) ActiveLock(lucee.runtime.debug.ActiveLock) LockException(lucee.runtime.exp.LockException) LockManagerImpl(lucee.runtime.lock.LockManagerImpl) RequestImpl(lucee.runtime.type.scope.RequestImpl) LockTimeoutException(lucee.runtime.lock.LockTimeoutException)

Example 2 with RequestImpl

use of lucee.runtime.type.scope.RequestImpl in project Lucee by lucee.

the class PageContextImpl method initialize.

/**
 * initialize a existing page context
 * @param servlet
 * @param req
 * @param rsp
 * @param errorPageURL
 * @param needsSession
 * @param bufferSize
 * @param autoFlush
 */
public PageContextImpl initialize(HttpServlet servlet, HttpServletRequest req, HttpServletResponse rsp, String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush, boolean isChild, boolean ignoreScopes) {
    parent = null;
    appListenerType = ApplicationListener.TYPE_NONE;
    this.ignoreScopes = ignoreScopes;
    requestId = counter++;
    ReqRspUtil.setContentType(rsp, "text/html; charset=" + config.getWebCharset().name());
    this.isChild = isChild;
    applicationContext = defaultApplicationContext;
    startTime = System.currentTimeMillis();
    thread = Thread.currentThread();
    this.req = new HTTPServletRequestWrap(req);
    this.rsp = rsp;
    this.servlet = servlet;
    // Writers
    if (config.debugLogOutput()) {
        CFMLWriter w = config.getCFMLWriter(this, req, rsp);
        w.setAllowCompression(false);
        DebugCFMLWriter dcw = new DebugCFMLWriter(w);
        bodyContentStack.init(dcw);
        debugger.setOutputLog(dcw);
    } else {
        bodyContentStack.init(config.getCFMLWriter(this, req, rsp));
    }
    writer = bodyContentStack.getWriter();
    forceWriter = writer;
    // Scopes
    server = ScopeContext.getServerScope(this, ignoreScopes);
    if (hasFamily) {
        variablesRoot = new VariablesImpl();
        variables = variablesRoot;
        request = new RequestImpl();
        _url = new URLImpl();
        _form = new FormImpl();
        urlForm = new UrlFormImpl(_form, _url);
        undefined = new UndefinedImpl(this, getScopeCascadingType());
        hasFamily = false;
    } else if (variables == null) {
        variablesRoot = new VariablesImpl();
        variables = variablesRoot;
    }
    request.initialize(this);
    if (config.mergeFormAndURL()) {
        url = urlForm;
        form = urlForm;
    } else {
        url = _url;
        form = _form;
    }
    // url.initialize(this);
    // form.initialize(this);
    // undefined.initialize(this);
    psq = config.getPSQL();
    fdEnabled = !config.allowRequestTimeout();
    if (config.getExecutionLogEnabled())
        this.execLog = config.getExecutionLogFactory().getInstance(this);
    if (debugger != null)
        debugger.init(config);
    undefined.initialize(this);
    timeoutStacktrace = null;
    return this;
}
Also used : UrlFormImpl(lucee.runtime.type.scope.UrlFormImpl) UndefinedImpl(lucee.runtime.type.scope.UndefinedImpl) HTTPServletRequestWrap(lucee.runtime.net.http.HTTPServletRequestWrap) DebugCFMLWriter(lucee.runtime.debug.DebugCFMLWriter) CFMLWriter(lucee.runtime.writer.CFMLWriter) UrlFormImpl(lucee.runtime.type.scope.UrlFormImpl) FormImpl(lucee.runtime.type.scope.FormImpl) VariablesImpl(lucee.runtime.type.scope.VariablesImpl) DebugCFMLWriter(lucee.runtime.debug.DebugCFMLWriter) RequestImpl(lucee.runtime.type.scope.RequestImpl) URLImpl(lucee.runtime.type.scope.URLImpl)

Aggregations

RequestImpl (lucee.runtime.type.scope.RequestImpl)2 PageContextImpl (lucee.runtime.PageContextImpl)1 ActiveLock (lucee.runtime.debug.ActiveLock)1 DebugCFMLWriter (lucee.runtime.debug.DebugCFMLWriter)1 LockException (lucee.runtime.exp.LockException)1 LockManagerImpl (lucee.runtime.lock.LockManagerImpl)1 LockTimeoutException (lucee.runtime.lock.LockTimeoutException)1 HTTPServletRequestWrap (lucee.runtime.net.http.HTTPServletRequestWrap)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1 TimeSpan (lucee.runtime.type.dt.TimeSpan)1 ApplicationImpl (lucee.runtime.type.scope.ApplicationImpl)1 FormImpl (lucee.runtime.type.scope.FormImpl)1 URLImpl (lucee.runtime.type.scope.URLImpl)1 UndefinedImpl (lucee.runtime.type.scope.UndefinedImpl)1 UrlFormImpl (lucee.runtime.type.scope.UrlFormImpl)1 VariablesImpl (lucee.runtime.type.scope.VariablesImpl)1 CFMLWriter (lucee.runtime.writer.CFMLWriter)1