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);
}
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;
}
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);
}
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);
}
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", ""));
}
Aggregations