From 17414c5dcc528a44bc2bac0411fc7fe76460a81e Mon Sep 17 00:00:00 2001 From: Honghua Zhu Date: Tue, 2 Jul 2024 09:11:59 +0800 Subject: [PATCH] =?UTF-8?q?new=20feature:=20=E6=96=B0=E5=A2=9E=20auto=5Fst?= =?UTF-8?q?art=20=E5=8F=82=E6=95=B0=E7=94=A8=E4=BA=8E=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=8F=92=E4=BB=B6=20https://github.com/lealo?= =?UTF-8?q?ne/Lealone/issues/228=20https://github.com/lealone/Lealone/issu?= =?UTF-8?q?es/227?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/lealone/db/PluginObject.java | 5 +++++ .../src/main/java/com/lealone/main/Lealone.java | 10 ++++++++++ .../main/java/com/lealone/sql/admin/CreatePlugin.java | 3 +++ 3 files changed, 18 insertions(+) diff --git a/lealone-db/src/main/java/com/lealone/db/PluginObject.java b/lealone-db/src/main/java/com/lealone/db/PluginObject.java index e1f3de10c..b090a06f2 100644 --- a/lealone-db/src/main/java/com/lealone/db/PluginObject.java +++ b/lealone-db/src/main/java/com/lealone/db/PluginObject.java @@ -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; /** @@ -91,4 +92,8 @@ public void stop() { public String getState() { return state; } + + public boolean isAutoStart() { + return MapUtils.getBoolean(parameters, "auto_start", false); + } } diff --git a/lealone-main/src/main/java/com/lealone/main/Lealone.java b/lealone-main/src/main/java/com/lealone/main/Lealone.java index bfdff3ae4..b04971403 100644 --- a/lealone-main/src/main/java/com/lealone/main/Lealone.java +++ b/lealone-main/src/main/java/com/lealone/main/Lealone.java @@ -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; @@ -299,5 +300,14 @@ private void startProtocolServers() { logger.info(name + " started, host: {}, port: {}", server.getHost(), server.getPort()); } } + startPlugins(); + } + + private void startPlugins() { + List pluginObjects = LealoneDatabase.getInstance().getAllPluginObjects(); + for (PluginObject pluginObject : pluginObjects) { + if (pluginObject.isAutoStart()) + pluginObject.start(); + } } } diff --git a/lealone-sql/src/main/java/com/lealone/sql/admin/CreatePlugin.java b/lealone-sql/src/main/java/com/lealone/sql/admin/CreatePlugin.java index 8348b672d..c7aaa7b31 100644 --- a/lealone-sql/src/main/java/com/lealone/sql/admin/CreatePlugin.java +++ b/lealone-sql/src/main/java/com/lealone/sql/admin/CreatePlugin.java @@ -103,6 +103,9 @@ public int update() { lealoneDB.addDatabaseObject(session, pluginObject, lock); // 将缓存过期掉 lealoneDB.getNextModificationMetaId(); + + if (!lealoneDB.isStarting() && pluginObject.isAutoStart()) + pluginObject.start(); return 0; } }