From a357a911dab460df3e1704f5e729083f28c17075 Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Mon, 23 Oct 2023 22:01:38 +0200 Subject: [PATCH] improve OSGi bundle loading (reduce file access) --- .../runtime/config/ConfigServerFactory.java | 4 +- .../engine/ThreadLocalConfigServer.java | 37 +++++++++++++++++++ .../java/lucee/runtime/osgi/OSGiUtil.java | 23 +++++++++--- 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 core/src/main/java/lucee/runtime/engine/ThreadLocalConfigServer.java diff --git a/core/src/main/java/lucee/runtime/config/ConfigServerFactory.java b/core/src/main/java/lucee/runtime/config/ConfigServerFactory.java index 619897c987..55085a32e1 100644 --- a/core/src/main/java/lucee/runtime/config/ConfigServerFactory.java +++ b/core/src/main/java/lucee/runtime/config/ConfigServerFactory.java @@ -41,6 +41,7 @@ import lucee.runtime.CFMLFactory; import lucee.runtime.converter.ConverterException; import lucee.runtime.engine.CFMLEngineImpl; +import lucee.runtime.engine.ThreadLocalConfigServer; import lucee.runtime.engine.ThreadLocalPageContext; import lucee.runtime.exp.ApplicationException; import lucee.runtime.exp.PageException; @@ -119,7 +120,7 @@ public static ConfigServerImpl newInstance(CFMLEngineImpl engine, Map cThreadLocal = new ThreadLocal(); + + /** + * register a Config for he current thread + * + * @param config Config to register + */ + public static void register(ConfigServer config) {// DO NOT CHANGE, used in Ortus extension via reflection + cThreadLocal.set(config); + } + + /** + * returns Config registered for the current thread + * + * @return Config for the current thread or null + */ + public static ConfigServer get() { + return cThreadLocal.get(); + } + + /** + * release the pagecontext for the current thread + */ + public static void release() {// DO NOT CHANGE, used in Ortus extension via reflection + cThreadLocal.set(null); + } +} \ No newline at end of file diff --git a/core/src/main/java/lucee/runtime/osgi/OSGiUtil.java b/core/src/main/java/lucee/runtime/osgi/OSGiUtil.java index b3aece8bc3..ec397a8665 100644 --- a/core/src/main/java/lucee/runtime/osgi/OSGiUtil.java +++ b/core/src/main/java/lucee/runtime/osgi/OSGiUtil.java @@ -71,10 +71,12 @@ import lucee.loader.osgi.BundleUtil; import lucee.loader.util.Util; import lucee.runtime.config.Config; +import lucee.runtime.config.ConfigServer; import lucee.runtime.config.ConfigWebFactory; import lucee.runtime.config.ConfigWebUtil; import lucee.runtime.config.Identification; import lucee.runtime.engine.CFMLEngineImpl; +import lucee.runtime.engine.ThreadLocalConfigServer; import lucee.runtime.engine.ThreadLocalPageContext; import lucee.runtime.exp.PageException; import lucee.runtime.op.Caster; @@ -858,10 +860,15 @@ private static Resource downloadBundle(CFMLEngineFactory factory, final String s throw re; } } - // print.e("xxxxxxxxxxxxxxxxxxxxxxx"); - // print.e(symbolicName + ":" + symbolicVersion); final Resource jarDir = ResourceUtil.toResource(factory.getBundleDirectory()); - final URL updateProvider = factory.getUpdateLocation(); + final URL updateProvider; + if (ThreadLocalPageContext.insideServerNewInstance()) { + ConfigServer cs = ThreadLocalConfigServer.get(); + updateProvider = cs != null ? cs.getUpdateLocation() : factory.getUpdateLocation(); + } + else { + updateProvider = factory.getUpdateLocation(); + } if (symbolicVersion == null) symbolicVersion = "latest"; final URL updateUrl = new URL(updateProvider, "/rest/update/provider/download/" + symbolicName + "/" + symbolicVersion + "/" + (id != null ? id.toQueryString() : "") @@ -1097,6 +1104,7 @@ private static BundleFile _getBundleFile(CFMLEngineFactory factory, String name, } private static BundleFile _getBundleFile(CFMLEngineFactory factory, BundleRange bundleRange, List addional, StringBuilder versionsFound) { + Resource match = null; try { @@ -1212,10 +1220,13 @@ private static List createPossibleNameMatches(Resource dir, List