Skip to content

Commit

Permalink
add gateway functions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Sep 4, 2024
1 parent da5f8a7 commit 41f14bd
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package lucee.runtime.functions.gateway;

import lucee.runtime.PageContext;
import lucee.runtime.config.ConfigWebPro;
import lucee.runtime.exp.FunctionException;
import lucee.runtime.exp.PageException;
import lucee.runtime.ext.function.Function;
import lucee.runtime.gateway.GatewayEngineImpl;

public final class GatewayAction implements Function {

private static final long serialVersionUID = -4801573283953497373L;

public static String call(PageContext pc, String gatewayID, String action) throws PageException {
GatewayEngineImpl g = ((GatewayEngineImpl) ((ConfigWebPro) pc.getConfig()).getGatewayEngine());

action = action.trim().toLowerCase();

if ("start".equals(action)) g.start(gatewayID);
else if ("stop".equals(action)) g.stop(gatewayID);
else if ("restart".equals(action)) g.restart(gatewayID);
else new FunctionException(pc, "GatewayAction", 2, "action", "invalid action [" + action + "], valid values are [start,stop,restart]");
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package lucee.runtime.functions.gateway;

import lucee.runtime.PageContext;
import lucee.runtime.config.ConfigWebPro;
import lucee.runtime.exp.PageException;
import lucee.runtime.ext.function.Function;
import lucee.runtime.gateway.GatewayEngineImpl;
import lucee.runtime.gateway.GatewayUtil;

public final class GatewayState implements Function {

public static String call(PageContext pc, String gatewayID) throws PageException {
GatewayEngineImpl g = ((GatewayEngineImpl) ((ConfigWebPro) pc.getConfig()).getGatewayEngine());
return GatewayUtil.toState(g.getState(gatewayID), "UNDEFINED");
}
}
9 changes: 9 additions & 0 deletions core/src/main/java/lucee/runtime/gateway/GatewayUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,13 @@ public static int getState(GatewayEntry ge) { // this method only exists to make
return ge.getGateway().getState();
}

public static String toState(int state, String defaultValue) {
if (Gateway.FAILED == state) return "failed";
if (Gateway.RUNNING == state) return "running";
if (Gateway.STARTING == state) return "starting";
if (Gateway.STOPPED == state) return "stopped";
if (Gateway.STOPPING == state) return "stopping";
return defaultValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1829,8 +1829,8 @@ public JavaSettings getJavaSettings() {
getRPCClassLoader();
}
catch (IOException e) {
return ((ConfigPro) config).getJavaSettings();
}
if (javaSettings == null) return ((ConfigPro) config).getJavaSettings();
return javaSettings;
}

Expand Down
36 changes: 36 additions & 0 deletions core/src/main/java/resource/fld/core-base.fld
Original file line number Diff line number Diff line change
Expand Up @@ -12404,6 +12404,42 @@ You can find a list of all available timezones in the Lucee administrator (Setti
<type>string</type>
</return>
</function>
<!-- GatewayState -->
<function>
<name>GatewayState</name>
<class>lucee.runtime.functions.gateway.GatewayState</class>
<description>Return the current state for the given gateway id.</description>
<argument>
<name>gatewayID</name>
<type>string</type>
<required>Yes</required>
<description>Identifier of the gateway to get info for.</description>
</argument>
<return>
<type>string</type>
</return>
</function>
<!-- GatewayAction -->
<function>
<name>GatewayAction</name>
<class>lucee.runtime.functions.gateway.GatewayAction</class>
<description>Executes a specifc action for a gateway instance.</description>
<argument>
<name>gatewayID</name>
<type>string</type>
<required>Yes</required>
<description>Identifier of the gateway to do the action on.</description>
</argument>
<argument>
<name>action</name>
<type>string</type>
<required>Yes</required>
<description>action to execute, possible values are [start,stop and restart]</description>
</argument>
<return>
<type>string</type>
</return>
</function>

<!-- serialize -->
<function>
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.75-SNAPSHOT"/>
<property name="version" value="6.2.0.76-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.75-SNAPSHOT</version>
<version>6.2.0.76-SNAPSHOT</version>
<packaging>jar</packaging>

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

0 comments on commit 41f14bd

Please sign in to comment.