From cee1ac4f82ccff878a4f057990a1152e32409a60 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 15 Oct 2018 14:36:56 +0200 Subject: [PATCH] [New] added StrolchAgent.getSingleThreadExecutor() --- .../li/strolch/agent/api/StrolchAgent.java | 24 +++++++++++++++++-- .../strolch/agent/api/StrolchComponent.java | 21 ++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchAgent.java b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchAgent.java index 7704f30c5..1eb76c285 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchAgent.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchAgent.java @@ -104,6 +104,26 @@ public class StrolchAgent { return executor; } + /** + * Return the {@link ExecutorService} instantiated for this agent + * + * @return the {@link ExecutorService} instantiated for this agent + */ + public ExecutorService getSingleThreadExecutor() { + return getSingleThreadExecutor("Agent"); + } + + public synchronized ExecutorService getSingleThreadExecutor(String poolName) { + DBC.PRE.assertNotEmpty("poolName must be set!", poolName); + ExecutorService executor = this.executors.get(poolName); + if (executor == null) { + executor = Executors.newSingleThreadExecutor(new ThreadPoolFactory(poolName)); + this.executors.put(poolName, executor); + } + + return executor; + } + /** * Return the {@link ScheduledExecutorService} instantiated for this agent * @@ -125,8 +145,8 @@ public class StrolchAgent { } /** - * Initializes the underlying container and prepares the executor services. Before calling this method, - * {@link #setup(String, File, File, File)} must have ben called + * Initializes the underlying container and prepares the executor services. Before calling this method, {@link + * #setup(String, File, File, File)} must have ben called */ public void initialize() { if (this.container == null) diff --git a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java index e285d714d..0bdc06210 100644 --- a/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java +++ b/li.strolch.agent/src/main/java/li/strolch/agent/api/StrolchComponent.java @@ -136,6 +136,27 @@ public class StrolchComponent { return this.container.getAgent().getExecutor(poolName); } + /** + * Return the {@link ExecutorService} instantiated for this agent + * + * @return the {@link ExecutorService} instantiated for this agent + */ + protected ExecutorService getSingleThreadExecutor() { + return this.container.getAgent().getSingleThreadExecutor(); + } + + /** + * Return the {@link ExecutorService} for the given poolName instantiated for this agent + * + * @param poolName + * the name of the pool + * + * @return the {@link ExecutorService} for the given poolName instantiated for this agent + */ + protected ExecutorService getSingleThreadExecutor(String poolName) { + return this.container.getAgent().getSingleThreadExecutor(poolName); + } + /** * Return the {@link ScheduledExecutorService} instantiated for this agent *