Search in sources :

Example 1 with CFMLEngineImpl

use of lucee.runtime.engine.CFMLEngineImpl in project Lucee by lucee.

the class XMLConfigServerFactory method reloadInstance.

/**
 * reloads the Config Object
 * @param configServer
 * @throws SAXException
 * @throws ClassNotFoundException
 * @throws PageException
 * @throws IOException
 * @throws TagLibException
 * @throws FunctionLibException
 * @throws BundleException
 */
public static void reloadInstance(CFMLEngine engine, ConfigServerImpl configServer) throws SAXException, ClassException, PageException, IOException, TagLibException, FunctionLibException, BundleException {
    Resource configFile = configServer.getConfigFile();
    if (configFile == null)
        return;
    if (second(configServer.getLoadTime()) > second(configFile.lastModified()))
        return;
    int iDoNew = doNew(engine, configServer.getConfigDir(), false).updateType;
    boolean doNew = iDoNew != NEW_NONE;
    load(configServer, loadDocument(configFile), true, doNew);
    ((CFMLEngineImpl) ConfigWebUtil.getEngine(configServer)).onStart(configServer, true);
}
Also used : CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) Resource(lucee.commons.io.res.Resource) FileResource(lucee.commons.io.res.type.file.FileResource)

Example 2 with CFMLEngineImpl

use of lucee.runtime.engine.CFMLEngineImpl in project Lucee by lucee.

the class XMLConfigServerFactory method newInstance.

/**
 * creates a new ServletConfig Impl Object
 * @param engine
 * @param initContextes
 * @param contextes
 * @param configDir
 * @return new Instance
 * @throws SAXException
 * @throws ClassNotFoundException
 * @throws PageException
 * @throws IOException
 * @throws TagLibException
 * @throws FunctionLibException
 * @throws BundleException
 */
public static ConfigServerImpl newInstance(CFMLEngineImpl engine, Map<String, CFMLFactory> initContextes, Map<String, CFMLFactory> contextes, Resource configDir) throws SAXException, ClassException, PageException, IOException, TagLibException, FunctionLibException, BundleException {
    boolean isCLI = SystemUtil.isCLICall();
    if (isCLI) {
        Resource logs = configDir.getRealResource("logs");
        logs.mkdirs();
        Resource out = logs.getRealResource("out");
        Resource err = logs.getRealResource("err");
        ResourceUtil.touch(out);
        ResourceUtil.touch(err);
        if (logs instanceof FileResource) {
            SystemUtil.setPrintWriter(SystemUtil.OUT, new PrintWriter((FileResource) out));
            SystemUtil.setPrintWriter(SystemUtil.ERR, new PrintWriter((FileResource) err));
        } else {
            SystemUtil.setPrintWriter(SystemUtil.OUT, new PrintWriter(IOUtil.getWriter(out, "UTF-8")));
            SystemUtil.setPrintWriter(SystemUtil.ERR, new PrintWriter(IOUtil.getWriter(err, "UTF-8")));
        }
    }
    SystemOut.print(SystemUtil.getPrintWriter(SystemUtil.OUT), "===================================================================\n" + "SERVER CONTEXT\n" + "-------------------------------------------------------------------\n" + "- config:" + configDir + "\n" + "- loader-version:" + SystemUtil.getLoaderVersion() + "\n" + "- core-version:" + engine.getInfo().getVersion() + "\n" + "===================================================================\n");
    int iDoNew = doNew(engine, configDir, false).updateType;
    boolean doNew = iDoNew != NEW_NONE;
    Resource configFile = configDir.getRealResource("lucee-server.xml");
    if (!configFile.exists()) {
        configFile.createFile(true);
        // InputStream in = new TextFile("").getClass().getResourceAsStream("/resource/config/server.xml");
        createFileFromResource("/resource/config/server.xml", configFile.getAbsoluteResource(), "tpiasfap");
    }
    Document doc = loadDocumentCreateIfFails(configFile, "server");
    // get version
    Element luceeConfiguration = doc.getDocumentElement();
    String strVersion = luceeConfiguration.getAttribute("version");
    double version = Caster.toDoubleValue(strVersion, 1.0d);
    boolean cleanupDatasources = version < 5.0D;
    ConfigServerImpl config = new ConfigServerImpl(engine, initContextes, contextes, configDir, configFile);
    load(config, doc, false, doNew);
    createContextFiles(configDir, config, doNew, cleanupDatasources);
    ((CFMLEngineImpl) ConfigWebUtil.getEngine(config)).onStart(config, false);
    return config;
}
Also used : CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) Element(org.w3c.dom.Element) Resource(lucee.commons.io.res.Resource) FileResource(lucee.commons.io.res.type.file.FileResource) FileResource(lucee.commons.io.res.type.file.FileResource) Document(org.w3c.dom.Document) PrintWriter(java.io.PrintWriter)

Example 3 with CFMLEngineImpl

use of lucee.runtime.engine.CFMLEngineImpl in project Lucee by lucee.

the class XMLConfigWebFactory method loadMonitors.

private static void loadMonitors(ConfigServerImpl configServer, ConfigImpl config, Document doc) throws IOException {
    // only load in server context
    if (configServer != null)
        return;
    configServer = (ConfigServerImpl) config;
    Element parent = getChildByName(doc.getDocumentElement(), "monitoring");
    boolean enabled = Caster.toBooleanValue(getAttr(parent, "enabled"), false);
    configServer.setMonitoringEnabled(enabled);
    SystemOut.printDate(config.getOutWriter(), "monitoring is " + (enabled ? "enabled" : "disabled"));
    Element[] children = getChildren(parent, "monitor");
    java.util.List<IntervallMonitor> intervalls = new ArrayList<IntervallMonitor>();
    java.util.List<RequestMonitor> requests = new ArrayList<RequestMonitor>();
    java.util.List<MonitorTemp> actions = new ArrayList<MonitorTemp>();
    String strType, name;
    ClassDefinition cd;
    boolean log, async;
    short type;
    for (int i = 0; i < children.length; i++) {
        Element el = children[i];
        cd = getClassDefinition(el, "", config.getIdentification());
        strType = getAttr(el, "type");
        name = getAttr(el, "name");
        async = Caster.toBooleanValue(getAttr(el, "async"), false);
        log = Caster.toBooleanValue(getAttr(el, "log"), true);
        if ("request".equalsIgnoreCase(strType))
            type = IntervallMonitor.TYPE_REQUEST;
        else if ("action".equalsIgnoreCase(strType))
            type = Monitor.TYPE_ACTION;
        else
            type = IntervallMonitor.TYPE_INTERVAL;
        if (cd.hasClass() && !StringUtil.isEmpty(name)) {
            name = name.trim();
            try {
                Class clazz = cd.getClazz();
                Object obj;
                ConstructorInstance constr = Reflector.getConstructorInstance(clazz, new Object[] { configServer }, null);
                if (constr != null)
                    obj = constr.invoke();
                else
                    obj = clazz.newInstance();
                SystemOut.printDate(config.getOutWriter(), "loaded " + (strType) + " monitor [" + clazz.getName() + "]");
                if (type == IntervallMonitor.TYPE_INTERVAL) {
                    IntervallMonitor m = obj instanceof IntervallMonitor ? (IntervallMonitor) obj : new IntervallMonitorWrap(obj);
                    m.init(configServer, name, log);
                    intervalls.add(m);
                } else if (type == Monitor.TYPE_ACTION) {
                    ActionMonitor am = obj instanceof ActionMonitor ? (ActionMonitor) obj : new ActionMonitorWrap(obj);
                    actions.add(new MonitorTemp(am, name, log));
                } else {
                    RequestMonitorPro m = new RequestMonitorProImpl(obj instanceof RequestMonitor ? (RequestMonitor) obj : new RequestMonitorWrap(obj));
                    if (async)
                        m = new AsyncRequestMonitor(m);
                    m.init(configServer, name, log);
                    SystemOut.printDate(config.getOutWriter(), "initialize " + (strType) + " monitor [" + clazz.getName() + "]");
                    requests.add(m);
                }
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
                SystemOut.printDate(config.getErrWriter(), ExceptionUtil.getStacktrace(t, true));
            }
        }
    }
    configServer.setRequestMonitors(requests.toArray(new RequestMonitor[requests.size()]));
    configServer.setIntervallMonitors(intervalls.toArray(new IntervallMonitor[intervalls.size()]));
    ActionMonitorCollector actionMonitorCollector = ActionMonitorFatory.getActionMonitorCollector(configServer, actions.toArray(new MonitorTemp[actions.size()]));
    configServer.setActionMonitorCollector(actionMonitorCollector);
    ((CFMLEngineImpl) configServer.getCFMLEngine()).touchMonitor(configServer);
}
Also used : RequestMonitorPro(lucee.runtime.monitor.RequestMonitorPro) IntervallMonitor(lucee.runtime.monitor.IntervallMonitor) RequestMonitorWrap(lucee.runtime.monitor.RequestMonitorWrap) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ConstructorInstance(lucee.runtime.reflection.pairs.ConstructorInstance) ClassDefinition(lucee.runtime.db.ClassDefinition) RequestMonitorProImpl(lucee.runtime.monitor.RequestMonitorProImpl) ActionMonitor(lucee.runtime.monitor.ActionMonitor) ActionMonitorWrap(lucee.runtime.monitor.ActionMonitorWrap) lucee.aprint(lucee.aprint) CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) AsyncRequestMonitor(lucee.runtime.monitor.AsyncRequestMonitor) ActionMonitorCollector(lucee.runtime.monitor.ActionMonitorCollector) CFXTagClass(lucee.runtime.cfx.customtag.CFXTagClass) CPPCFXTagClass(lucee.runtime.cfx.customtag.CPPCFXTagClass) JavaCFXTagClass(lucee.runtime.cfx.customtag.JavaCFXTagClass) IntervallMonitorWrap(lucee.runtime.monitor.IntervallMonitorWrap) RequestMonitor(lucee.runtime.monitor.RequestMonitor) AsyncRequestMonitor(lucee.runtime.monitor.AsyncRequestMonitor)

Example 4 with CFMLEngineImpl

use of lucee.runtime.engine.CFMLEngineImpl in project Lucee by lucee.

the class RamCache method init.

@Override
public void init(Config config, String cacheName, Struct arguments) throws IOException {
    // RamCache is also used without calling init, because of that we have this test in constructor and here
    if (controller == null) {
        CFMLEngine engine = ConfigWebUtil.getEngine(config);
        if (engine instanceof CFMLEngineImpl) {
            controller = new Controler((CFMLEngineImpl) engine, this);
            controller.start();
        }
    }
    if (controller == null)
        throw new IOException("was not able to start controller");
    // until
    long until = Caster.toLongValue(arguments.get("timeToLiveSeconds", Constants.LONG_ZERO), Constants.LONG_ZERO) * 1000;
    long idleTime = Caster.toLongValue(arguments.get("timeToIdleSeconds", Constants.LONG_ZERO), Constants.LONG_ZERO) * 1000;
    Object ci = arguments.get("controlIntervall", null);
    if (ci == null)
        ci = arguments.get("controlInterval", null);
    int intervalInSeconds = Caster.toIntValue(ci, DEFAULT_CONTROL_INTERVAL);
    init(until, idleTime, intervalInSeconds);
}
Also used : CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) CFMLEngine(lucee.loader.engine.CFMLEngine) IOException(java.io.IOException)

Example 5 with CFMLEngineImpl

use of lucee.runtime.engine.CFMLEngineImpl in project Lucee by lucee.

the class Admin method doGetInfo.

private void doGetInfo() throws PageException {
    Struct sct = new StructImpl();
    pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
    if (config instanceof ConfigWebImpl) {
        ConfigWebImpl cw = (ConfigWebImpl) config;
        sct.setEL(KeyConstants._id, cw.getIdentification().getId());
        sct.setEL(KeyConstants._label, cw.getLabel());
        sct.setEL(KeyConstants._hash, cw.getHash());
        sct.setEL(KeyConstants._root, cw.getRootDirectory().getAbsolutePath());
        sct.setEL("configServerDir", cw.getConfigServerDir().getAbsolutePath());
        sct.setEL("configWebDir", cw.getConfigDir().getAbsolutePath());
    } else {
        sct.setEL("configServerDir", config.getConfigDir().getAbsolutePath());
        sct.setEL("configWebDir", pageContext.getConfig().getConfigDir().getAbsolutePath());
    }
    sct.setEL(KeyConstants._config, config.getConfigFile().getAbsolutePath());
    // Servlets
    if (config instanceof ConfigServer) {
        ConfigServer cs = (ConfigServer) config;
        CFMLEngineImpl engine = (CFMLEngineImpl) cs.getCFMLEngine();
        Struct srv = new StructImpl(), params;
        ServletConfig[] configs = engine.getServletConfigs();
        ServletConfig sc;
        Enumeration e;
        String name, value;
        for (int i = 0; i < configs.length; i++) {
            sc = configs[i];
            e = sc.getInitParameterNames();
            params = new StructImpl();
            while (e.hasMoreElements()) {
                name = (String) e.nextElement();
                value = sc.getInitParameter(name);
                params.set(name, value);
            }
            srv.set(sc.getServletName(), params);
        }
        sct.set("servlets", srv);
    }
    // sct.setEL("javaAgentSupported", Caster.toBoolean(InstrumentationUtil.isSupported()));
    sct.setEL("javaAgentSupported", Boolean.TRUE);
// sct.setEL("javaAgentPath", ClassUtil.getSourcePathForClass("lucee.runtime.instrumentation.Agent", ""));
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) StructImpl(lucee.runtime.type.StructImpl) Enumeration(java.util.Enumeration) ServletConfig(javax.servlet.ServletConfig) ConfigServer(lucee.runtime.config.ConfigServer) Struct(lucee.runtime.type.Struct)

Aggregations

CFMLEngineImpl (lucee.runtime.engine.CFMLEngineImpl)8 Resource (lucee.commons.io.res.Resource)4 lucee.aprint (lucee.aprint)3 Document (org.w3c.dom.Document)3 FileResource (lucee.commons.io.res.type.file.FileResource)2 ConfigServer (lucee.runtime.config.ConfigServer)2 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)2 Struct (lucee.runtime.type.Struct)2 StructImpl (lucee.runtime.type.StructImpl)2 Element (org.w3c.dom.Element)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 ServletConfig (javax.servlet.ServletConfig)1 CFMLEngine (lucee.loader.engine.CFMLEngine)1 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)1 Mapping (lucee.runtime.Mapping)1 PageContextImpl (lucee.runtime.PageContextImpl)1 CFXTagClass (lucee.runtime.cfx.customtag.CFXTagClass)1