Skip to content

Commit

Permalink
improve OSGi bundle loading (reduce file access)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Oct 23, 2023
1 parent 63b74fe commit a357a91
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -119,7 +120,7 @@ public static ConfigServerImpl newInstance(CFMLEngineImpl engine, Map<String, CF
"has " + (hasConfigOld ? "" : "no ") + "xml server context config [" + configFileOld + "]");
}
ConfigServerImpl config = existing != null ? existing : new ConfigServerImpl(engine, initContextes, contextes, configDir, configFileNew, ui, essentialOnly);

ThreadLocalConfigServer.register(config);
// translate to new
if (!hasConfigNew) {
if (hasConfigOld) {
Expand Down Expand Up @@ -164,6 +165,7 @@ public static ConfigServerImpl newInstance(CFMLEngineImpl engine, Map<String, CF
}
finally {
ThreadLocalPageContext.insideServerNewInstance(false);
ThreadLocalConfigServer.release();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package lucee.runtime.engine;

import lucee.runtime.config.ConfigServer;

/**
* class to handle thread local PageContext, do use pagecontext in classes that have no method
* argument pagecontext
*/
public final class ThreadLocalConfigServer {

private static ThreadLocal<ConfigServer> cThreadLocal = new ThreadLocal<ConfigServer>();

/**
* 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);
}
}
23 changes: 17 additions & 6 deletions core/src/main/java/lucee/runtime/osgi/OSGiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() : "")
Expand Down Expand Up @@ -1097,6 +1104,7 @@ private static BundleFile _getBundleFile(CFMLEngineFactory factory, String name,
}

private static BundleFile _getBundleFile(CFMLEngineFactory factory, BundleRange bundleRange, List<Resource> addional, StringBuilder versionsFound) {

Resource match = null;
try {

Expand Down Expand Up @@ -1212,10 +1220,13 @@ private static List<Resource> createPossibleNameMatches(Resource dir, List<Resou
VersionRange vr = bundleRange.getVersionRange();
if (vr != null) {
VersionDefinition from = vr.getFrom();
if (from != null && from.op == VersionDefinition.EQ || from.op == VersionDefinition.GTE) {
if (from != null && from.version != null && (from.op == VersionDefinition.EQ || from.op == VersionDefinition.GTE)) {
String name = bundleRange.getName();
String[] patterns = new String[] { name + "-" + from.version + ".jar", name.replace('.', '-') + "-" + (from.version.toString().replace('.', '-')) + ".jar",
name.replace('-', '.') + "-" + from.version + ".jar" };
String regular = name + "-" + from.version + ".jar";
String dash = name.replace('.', '-') + "-" + (from.version.toString().replace('.', '-')) + ".jar";
String dot = name.replace('-', '.') + "-" + from.version + ".jar";

String[] patterns = regular.equals(dot) ? new String[] { regular, dash } : new String[] { regular, dot, dash };

for (String pattern: patterns) {
resources.add(dir.getRealResource(pattern));
Expand Down

0 comments on commit a357a91

Please sign in to comment.