Skip to content

Commit

Permalink
reset mappings in ConfigWeb
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 23, 2024
1 parent b3f0e73 commit ab602c3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 77 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 @@ -576,7 +576,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();
Admin.getConfigServerImpl(config).resetMappings();
ConfigUtil.getConfigWebImpl(config).resetMappings();
if (reload) admin._reload();
}

Expand Down Expand Up @@ -4735,7 +4735,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.getConfigServerImpl(config).resetMappings();
ConfigUtil.getConfigWebImpl(config).resetMappings();
reloadNecessary = true;
}

Expand Down Expand Up @@ -5023,7 +5023,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.getConfigServerImpl(config).resetMappings();
ConfigUtil.getConfigWebImpl(config).resetMappings();
reloadNecessary = true;

logger.debug("extension", "Update Mapping [" + virtual + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static ConfigWebPro newInstanceWeb(CFMLEngine engine, CFMLFactoryImpl fac

Resource configDir = configServer.getConfigDir();
double start = SystemUtil.millis();
ConfigWebPro configWeb = existingToUpdate != null ? existingToUpdate.setInstance(factory, configServer, servletConfig)
ConfigWebPro configWeb = existingToUpdate != null ? existingToUpdate.setInstance(factory, configServer, servletConfig, true)
: new ConfigWebImpl(factory, configServer, servletConfig);
factory.setConfig(configServer, configWeb);

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

public static ConfigWebImpl getConfigWebImpl(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());
}
}
110 changes: 40 additions & 70 deletions core/src/main/java/lucee/runtime/config/ConfigWebImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,17 @@ public class ConfigWebImpl extends ConfigBase implements ConfigWebPro {
private lucee.runtime.rest.Mapping[] restMappings;

public ConfigWebImpl(CFMLFactoryImpl factory, ConfigServerImpl cs, ServletConfig config) {
setInstance(factory, cs, config);
setInstance(factory, cs, config, false);
}

public ConfigWebPro setInstance(CFMLFactoryImpl factory, ConfigServerImpl cs, ServletConfig config) {
public ConfigWebPro setInstance(CFMLFactoryImpl factory, ConfigServerImpl cs, ServletConfig config, boolean reload) {
this.id = null;
this.factory = factory;
this.cs = cs;
this.config = config;
helper = new ConfigWebHelper(cs, this);

reload();
if (reload) reload();
return this;
}

Expand Down Expand Up @@ -376,16 +376,6 @@ public boolean passwordEqual(Password password) {
return cs.passwordEqual(password);
}

@Override
public Mapping[] getMappings() {
if (mappings == null) {
synchronized (this) {
if (mappings == null) createMapping();
}
}
return mappings;// cs.getMappings();
}

@Override
public lucee.runtime.rest.Mapping[] getRestMappings() {
if (restMappings == null) {
Expand Down Expand Up @@ -1810,65 +1800,56 @@ public void reload() {
synchronized (this) {
if (mappings != null) {
ConfigFactoryImpl.flushPageSourcePool(mappings);
// resetMappings(false);// MUST 7 iss that needed?
}

createMapping();
createRestMapping();
}
}

private void createMapping() {
Map<String, Mapping> existing = 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);
@Override
public Mapping[] getMappings() {
if (mappings == null) {
synchronized (SystemUtil.createToken("ConfigWebImpl", "getMappings")) {
if (mappings == null) {
Mapping[] existing = cs.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;
mappings.put(m.getVirtualLowerCase(), m);
}

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);
}
mappings.put("/", m);
}

this.mappings = ConfigUtil.sort(mappings.values().toArray(new Mapping[mappings.size()]));
}
}
}
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;
return mappings;
}

public ConfigWebImpl resetMappings() {
if (mappings != null) {
synchronized (SystemUtil.createToken("ConfigWebImpl", "getMappings")) {
if (mappings != null) {
mappings = null;
cs.resetMappings();
}
}
mappings.put("/", m);
}
this.mappings = ConfigUtil.sort(mappings.values().toArray(new Mapping[mappings.size()]));
return this;
}

private void createRestMapping() {
Expand All @@ -1891,17 +1872,6 @@ private void createRestMapping() {
this.restMappings = mappings.values().toArray(new lucee.runtime.rest.Mapping[mappings.size()]);
}

private Map<String, Mapping> getExistingMappings() {
Map<String, Mapping> mappings = MapFactory.<String, Mapping>getConcurrentMap();

if (this.mappings != null) {
for (Mapping m: this.mappings) {
mappings.put(m.getVirtualLowerCase(), m);
}
}
return mappings;
}

@Override
public void removeDatasourceConnectionPool(DataSource ds) {
cs.removeDatasourceConnectionPool(ds);
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 @@ -1023,7 +1023,7 @@ else if (mappingType == MAPPING_CT) {
mapping.getInspectTemplateRaw(), mapping.getInspectTemplateAutoIntervalRaw(true), mapping.getInspectTemplateAutoIntervalRaw(false), mapping.isTopLevel(),
mapping.getListenerMode(), mapping.getListenerType(), mapping.isReadonly());
store();
Admin.getConfigServerImpl(config).resetMappings();
ConfigUtil.getConfigWebImpl(configWeb).resetMappings();
}

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

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

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

Expand Down

0 comments on commit ab602c3

Please sign in to comment.