Skip to content

Commit

Permalink
fix RHExtension issue
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 25, 2024
1 parent de05b7d commit 62d1382
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 71 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/lucee/runtime/config/ConfigAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ protected static void updateMapping(ConfigPro config, String virtual, String phy
admin._updateMapping(virtual, physical, archive, primary, inspect, inspectTemplateIntervalSlow, inspectTemplateIntervalFast, toplevel, listenerMode, listenerType,
readonly);
admin._store();
ConfigUtil.getConfigWebImpl(config).resetMappings();
ConfigUtil.getConfigWebIfPossible(config).resetMappings();
if (reload) admin._reload();
}

Expand Down Expand Up @@ -4734,7 +4734,7 @@ public void updateRHExtension(Config config, RHExtension rhext, boolean reload,
String sub = subFolder(entry);
logger.log(Log.LEVEL_DEBUG, "extension", "deploy mapping " + sub);
updateArchive(zis, sub, false);
ConfigUtil.getConfigWebImpl(config).resetMappings();
ConfigUtil.getConfigWebIfPossible(config).resetMappings();
reloadNecessary = true;
}

Expand Down Expand Up @@ -5022,7 +5022,7 @@ else if (!StringUtil.isEmpty(cfc, true)) {
toplevel = Caster.toBooleanValue(map.get("toplevel"), false);
readonly = Caster.toBooleanValue(map.get("readonly"), false);
_updateMapping(virtual, physical, archive, primary, inspect, inspectTemplateIntervalSlow, inspectTemplateIntervalFast, toplevel, lmode, ltype, readonly);
ConfigUtil.getConfigWebImpl(config).resetMappings();
ConfigUtil.getConfigWebIfPossible(config).resetMappings();
reloadNecessary = true;

logger.debug("extension", "Update Mapping [" + virtual + "]");
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/lucee/runtime/config/ConfigPro.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,6 @@ public Resource[] getResources(PageContext pc, Mapping[] mappings, String realPa
public CFMLEngine getEngine();

public boolean getDateCasterClassicStyle();

public ConfigPro resetMappings();
}
13 changes: 9 additions & 4 deletions core/src/main/java/lucee/runtime/config/ConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1458,12 +1458,17 @@ public static ConfigServerImpl getConfigServerImpl(Config config) {
throw new RuntimeException("getConfigServerImpl: " + config.getClass().getName());
}

public static ConfigWebImpl getConfigWebImpl(Config config) {
/**
* returns ConfigWeb if available, otherwise ConfigServer
*
* @param config
* @return
*/
public static ConfigPro getConfigWebIfPossible(Config config) {
if (config instanceof ConfigWebImpl) return ((ConfigWebImpl) config);
Config c = ThreadLocalPageContext.getConfig();
LogUtil.log(Log.LEVEL_ERROR, "config", "canno convert the following instance to a ConfigWebImpl: " + config.getClass().getName());
if (c instanceof ConfigWebImpl) return ((ConfigWebImpl) c);
// MUST remove
throw new RuntimeException("getConfigWebImpl: " + config.getClass().getName());

return getConfigServerImpl(config);
}
}
61 changes: 2 additions & 59 deletions core/src/main/java/lucee/runtime/config/ConfigWebImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.osgi.framework.Version;

import lucee.print;
import lucee.commons.collection.MapFactory;
import lucee.commons.io.SystemUtil;
import lucee.commons.io.cache.Cache;
Expand Down Expand Up @@ -1805,17 +1804,14 @@ public Mapping[] getMappings() {
// Mapping
Map<String, Mapping> mappings = MapFactory.<String, Mapping>getConcurrentMap(existing.length + 1);
boolean finished = false;

for (Mapping m: existing) {
if ("/".equals(m.getVirtual())) finished = true;

print.e(m.getVirtual() + ":" + m);
MappingImpl tmp = ((MappingImpl) m).cloneReadOnly(this);

mappings.put(tmp.getVirtualLowerCase(), tmp);
}

if (!finished) {

Mapping m;
if (ResourceUtil.isUNCPath(getRootDirectory().getPath())) {
m = new MappingImpl(this, "/", getRootDirectory().getPath(), null, ConfigPro.INSPECT_UNDEFINED, ConfigPro.INSPECT_INTERVAL_UNDEFINED,
Expand All @@ -1834,60 +1830,7 @@ public Mapping[] getMappings() {
return mappings;
}

private void createMapping() {
Map<String, Mapping> existing = null;// getExistingMappings();

// Mapping
Map<String, Mapping> mappings = MapFactory.<String, Mapping>getConcurrentMap();
Mapping tmp;
boolean finished = false;
Mapping ex;
Mapping[] sm = cs.getMappings();
if (sm != null) {
for (int i = 0; i < sm.length; i++) {
if (!sm[i].isHidden()) {
if ("/".equals(sm[i].getVirtual())) finished = true;
ex = existing.get(sm[i].getVirtualLowerCase());
if (ex != null && ex.equals(sm[i])) {
mappings.put(ex.getVirtualLowerCase(), ex);
continue;
}
else if (sm[i] instanceof MappingImpl) {
tmp = ((MappingImpl) sm[i]).cloneReadOnly(this);
mappings.put(tmp.getVirtualLowerCase(), tmp);

}
else {
tmp = sm[i];
mappings.put(tmp.getVirtualLowerCase(), tmp);
}

if (ex instanceof MappingImpl) {
((MappingImpl) ex).flush();
}

}
}
}
if (!finished) {
Mapping m;
if (ResourceUtil.isUNCPath(getRootDirectory().getPath())) {
m = new MappingImpl(this, "/", getRootDirectory().getPath(), null, ConfigPro.INSPECT_UNDEFINED, ConfigPro.INSPECT_INTERVAL_UNDEFINED,
ConfigPro.INSPECT_INTERVAL_UNDEFINED, true, true, true, true, false, false, null, -1, -1);
}
else {
m = new MappingImpl(this, "/", "/", null, ConfigPro.INSPECT_UNDEFINED, ConfigPro.INSPECT_INTERVAL_UNDEFINED, ConfigPro.INSPECT_INTERVAL_UNDEFINED, true, true, true,
true, false, false, null, -1, -1, true, true);
}
ex = existing.get("/");
if (ex != null && ex.equals(m)) {
m = ex;
}
mappings.put("/", m);
}
this.mappings = ConfigUtil.sort(mappings.values().toArray(new Mapping[mappings.size()]));
}

@Override
public ConfigWebImpl resetMappings() {
if (mappings != null) {
synchronized (SystemUtil.createToken("ConfigWebImpl", "getMappings")) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/lucee/runtime/tag/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ else if (mappingType == MAPPING_CT) {
mapping.getInspectTemplateRaw(), mapping.getInspectTemplateAutoIntervalRaw(true), mapping.getInspectTemplateAutoIntervalRaw(false), mapping.isTopLevel(),
mapping.getListenerMode(), mapping.getListenerType(), mapping.isReadonly());
store();
ConfigUtil.getConfigWebImpl(configWeb).resetMappings();
ConfigUtil.getConfigWebIfPossible(config).resetMappings();
}

}
Expand Down Expand Up @@ -2059,7 +2059,7 @@ private void doGetComponentMappings() throws PageException {
private void doRemoveMapping() throws PageException {
admin.removeMapping(getString("admin", action, "virtual"));
store();
ConfigUtil.getConfigWebImpl(configWeb).resetMappings();
ConfigUtil.getConfigWebIfPossible(config).resetMappings();
adminSync.broadcast(attributes, config);
}

Expand Down Expand Up @@ -2093,7 +2093,7 @@ private void doUpdateMapping() throws PageException {

);
store();
ConfigUtil.getConfigWebImpl(configWeb).resetMappings();
ConfigUtil.getConfigWebIfPossible(config).resetMappings();
adminSync.broadcast(attributes, config);
}

Expand Down
6 changes: 4 additions & 2 deletions loader/src/main/java/lucee/loader/osgi/BundleLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private static Map<String, File> loadAvailableBundles(final File jarDirectory) {
final Map<String, File> rtn = new ConcurrentHashMap<>();
final File[] jars = jarDirectory.listFiles();

if (jars != null) {
if (jars != null && jars.length > 0) {
// Create a thread pool with a fixed number of threads
// ExecutorService executor = Executors.newFixedThreadPool(Math.min(jars.length,
// Runtime.getRuntime().availableProcessors()));
Expand Down Expand Up @@ -226,7 +226,9 @@ private static Map<String, File> loadAvailableBundlesSerial(final File jarDirect
}

public static ExecutorService createExecutorService(int maxThreads) {

if (maxThreads <= 0) {
throw new IllegalArgumentException("Invalid value for maxThreads: " + maxThreads + ". The value must be greater than 0.");
}
if (parseJavaVersion(System.getProperty("java.version")) >= 19) {
// FUTURE use newVirtualThreadPerTaskExecutor natively
try {
Expand Down

0 comments on commit 62d1382

Please sign in to comment.