Skip to content

Commit

Permalink
add initial version for startup hook for components
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Jul 18, 2024
1 parent 248f577 commit 6c973cb
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
62 changes: 61 additions & 1 deletion core/src/main/java/lucee/runtime/config/ConfigAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,24 @@ private void _removeStartupHook(ClassDefinition cd) throws PageException {
}
}

private void _removeStartupHook(String component) {

Array children = ConfigWebUtil.getAsArray("startupHooks", root);
Key[] keys = children.keys();
// Remove
for (int i = keys.length - 1; i >= 0; i--) {
Key key = keys[i];
Struct tmp = Caster.toStruct(children.get(key, null), null);
if (tmp == null) continue;

String n = Caster.toString(tmp.get(KeyConstants._component, null), null);
if (n != null && n.equalsIgnoreCase(component)) {
children.removeEL(key);
break;
}
}
}

private void unloadStartupIfNecessary(ConfigPro config, ClassDefinition<?> cd, boolean force) {
ConfigBase.Startup startup = config.getStartups().get(cd.getClassName());
if (startup == null) return;
Expand Down Expand Up @@ -1736,6 +1754,34 @@ private void _updateStartupHook(ClassDefinition cd) throws PageException {
}
}

private void _updateStartupHook(String component) {
// unloadStartupIfNecessary(config, cd, false);

Array children = ConfigWebUtil.getAsArray("startupHooks", root);

// Update
Struct child = null;
for (int i = 1; i <= children.size(); i++) {
Struct tmp = Caster.toStruct(children.get(i, null), null);
if (tmp == null) continue;

String n = ConfigWebUtil.getAsString("component", tmp, null);
if (n.equalsIgnoreCase(component)) {
child = tmp;
break;
}
}

// Insert
if (child == null) {
child = new StructImpl(Struct.TYPE_LINKED);
children.appendEL(child);
}

// make sure the class exists
child.setEL(KeyConstants._component, component);
}

public void updateGatewayEntry(String id, ClassDefinition cd, String componentPath, String listenerCfcPath, int startupMode, Struct custom, boolean readOnly)
throws PageException {
checkWriteAccess();
Expand Down Expand Up @@ -4915,11 +4961,20 @@ public void updateRHExtension(Config config, RHExtension rhext, boolean reload,
while (itl.hasNext()) {
map = itl.next();
ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
String cfc = map.get("component");

// class
if (cd != null && cd.isBundle()) {
_updateStartupHook(cd);
reloadNecessary = true;
logger.info("extension", "Update Startup Hook [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
}
// component
else if (!StringUtil.isEmpty(cfc, true)) {
_updateStartupHook(cfc);
reloadNecessary = true;
logger.info("extension", "Update Startup Hook [" + cfc + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
}
logger.info("extension", "Update Startup Hook [" + cd + "] from extension [" + rhext.getName() + ":" + rhext.getVersion() + "]");
}
}

Expand Down Expand Up @@ -5239,9 +5294,14 @@ private void removeRHExtension(Config config, RHExtension rhe, RHExtension repla
while (itl.hasNext()) {
map = itl.next();
ClassDefinition cd = RHExtension.toClassDefinition(config, map, null);
String cfc = map.get("component");

if (cd != null && cd.isBundle()) {
_removeStartupHook(cd);
}
else if (!StringUtil.isEmpty(cfc, true)) {
_removeStartupHook(cfc);
}
logger.info("extension", "Remove Startup Hook [" + cd + "] from extension [" + rhe.getName() + ":" + rhe.getVersion() + "]");
}
}
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/java/lucee/runtime/config/ConfigWebFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4331,7 +4331,14 @@ private static void _loadStartupHook(ConfigServerImpl configServer, ConfigImpl c
try {
child = Caster.toStruct(it.next());
if (child == null) continue;
// component
String cfc = Caster.toString(child.get(KeyConstants._component), null);
if (!StringUtil.isEmpty(cfc, true)) {
// TODO start hook
continue;
}

// class
ClassDefinition cd = getClassDefinition(child, "", config.getIdentification());
ConfigBase.Startup existing = config.getStartups().get(cd.getClassName());

Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.2.0.23-SNAPSHOT"/>
<property name="version" value="6.2.0.24-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.2.0.23-SNAPSHOT</version>
<version>6.2.0.24-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 6c973cb

Please sign in to comment.