Search in sources :

Example 1 with ActionMonitorCollector

use of lucee.runtime.monitor.ActionMonitorCollector 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)

Aggregations

ArrayList (java.util.ArrayList)1 lucee.aprint (lucee.aprint)1 CFXTagClass (lucee.runtime.cfx.customtag.CFXTagClass)1 CPPCFXTagClass (lucee.runtime.cfx.customtag.CPPCFXTagClass)1 JavaCFXTagClass (lucee.runtime.cfx.customtag.JavaCFXTagClass)1 ClassDefinition (lucee.runtime.db.ClassDefinition)1 CFMLEngineImpl (lucee.runtime.engine.CFMLEngineImpl)1 ActionMonitor (lucee.runtime.monitor.ActionMonitor)1 ActionMonitorCollector (lucee.runtime.monitor.ActionMonitorCollector)1 ActionMonitorWrap (lucee.runtime.monitor.ActionMonitorWrap)1 AsyncRequestMonitor (lucee.runtime.monitor.AsyncRequestMonitor)1 IntervallMonitor (lucee.runtime.monitor.IntervallMonitor)1 IntervallMonitorWrap (lucee.runtime.monitor.IntervallMonitorWrap)1 RequestMonitor (lucee.runtime.monitor.RequestMonitor)1 RequestMonitorPro (lucee.runtime.monitor.RequestMonitorPro)1 RequestMonitorProImpl (lucee.runtime.monitor.RequestMonitorProImpl)1 RequestMonitorWrap (lucee.runtime.monitor.RequestMonitorWrap)1 ConstructorInstance (lucee.runtime.reflection.pairs.ConstructorInstance)1 Element (org.w3c.dom.Element)1