Skip to content

Commit

Permalink
new feature: 新增 auto_start 参数用于自动启动插件 #228 #227
Browse files Browse the repository at this point in the history
  • Loading branch information
codefollower committed Jul 2, 2024
1 parent 179f559 commit 17414c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lealone-db/src/main/java/com/lealone/db/PluginObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.net.URLClassLoader;

import com.lealone.common.util.CaseInsensitiveMap;
import com.lealone.common.util.MapUtils;
import com.lealone.common.util.StatementBuilder;

/**
Expand Down Expand Up @@ -91,4 +92,8 @@ public void stop() {
public String getState() {
return state;
}

public boolean isAutoStart() {
return MapUtils.getBoolean(parameters, "auto_start", false);
}
}
10 changes: 10 additions & 0 deletions lealone-main/src/main/java/com/lealone/main/Lealone.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.lealone.db.LealoneDatabase;
import com.lealone.db.PluggableEngine;
import com.lealone.db.PluginManager;
import com.lealone.db.PluginObject;
import com.lealone.db.SysProperties;
import com.lealone.db.scheduler.Scheduler;
import com.lealone.db.scheduler.SchedulerFactory;
Expand Down Expand Up @@ -299,5 +300,14 @@ private void startProtocolServers() {
logger.info(name + " started, host: {}, port: {}", server.getHost(), server.getPort());
}
}
startPlugins();
}

private void startPlugins() {
List<PluginObject> pluginObjects = LealoneDatabase.getInstance().getAllPluginObjects();
for (PluginObject pluginObject : pluginObjects) {
if (pluginObject.isAutoStart())
pluginObject.start();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public int update() {
lealoneDB.addDatabaseObject(session, pluginObject, lock);
// 将缓存过期掉
lealoneDB.getNextModificationMetaId();

if (!lealoneDB.isStarting() && pluginObject.isAutoStart())
pluginObject.start();
return 0;
}
}

0 comments on commit 17414c5

Please sign in to comment.