You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2023/03/18 21:16:56 UTC
[iotdb] 02/03: refactor pipe agent skeleton
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch IOTDB-5692
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit a6c8bdba4ca6efe19b19e0b0705c4439f9e73f01
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Fri Mar 17 12:47:49 2023 +0800
refactor pipe agent skeleton
---
.../org/apache/iotdb/db/pipe/agent/PipeAgent.java | 26 ++++++++++++++++++----
.../iotdb/db/pipe/agent/PipePluginAgent.java | 16 ++++++++-----
.../iotdb/db/pipe/agent/PipeRuntimeAgent.java | 9 +++++---
.../apache/iotdb/db/pipe/agent/PipeTaskAgent.java | 9 +++++---
4 files changed, 44 insertions(+), 16 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipeAgent.java b/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipeAgent.java
index e94807e8e1..7e3b3a1e87 100644
--- a/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipeAgent.java
+++ b/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipeAgent.java
@@ -19,10 +19,28 @@
package org.apache.iotdb.db.pipe.agent;
+import org.apache.iotdb.commons.pipe.plugin.meta.DataNodePipePluginMetaKeeper;
+
+/** PipeAgent is the entry point of the pipe module in DatNode. */
public class PipeAgent {
+ private final PipePluginAgent pipePluginAgent;
+ private final PipeTaskAgent pipeTaskAgent;
+ private final PipeRuntimeAgent pipeRuntimeAgent;
+
/** Private constructor to prevent users from creating a new instance. */
- private PipeAgent() {}
+ private PipeAgent() {
+ final DataNodePipePluginMetaKeeper pipePluginMetaKeeper = new DataNodePipePluginMetaKeeper();
+
+ pipePluginAgent = PipePluginAgent.setupAndGetInstance(pipePluginMetaKeeper);
+ pipeTaskAgent = PipeTaskAgent.setupAndGetInstance();
+ pipeRuntimeAgent = PipeRuntimeAgent.setupAndGetInstance();
+ }
+
+ /** The singleton holder of PipeAgent. */
+ private static class PipeAgentHolder {
+ private static final PipeAgent HANDLE = new PipeAgent();
+ }
/**
* Get the singleton instance of PipeTaskAgent.
@@ -30,7 +48,7 @@ public class PipeAgent {
* @return the singleton instance of PipeTaskAgent
*/
public static PipeTaskAgent task() {
- return PipeTaskAgent.getInstance();
+ return PipeAgentHolder.HANDLE.pipeTaskAgent;
}
/**
@@ -39,7 +57,7 @@ public class PipeAgent {
* @return the singleton instance of PipePluginAgent
*/
public static PipePluginAgent plugin() {
- return PipePluginAgent.getInstance();
+ return PipeAgentHolder.HANDLE.pipePluginAgent;
}
/**
@@ -48,6 +66,6 @@ public class PipeAgent {
* @return the singleton instance of PipeRuntimeAgent
*/
public static PipeRuntimeAgent runtime() {
- return PipeRuntimeAgent.getInstance();
+ return PipeAgentHolder.HANDLE.pipeRuntimeAgent;
}
}
diff --git a/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipePluginAgent.java b/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipePluginAgent.java
index a0a62ca118..57cb0fb1b3 100644
--- a/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipePluginAgent.java
+++ b/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipePluginAgent.java
@@ -41,8 +41,7 @@ public class PipePluginAgent {
private final ReentrantLock lock = new ReentrantLock();
- private final DataNodePipePluginMetaKeeper pipePluginMetaKeeper =
- new DataNodePipePluginMetaKeeper();
+ private final DataNodePipePluginMetaKeeper pipePluginMetaKeeper;
/////////////////////////////// Lock ///////////////////////////////
@@ -181,13 +180,18 @@ public class PipePluginAgent {
///////////////////////// Singleton Instance Holder /////////////////////////
- private PipePluginAgent() {}
+ private PipePluginAgent(DataNodePipePluginMetaKeeper pipePluginMetaKeeper) {
+ this.pipePluginMetaKeeper = pipePluginMetaKeeper;
+ }
private static class PipePluginAgentServiceHolder {
- private static final PipePluginAgent INSTANCE = new PipePluginAgent();
+ private static PipePluginAgent instance = null;
}
- static PipePluginAgent getInstance() {
- return PipePluginAgentServiceHolder.INSTANCE;
+ static PipePluginAgent setupAndGetInstance(DataNodePipePluginMetaKeeper pipePluginMetaKeeper) {
+ if (PipePluginAgentServiceHolder.instance == null) {
+ PipePluginAgentServiceHolder.instance = new PipePluginAgent(pipePluginMetaKeeper);
+ }
+ return PipePluginAgentServiceHolder.instance;
}
}
diff --git a/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipeRuntimeAgent.java b/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipeRuntimeAgent.java
index fe9ab3ee8a..e42b1f66f3 100644
--- a/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipeRuntimeAgent.java
+++ b/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipeRuntimeAgent.java
@@ -26,10 +26,13 @@ public class PipeRuntimeAgent {
private PipeRuntimeAgent() {}
private static class PipeRuntimeAgentHolder {
- private static final PipeRuntimeAgent INSTANCE = new PipeRuntimeAgent();
+ private static PipeRuntimeAgent INSTANCE = null;
}
- static PipeRuntimeAgent getInstance() {
- return PipeRuntimeAgent.PipeRuntimeAgentHolder.INSTANCE;
+ static PipeRuntimeAgent setupAndGetInstance() {
+ if (PipeRuntimeAgentHolder.INSTANCE == null) {
+ PipeRuntimeAgentHolder.INSTANCE = new PipeRuntimeAgent();
+ }
+ return PipeRuntimeAgentHolder.INSTANCE;
}
}
diff --git a/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipeTaskAgent.java b/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipeTaskAgent.java
index 75c8e14636..5034fb50e7 100644
--- a/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipeTaskAgent.java
+++ b/server/src/main/java/org/apache/iotdb/db/pipe/agent/PipeTaskAgent.java
@@ -26,10 +26,13 @@ public class PipeTaskAgent {
private PipeTaskAgent() {}
private static class PipeTaskAgentHolder {
- private static final PipeTaskAgent INSTANCE = new PipeTaskAgent();
+ private static PipeTaskAgent instance = null;
}
- static PipeTaskAgent getInstance() {
- return PipeTaskAgent.PipeTaskAgentHolder.INSTANCE;
+ static PipeTaskAgent setupAndGetInstance() {
+ if (PipeTaskAgentHolder.instance == null) {
+ PipeTaskAgentHolder.instance = new PipeTaskAgent();
+ }
+ return PipeTaskAgentHolder.instance;
}
}