Skip to content

Commit

Permalink
fix: server plugin installation priority
Browse files Browse the repository at this point in the history
Fixed issue #1684
  • Loading branch information
lvca committed Aug 8, 2024
1 parent 9e60b96 commit 961a9c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 12 additions & 3 deletions server/src/main/java/com/arcadedb/server/ArcadeDBServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,25 @@ public synchronized void start() {

// START HTTP SERVER IMMEDIATELY. THE HTTP ADDRESS WILL BE USED BY HA
httpServer = new HttpServer(this);

registerPlugins(ServerPlugin.INSTALLATION_PRIORITY.BEFORE_HTTP_ON);

httpServer.startService();

if (configuration.getValueAsBoolean(GlobalConfiguration.HA_ENABLED)) {
haServer = new HAServer(this, configuration);
haServer.startService();
}

loadDefaultDatabases();
registerPlugins(ServerPlugin.INSTALLATION_PRIORITY.AFTER_HTTP_ON);

registerPlugins();
loadDefaultDatabases();

// RELOAD DATABASE IF A PLUGIN REGISTERED A NEW DATABASE (LIKE THE GREMLIN SERVER)
loadDatabases();

registerPlugins(ServerPlugin.INSTALLATION_PRIORITY.AFTER_DATABASES_OPEN);

status = STATUS.ONLINE;

LogManager.instance().log(this, Level.INFO, "Available query languages: %s", new QueryEngineManager().getAvailableLanguages());
Expand Down Expand Up @@ -220,7 +225,7 @@ private Set<String> getPluginNames() {
return result;
}

private void registerPlugins() {
private void registerPlugins(final ServerPlugin.INSTALLATION_PRIORITY installationPriority) {
final String registeredPlugins = configuration.getValueAsString(GlobalConfiguration.SERVER_PLUGINS);
if (registeredPlugins != null && !registeredPlugins.isEmpty()) {
final String[] pluginEntries = registeredPlugins.split(",");
Expand All @@ -233,6 +238,10 @@ private void registerPlugins() {

final Class<ServerPlugin> c = (Class<ServerPlugin>) Class.forName(pluginClass);
final ServerPlugin pluginInstance = c.getConstructor().newInstance();

if (pluginInstance.getInstallationPriority() != installationPriority)
continue;

pluginInstance.configure(this, configuration);

pluginInstance.startService();
Expand Down
8 changes: 8 additions & 0 deletions server/src/main/java/com/arcadedb/server/ServerPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import com.arcadedb.server.http.HttpServer;
import io.undertow.server.handlers.PathHandler;

import static com.arcadedb.server.ServerPlugin.INSTALLATION_PRIORITY.BEFORE_HTTP_ON;

public interface ServerPlugin {
enum INSTALLATION_PRIORITY {BEFORE_HTTP_ON, AFTER_HTTP_ON, AFTER_DATABASES_OPEN}

default void configure(ArcadeDBServer arcadeDBServer, ContextConfiguration configuration) {
// DEFAULT IMPLEMENTATION
}
Expand All @@ -36,4 +40,8 @@ default void stopService() {
default void registerAPI(final HttpServer httpServer, final PathHandler routes) {
// DEFAULT IMPLEMENTATION
}

default INSTALLATION_PRIORITY getInstallationPriority() {
return BEFORE_HTTP_ON;
}
}

0 comments on commit 961a9c6

Please sign in to comment.