Search in sources :

Example 16 with CFMLFactoryImpl

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

the class GetUsageData method call.

public static Struct call(PageContext pc) throws PageException {
    ConfigWeb cw = pc.getConfig();
    ConfigServer cs = cw.getConfigServer("server");
    ConfigWeb[] webs = cs.getConfigWebs();
    CFMLEngineFactory.getInstance();
    CFMLEngineImpl engine = (CFMLEngineImpl) cs.getCFMLEngine();
    Struct sct = new StructImpl();
    // Locks
    /*LockManager manager = pc.getConfig().getLockManager();
        String[] locks = manager.getOpenLockNames();
        for(int i=0;i<locks.length;i++){
        	locks[i].
        }
        if(!ArrayUtil.isEmpty(locks)) 
        	strLocks=" open locks at this time ("+List.arrayToList(locks, ", ")+").";
		*/
    // Requests
    Query req = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._uri, START_TIME, KeyConstants._timeout }, 0, "requests");
    sct.setEL(KeyConstants._requests, req);
    // Template Cache
    Query tc = new QueryImpl(new Collection.Key[] { KeyConstants._web, ELEMENTS, KeyConstants._size }, 0, "templateCache");
    sct.setEL(KeyImpl.init("templateCache"), tc);
    // Scopes
    Struct scopes = new StructImpl();
    sct.setEL(KeyConstants._scopes, scopes);
    Query app = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, ELEMENTS, KeyConstants._size }, 0, "templateCache");
    scopes.setEL(KeyConstants._application, app);
    Query sess = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, USERS, ELEMENTS, KeyConstants._size }, 0, "templateCache");
    scopes.setEL(KeyConstants._session, sess);
    // Query
    Query qry = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, START_TIME, KeyConstants._sql }, 0, "requests");
    sct.setEL(QUERIES, qry);
    // Locks
    Query lck = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, KeyConstants._name, START_TIME, KeyConstants._timeout, KeyConstants._type }, 0, "requests");
    sct.setEL(LOCKS, lck);
    // Loop webs
    ConfigWebImpl web;
    Map<Integer, PageContextImpl> pcs;
    PageContextImpl _pc;
    int row, openConnections = 0;
    CFMLFactoryImpl factory;
    ActiveQuery[] queries;
    ActiveQuery aq;
    ActiveLock[] locks;
    ActiveLock al;
    for (int i = 0; i < webs.length; i++) {
        // Loop requests
        web = (ConfigWebImpl) webs[i];
        factory = (CFMLFactoryImpl) web.getFactory();
        pcs = factory.getActivePageContexts();
        Iterator<PageContextImpl> it = pcs.values().iterator();
        while (it.hasNext()) {
            _pc = it.next();
            if (_pc.isGatewayContext())
                continue;
            // Request
            row = req.addRow();
            req.setAt(KeyConstants._web, row, web.getLabel());
            req.setAt(KeyConstants._uri, row, getPath(_pc.getHttpServletRequest()));
            req.setAt(START_TIME, row, new DateTimeImpl(pc.getStartTime(), false));
            req.setAt(KeyConstants._timeout, row, new Double(pc.getRequestTimeout()));
            // Query
            queries = _pc.getActiveQueries();
            if (queries != null) {
                for (int y = 0; y < queries.length; y++) {
                    aq = queries[y];
                    row = qry.addRow();
                    qry.setAt(KeyConstants._web, row, web.getLabel());
                    qry.setAt(KeyConstants._application, row, _pc.getApplicationContext().getName());
                    qry.setAt(START_TIME, row, new DateTimeImpl(web, aq.startTime, true));
                    qry.setAt(KeyConstants._sql, row, aq.sql);
                }
            }
            // Lock
            locks = _pc.getActiveLocks();
            if (locks != null) {
                for (int y = 0; y < locks.length; y++) {
                    al = locks[y];
                    row = lck.addRow();
                    lck.setAt(KeyConstants._web, row, web.getLabel());
                    lck.setAt(KeyConstants._application, row, _pc.getApplicationContext().getName());
                    lck.setAt(KeyConstants._name, row, al.name);
                    lck.setAt(START_TIME, row, new DateTimeImpl(web, al.startTime, true));
                    lck.setAt(KeyConstants._timeout, row, Caster.toDouble(al.timeoutInMillis / 1000));
                    lck.setAt(KeyConstants._type, row, al.type == LockManager.TYPE_EXCLUSIVE ? "exclusive" : "readonly");
                }
            }
        }
        Iterator<Integer> _it = web.getDatasourceConnectionPool().openConnections().values().iterator();
        while (_it.hasNext()) {
            openConnections += _it.next().intValue();
        }
        // Template Cache
        Mapping[] mappings = ConfigWebUtil.getAllMappings(web);
        long[] tce = templateCacheElements(mappings);
        row = tc.addRow();
        tc.setAt(KeyConstants._web, row, web.getLabel());
        tc.setAt(KeyConstants._size, row, new Double(tce[1]));
        tc.setAt(ELEMENTS, row, new Double(tce[0]));
        // Scope Application
        getAllApplicationScopes(web, factory.getScopeContext(), app);
        getAllCFSessionScopes(web, factory.getScopeContext(), sess);
    }
    // Datasource
    Struct ds = new StructImpl();
    sct.setEL(KeyConstants._datasources, ds);
    // there is only one cache for all contexts
    ds.setEL(CACHED_QUERIES, Caster.toDouble(pc.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_QUERY, null).size(pc)));
    // ds.setEL(CACHED_QUERIES, Caster.toDouble(pc.getQueryCache().size(pc))); // there is only one cache for all contexts
    ds.setEL(OPEN_CONNECTIONS, Caster.toDouble(openConnections));
    // Memory
    Struct mem = new StructImpl();
    sct.setEL(KeyConstants._memory, mem);
    mem.setEL("heap", SystemUtil.getMemoryUsageAsStruct(SystemUtil.MEMORY_TYPE_HEAP));
    mem.setEL("nonheap", SystemUtil.getMemoryUsageAsStruct(SystemUtil.MEMORY_TYPE_NON_HEAP));
    // uptime
    sct.set("uptime", new DateTimeImpl(engine.uptime(), true));
    // now
    sct.set("now", new DateTimeImpl(pc));
    return sct;
}
Also used : ActiveQuery(lucee.runtime.debug.ActiveQuery) Query(lucee.runtime.type.Query) Mapping(lucee.runtime.Mapping) Struct(lucee.runtime.type.Struct) QueryImpl(lucee.runtime.type.QueryImpl) ActiveLock(lucee.runtime.debug.ActiveLock) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) ConfigServer(lucee.runtime.config.ConfigServer) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) StructImpl(lucee.runtime.type.StructImpl) ActiveQuery(lucee.runtime.debug.ActiveQuery) Collection(lucee.runtime.type.Collection)

Example 17 with CFMLFactoryImpl

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

the class InternalRequest method call.

public static Struct call(final PageContext pc, String template, String method, Struct urls, Struct forms, Struct cookies, Struct headers, Object body, String strCharset, boolean addToken) throws PageException {
    // add token
    if (addToken) {
        // if(true) throw new ApplicationException("addtoken==true");
        if (cookies == null)
            cookies = new StructImpl();
        cookies.set(KeyConstants._cfid, pc.getCFID());
        cookies.set(KeyConstants._cftoken, pc.getCFToken());
        String jsessionid = pc.getJSessionId();
        if (jsessionid != null)
            cookies.set("jsessionid", jsessionid);
    }
    // charset
    Charset reqCharset = StringUtil.isEmpty(strCharset) ? pc.getWebCharset() : CharsetUtil.toCharset(strCharset);
    String ext = ResourceUtil.getExtension(template, null);
    // welcome files
    if (StringUtil.isEmpty(ext)) {
        throw new FunctionException(pc, "Invoke", 1, "url", "welcome file listing not supported, please define the template name.");
    }
    // dialect
    int dialect = ((CFMLFactoryImpl) pc.getConfig().getFactory()).toDialect(ext, -1);
    if (dialect == -1)
        dialect = pc.getCurrentTemplateDialect();
    // CFMLEngine.DIALECT_LUCEE
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] _barr = null;
    if (Decision.isBinary(body))
        _barr = Caster.toBinary(body);
    else if (body != null) {
        Charset cs = null;
        // get charset
        if (headers != null) {
            String strCT = Caster.toString(headers.get(CONTENT_TYPE), null);
            if (strCT != null) {
                ContentType ct = HTTPUtil.toContentType(strCT, null);
                if (ct != null) {
                    String strCS = ct.getCharset();
                    if (!StringUtil.isEmpty(strCS))
                        cs = CharsetUtil.toCharSet(strCS, CharSet.UTF8).toCharset();
                }
            }
        }
        if (cs == null)
            cs = CharsetUtil.UTF8;
        String str = Caster.toString(body);
        _barr = str.getBytes(cs);
    }
    PageContextImpl _pc = createPageContext(pc, template, urls, cookies, headers, _barr, reqCharset, baos);
    fillForm(_pc, forms);
    Collection cookie, request, session = null;
    int status;
    long exeTime;
    boolean isText = false;
    Charset _charset = null;
    try {
        if (CFMLEngine.DIALECT_LUCEE == dialect)
            _pc.execute(template, true, false);
        else
            _pc.executeCFML(template, true, false);
    } finally {
        _pc.flush();
        cookie = _pc.cookieScope().duplicate(false);
        request = _pc.requestScope().duplicate(false);
        session = sessionEnabled(_pc) ? _pc.sessionScope().duplicate(false) : null;
        exeTime = System.currentTimeMillis() - pc.getStartTime();
        // debugging=_pc.getDebugger().getDebuggingData(_pc).duplicate(false);
        HttpServletResponseDummy rsp = (HttpServletResponseDummy) _pc.getHttpServletResponse();
        // headers
        Collection.Key name;
        headers = new StructImpl();
        Iterator<String> it = rsp.getHeaderNames().iterator();
        java.util.Collection<String> values;
        while (it.hasNext()) {
            name = KeyImpl.init(it.next());
            values = rsp.getHeaders(name.getString());
            if (values == null || values.size() == 0)
                continue;
            if (values.size() > 1)
                headers.set(name, Caster.toArray(values));
            else
                headers.set(name, values.iterator().next());
        }
        // status
        status = rsp.getStatus();
        ContentType ct = HTTPUtil.toContentType(rsp.getContentType(), null);
        if (ct != null) {
            isText = HTTPUtil.isTextMimeType(ct.getMimeType());
            if (ct.getCharset() != null)
                _charset = CharsetUtil.toCharset(ct.getCharset(), null);
        }
        releasePageContext(_pc, pc);
    }
    Struct rst = new StructImpl();
    byte[] barr = baos.toByteArray();
    if (isText)
        rst.set(KeyConstants._filecontent, new String(barr, _charset == null ? reqCharset : _charset));
    else
        rst.set(FILECONTENT_BYNARY, barr);
    rst.set(KeyConstants._cookies, cookie);
    rst.set(KeyConstants._request, request);
    if (session != null)
        rst.set(KeyConstants._session, session);
    rst.set(KeyConstants._headers, headers);
    // rst.put(KeyConstants._debugging, debugging);
    rst.set(KeyConstants._executionTime, new Double(exeTime));
    rst.set(KeyConstants._status, new Double(status));
    rst.set(STATUS_CODE, new Double(status));
    return rst;
}
Also used : ContentType(lucee.commons.lang.mimetype.ContentType) FunctionException(lucee.runtime.exp.FunctionException) Charset(java.nio.charset.Charset) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PageContextImpl(lucee.runtime.PageContextImpl) Struct(lucee.runtime.type.Struct) Key(lucee.runtime.type.Collection.Key) StructImpl(lucee.runtime.type.StructImpl) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) Collection(lucee.runtime.type.Collection) HttpServletResponseDummy(lucee.runtime.net.http.HttpServletResponseDummy)

Example 18 with CFMLFactoryImpl

use of lucee.runtime.CFMLFactoryImpl 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 19 with CFMLFactoryImpl

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

the class SessionTracker method getSessionCollection.

public static Struct getSessionCollection(String appName) {
    PageContext pc = ThreadLocalPageContext.get();
    ScopeContext sc = ((CFMLFactoryImpl) pc.getCFMLFactory()).getScopeContext();
    return sc.getAllSessionScopes(appName);
}
Also used : ScopeContext(lucee.runtime.type.scope.ScopeContext) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext)

Example 20 with CFMLFactoryImpl

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

the class SessionTracker method getSessionCount.

public static int getSessionCount() {
    PageContext pc = ThreadLocalPageContext.get();
    ScopeContext sc = ((CFMLFactoryImpl) pc.getCFMLFactory()).getScopeContext();
    return sc.getSessionCount(pc);
}
Also used : ScopeContext(lucee.runtime.type.scope.ScopeContext) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext)

Aggregations

CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)20 PageContextImpl (lucee.runtime.PageContextImpl)7 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)7 Collection (lucee.runtime.type.Collection)5 ScopeContext (lucee.runtime.type.scope.ScopeContext)5 ConfigWeb (lucee.runtime.config.ConfigWeb)4 ApplicationException (lucee.runtime.exp.ApplicationException)4 Struct (lucee.runtime.type.Struct)4 StructImpl (lucee.runtime.type.StructImpl)4 BundleCollection (lucee.loader.osgi.BundleCollection)3 CFMLFactory (lucee.runtime.CFMLFactory)3 PageContext (lucee.runtime.PageContext)3 ConfigServer (lucee.runtime.config.ConfigServer)3 Key (lucee.runtime.type.Collection.Key)3 MalformedURLException (java.net.MalformedURLException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 ConfigServerImpl (lucee.runtime.config.ConfigServerImpl)2 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)2 NativeException (lucee.runtime.exp.NativeException)2 PageServletException (lucee.runtime.exp.PageServletException)2