Skip to content

Commit b99a23b

Browse files
committed
fixes #155 replace RuleLoaderStartupHook with MultiThreadRuleExecutor
1 parent 2cd30dc commit b99a23b

5 files changed

Lines changed: 282 additions & 247 deletions

File tree

pom.xml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@
4646
</snapshotRepository>
4747
</distributionManagement>
4848

49-
<repositories>
49+
<repositories>
5050
<repository>
51-
<id>confluent</id>
52-
<url>https://packages.confluent.io/maven/</url>
53-
</repository>
54-
<repository>
55-
<id>jitpack.io</id>
56-
<url>https://jitpack.io</url>
51+
<id>snapshot</id>
52+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
53+
<releases>
54+
<enabled>false</enabled>
55+
</releases>
56+
<snapshots>
57+
<enabled>true</enabled>
58+
</snapshots>
5759
</repository>
5860
<repository>
5961
<id>central</id>
@@ -62,13 +64,6 @@
6264
<enabled>true</enabled>
6365
</releases>
6466
</repository>
65-
<repository>
66-
<id>snapshot</id>
67-
<url>https://central.sonatype.org/content/repositories/snapshots</url>
68-
<snapshots>
69-
<enabled>true</enabled>
70-
</snapshots>
71-
</repository>
7267
</repositories>
7368
<pluginRepositories>
7469
<pluginRepository>
@@ -300,7 +295,12 @@
300295
</dependency>
301296
<dependency>
302297
<groupId>com.networknt</groupId>
303-
<artifactId>ruleloader-config</artifactId>
298+
<artifactId>rule-config</artifactId>
299+
<version>${version.light-4j}</version>
300+
</dependency>
301+
<dependency>
302+
<groupId>com.networknt</groupId>
303+
<artifactId>rule-loader</artifactId>
304304
<version>${version.light-4j}</version>
305305
</dependency>
306306
<dependency>

src/main/java/com/networknt/aws/lambda/handler/middleware/transformer/AbstractTransformerMiddleware.java

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.networknt.aws.lambda.handler.MiddlewareHandler;
44
import com.networknt.config.Config;
55
import com.networknt.rule.*;
6+
import com.networknt.service.SingletonServiceFactory;
67
import org.slf4j.Logger;
78
import org.slf4j.LoggerFactory;
89

@@ -11,58 +12,11 @@
1112

1213
public abstract class AbstractTransformerMiddleware implements MiddlewareHandler {
1314
private static final Logger LOG = LoggerFactory.getLogger(AbstractTransformerMiddleware.class);
14-
static Map<String, Object> endpointRulesMap = new HashMap<>();
15-
public static Map<String, Rule> rules;
16-
public static RuleEngine ruleEngine;
1715

1816
public AbstractTransformerMiddleware() {
19-
20-
// load endpointRules
21-
RuleLoaderConfig ruleLoaderConfig = RuleLoaderConfig.load();
22-
if (ruleLoaderConfig.isEnabled()) {
23-
if (RuleLoaderConfig.RULE_SOURCE_CONFIG_FOLDER.equals(ruleLoaderConfig.getRuleSource())) {
24-
// load the rules for the service from the externalized config folder. The filename is rules.yml
25-
String ruleString = Config.getInstance().getStringFromFile("rules.yml");
26-
rules = RuleMapper.string2RuleMap(ruleString);
27-
LOG.info("Load YAML rules from config folder with size = {}", rules.size());
28-
// load the endpoint rule mapping from the rule-loader.yml
29-
endpointRulesMap = ruleLoaderConfig.getEndpointRules();
30-
}
31-
if (rules != null) {
32-
// create the rule engine with the rule map.
33-
ruleEngine = new RuleEngine(rules, null);
34-
// iterate all action classes to initialize them to ensure that the jar file are deployed and configuration is registered.
35-
// This is to prevent runtime exception and also ensure that the configuration is part of the server info response.
36-
loadPluginClass();
37-
}
38-
} else {
39-
LOG.error("RuleLoaderConfig is not enabled. Please check the configuration.");
40-
}
4117
LOG.info("AbstractTransformerMiddleware is constructed");
4218
}
4319

44-
public static void loadPluginClass() {
45-
// iterate the rules map to find the action classes.
46-
for (Rule rule : rules.values()) {
47-
for (RuleAction action : rule.getActions()) {
48-
String actionClass = action.getActionClassName();
49-
loadActionClass(actionClass);
50-
}
51-
}
52-
}
53-
54-
public static void loadActionClass(String actionClass) {
55-
LOG.debug("load action class {}", actionClass);
56-
try {
57-
IAction ia = (IAction) Class.forName(actionClass).getDeclaredConstructor().newInstance();
58-
// this happens during the server startup, so the cache must be empty. No need to check.
59-
ruleEngine.actionClassCache.put(actionClass, ia);
60-
} catch (Exception e) {
61-
LOG.error("Exception:", e);
62-
throw new RuntimeException("Could not find rule action class " + actionClass, e);
63-
}
64-
}
65-
6620
public static Map<String, String> convertMapValueToString(Map<String, Object> originalMap) {
6721
Map<String, String> convertedMap = new HashMap<>();
6822
for (Map.Entry<String, Object> entry : originalMap.entrySet()) {

0 commit comments

Comments
 (0)