Search in sources :

Example 26 with ConfigWeb

use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.

the class PageSourceImpl method getDialect.

@Override
public int getDialect() {
    Config c = getMapping().getConfig();
    if (!((ConfigImpl) c).allowLuceeDialect())
        return CFMLEngine.DIALECT_CFML;
    // MUST improve performance on this
    ConfigWeb cw = null;
    String ext = ResourceUtil.getExtension(relPath, Constants.getCFMLComponentExtension());
    if (c instanceof ConfigWeb)
        cw = (ConfigWeb) c;
    else {
        c = ThreadLocalPageContext.getConfig();
        if (c instanceof ConfigWeb)
            cw = (ConfigWeb) c;
    }
    if (cw != null) {
        return ((CFMLFactoryImpl) cw.getFactory()).toDialect(ext, CFMLEngine.DIALECT_CFML);
    }
    return ConfigWebUtil.toDialect(ext, CFMLEngine.DIALECT_CFML);
}
Also used : Config(lucee.runtime.config.Config) ConfigWeb(lucee.runtime.config.ConfigWeb)

Example 27 with ConfigWeb

use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.

the class PageSourceImpl method loadPhysical.

/**
 * throws only an exception when compilation fails
 * @param pc
 * @param page
 * @return
 * @throws PageException
 */
private Page loadPhysical(PageContext pc, Page page) throws TemplateException {
    if (!mapping.hasPhysical())
        return null;
    ConfigWeb config = pc.getConfig();
    PageContextImpl pci = (PageContextImpl) pc;
    if ((mapping.getInspectTemplate() == Config.INSPECT_NEVER || pci.isTrusted(page)) && isLoad(LOAD_PHYSICAL))
        return page;
    Resource srcFile = getPhyscalFile();
    long srcLastModified = srcFile.lastModified();
    if (srcLastModified == 0L)
        return null;
    // Page exists
    if (page != null) {
        // if(page!=null && !recompileAlways) {
        if (srcLastModified != page.getSourceLastModified()) {
            // same size, maybe the content has not changed?
            boolean same = false;
            if (page instanceof PagePro && ((PagePro) page).getSourceLength() == srcFile.length()) {
                PagePro pp = (PagePro) page;
                try {
                    same = pp.getHash() == PageSourceCode.toString(this, config.getTemplateCharset()).hashCode();
                } catch (IOException e) {
                /*in case this exception happen, the following compile process will fail as well and report the error*/
                }
            }
            if (!same) {
                this.page = page = compile(config, mapping.getClassRootDirectory(), page, false, pc.ignoreScopes());
                page.setPageSource(this);
                page.setLoadType(LOAD_PHYSICAL);
            }
        }
    } else // page doesn't exist
    {
        Resource classRootDir = mapping.getClassRootDirectory();
        Resource classFile = classRootDir.getRealResource(getJavaName() + ".class");
        boolean isNew = false;
        // new class
        if (flush || !classFile.exists()) {
            this.page = page = compile(config, classRootDir, null, false, pc.ignoreScopes());
            flush = false;
            isNew = true;
        } else // load page
        {
            try {
                this.page = page = newInstance(mapping.getPhysicalClass(this.getClassName()));
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
                this.page = page = null;
            }
            if (page == null)
                this.page = page = compile(config, classRootDir, null, false, pc.ignoreScopes());
        }
        // check if version changed or lasMod
        if (!isNew && (srcLastModified != page.getSourceLastModified() || page.getVersion() != pc.getConfig().getFactory().getEngine().getInfo().getFullVersionInfo())) {
            isNew = true;
            this.page = page = compile(config, classRootDir, page, false, pc.ignoreScopes());
        }
        page.setPageSource(this);
        page.setLoadType(LOAD_PHYSICAL);
    }
    pci.setPageUsed(page);
    return page;
}
Also used : Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) ConfigWeb(lucee.runtime.config.ConfigWeb)

Example 28 with ConfigWeb

use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.

the class CallStackGet method abs.

private static String abs(PageContextImpl pc, String template) {
    ConfigWeb config = pc.getConfig();
    Resource res = config.getResource(template);
    if (res.exists())
        return template;
    PageSource ps = pc == null ? null : pc.getPageSource(template);
    res = ps == null ? null : ps.getPhyscalFile();
    if (res == null || !res.exists()) {
        res = config.getResource(ps.getDisplayPath());
        if (res != null && res.exists())
            return res.getAbsolutePath();
    } else
        return res.getAbsolutePath();
    return template;
}
Also used : Resource(lucee.commons.io.res.Resource) ConfigWeb(lucee.runtime.config.ConfigWeb) PageSource(lucee.runtime.PageSource)

Example 29 with ConfigWeb

use of lucee.runtime.config.ConfigWeb 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 30 with ConfigWeb

use of lucee.runtime.config.ConfigWeb in project Lucee by lucee.

the class GatewayEngineImpl method call.

public Object call(String cfcPath, String id, String functionName, Struct arguments, boolean cfcPeristent, Object defaultValue) throws PageException {
    String requestURI = toRequestURI(cfcPath);
    PageContext oldPC = ThreadLocalPageContext.get();
    PageContextImpl pc = null;
    try {
        pc = createPageContext(requestURI, id, functionName, arguments, cfcPeristent, true);
        String ext = ResourceUtil.getExtension(cfcPath, null);
        ConfigWeb config = (ConfigWeb) ThreadLocalPageContext.getConfig();
        int dialect = ext == null ? CFMLEngine.DIALECT_CFML : config.getFactory().toDialect(ext);
        // ThreadLocalPageContext.register(pc);
        Component cfc = getCFC(pc, requestURI);
        if (cfc.containsKey(functionName)) {
            if (dialect == CFMLEngine.DIALECT_LUCEE)
                pc.execute(requestURI, true, false);
            else
                pc.executeCFML(requestURI, true, false);
            // Result
            return pc.variablesScope().get(AMF_FORWARD, null);
        }
    } finally {
        CFMLFactory f = config.getFactory();
        f.releaseLuceePageContext(pc, true);
        ThreadLocalPageContext.register(oldPC);
    }
    return defaultValue;
}
Also used : ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) PageContext(lucee.runtime.PageContext) CFMLFactory(lucee.runtime.CFMLFactory) PageContextImpl(lucee.runtime.PageContextImpl) Component(lucee.runtime.Component) ConfigWeb(lucee.runtime.config.ConfigWeb)

Aggregations

ConfigWeb (lucee.runtime.config.ConfigWeb)34 Resource (lucee.commons.io.res.Resource)9 PageContextImpl (lucee.runtime.PageContextImpl)9 StructImpl (lucee.runtime.type.StructImpl)7 PageSource (lucee.runtime.PageSource)6 ConfigServer (lucee.runtime.config.ConfigServer)6 IOException (java.io.IOException)5 CFMLFactory (lucee.runtime.CFMLFactory)5 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)5 ThreadLocalPageContext (lucee.runtime.engine.ThreadLocalPageContext)5 PageException (lucee.runtime.exp.PageException)5 Struct (lucee.runtime.type.Struct)5 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)4 PageContext (lucee.runtime.PageContext)4 Config (lucee.runtime.config.Config)4 Log (lucee.commons.io.log.Log)3 Pair (lucee.commons.lang.Pair)3 Component (lucee.runtime.Component)3 Query (lucee.runtime.type.Query)3 QueryImpl (lucee.runtime.type.QueryImpl)3