use of lucee.runtime.engine.CFMLEngineImpl in project Lucee by lucee.
the class XMLConfigWebFactory method newInstance.
/**
* creates a new ServletConfig Impl Object
*
* @param configServer
* @param configDir
* @param servletConfig
* @return new Instance
* @throws SAXException
* @throws ClassNotFoundException
* @throws PageException
* @throws IOException
* @throws TagLibException
* @throws FunctionLibException
* @throws NoSuchAlgorithmException
* @throws BundleException
*/
public static ConfigWebImpl newInstance(CFMLEngine engine, CFMLFactoryImpl factory, ConfigServerImpl configServer, Resource configDir, boolean isConfigDirACustomSetting, ServletConfig servletConfig) throws SAXException, ClassException, PageException, IOException, TagLibException, FunctionLibException, NoSuchAlgorithmException, BundleException {
String hash = SystemUtil.hash(servletConfig.getServletContext());
Map<String, String> labels = configServer.getLabels();
String label = null;
if (labels != null) {
label = labels.get(hash);
}
if (label == null)
label = hash;
// make sure the web context does not point to the same directory as the server context
if (configDir.equals(configServer.getConfigDir()))
throw new ApplicationException("the web context [" + label + "] has defined the same configuration directory [" + configDir + "] as the server context");
ConfigWeb[] webs = configServer.getConfigWebs();
if (!ArrayUtil.isEmpty(webs)) {
for (int i = 0; i < webs.length; i++) {
// not sure this is necessary if(hash.equals(((ConfigWebImpl)webs[i]).getHash())) continue;
if (configDir.equals(webs[i].getConfigDir()))
throw new ApplicationException("the web context [" + label + "] has defined the same configuration directory [" + configDir + "] as the web context [" + webs[i].getLabel() + "]");
}
}
SystemOut.print(SystemUtil.getPrintWriter(SystemUtil.OUT), "===================================================================\n" + "WEB CONTEXT (" + label + ")\n" + "-------------------------------------------------------------------\n" + "- config:" + configDir + (isConfigDirACustomSetting ? " (custom setting)" : "") + "\n" + "- webroot:" + ReqRspUtil.getRootPath(servletConfig.getServletContext()) + "\n" + "- hash:" + hash + "\n" + "- label:" + label + "\n" + "===================================================================\n");
int iDoNew = doNew(engine, configDir, false).updateType;
boolean doNew = iDoNew != NEW_NONE;
Resource configFile = configDir.getRealResource("lucee-web.xml." + TEMPLATE_EXTENSION);
String strPath = servletConfig.getServletContext().getRealPath("/WEB-INF");
Resource path = ResourcesImpl.getFileResourceProvider().getResource(strPath);
// get config file
if (!configFile.exists()) {
createConfigFile("web", configFile);
}
Document doc = null;
Resource bugFile;
int count = 1;
doc = loadDocumentCreateIfFails(configFile, "web");
// htaccess
if (path.exists())
createHtAccess(path.getRealResource(".htaccess"));
if (configDir.exists())
createHtAccess(configDir.getRealResource(".htaccess"));
createContextFiles(configDir, servletConfig, doNew);
ConfigWebImpl configWeb = new ConfigWebImpl(factory, configServer, servletConfig, configDir, configFile);
load(configServer, configWeb, doc, false, doNew);
createContextFilesPost(configDir, configWeb, servletConfig, false, doNew);
// call web.cfc for this context
((CFMLEngineImpl) ConfigWebUtil.getEngine(configWeb)).onStart(configWeb, false);
return configWeb;
}
use of lucee.runtime.engine.CFMLEngineImpl in project Lucee by lucee.
the class XMLConfigWebFactory method reloadInstance.
/**
* reloads the Config Object
*
* @param cs
* @param force
* @throws SAXException
* @throws ClassNotFoundException
* @throws PageException
* @throws IOException
* @throws TagLibException
* @throws FunctionLibException
* @throws BundleException
* @throws NoSuchAlgorithmException
*/
public static void reloadInstance(CFMLEngine engine, ConfigServerImpl cs, ConfigWebImpl cw, boolean force) throws SAXException, ClassException, PageException, IOException, TagLibException, FunctionLibException, BundleException {
Resource configFile = cw.getConfigFile();
Resource configDir = cw.getConfigDir();
int iDoNew = doNew(engine, configDir, false).updateType;
boolean doNew = iDoNew != NEW_NONE;
if (configFile == null)
return;
if (second(cw.getLoadTime()) > second(configFile.lastModified()) && !force)
return;
Document doc = loadDocument(configFile);
createContextFiles(configDir, null, doNew);
cw.reset();
load(cs, cw, doc, true, doNew);
createContextFilesPost(configDir, cw, null, false, doNew);
((CFMLEngineImpl) ConfigWebUtil.getEngine(cw)).onStart(cw, true);
}
use of lucee.runtime.engine.CFMLEngineImpl 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;
}
Aggregations