From 992335d3698a0d73425bb288602ba7ad524cfea2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 3 Jun 2008 01:45:25 +0200 Subject: [PATCH] add thread pool --- src/net/pterodactylus/jsite/core/Core.java | 8 ++++ src/net/pterodactylus/jsite/core/CoreImpl.java | 63 ++++++++++++++++---------- 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/net/pterodactylus/jsite/core/Core.java b/src/net/pterodactylus/jsite/core/Core.java index 456ddae..7185b2e 100644 --- a/src/net/pterodactylus/jsite/core/Core.java +++ b/src/net/pterodactylus/jsite/core/Core.java @@ -22,6 +22,7 @@ package net.pterodactylus.jsite.core; import java.io.IOException; import java.net.UnknownHostException; import java.util.List; +import java.util.concurrent.Executor; import net.pterodactylus.jsite.project.Project; @@ -49,6 +50,13 @@ public interface Core { public void removeCoreListener(CoreListener coreListener); /** + * Returns a thread pool. + * + * @return A thread pool + */ + public Executor getThreadPool(); + + /** * Adds the given node to the core. * * @param node diff --git a/src/net/pterodactylus/jsite/core/CoreImpl.java b/src/net/pterodactylus/jsite/core/CoreImpl.java index 9073655..dc35c56 100644 --- a/src/net/pterodactylus/jsite/core/CoreImpl.java +++ b/src/net/pterodactylus/jsite/core/CoreImpl.java @@ -23,6 +23,8 @@ import java.io.IOException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; import net.pterodactylus.jsite.project.Project; import net.pterodactylus.jsite.project.ProjectManager; @@ -37,6 +39,9 @@ public class CoreImpl implements Core, NodeListener, RequestListener { /** The core listeners. */ private final List coreListeners = new ArrayList(); + /** Thread pool. */ + private Executor threadPool = Executors.newCachedThreadPool(); + /** The project manager. */ private ProjectManager projectManager; @@ -73,7 +78,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The directory the projects were loaded from */ private void fireLoadingProjectsDone(String directory) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.loadingProjectsDone(directory); } } @@ -88,7 +93,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The exception that occured when loading projects */ private void fireLoadingProjectsFailed(String directory, Throwable throwable) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.loadingProjectsFailed(directory, throwable); } } @@ -100,7 +105,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The directory the projects were saved to */ private void fireSavingProjectsDone(String directory) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.savingProjectsDone(directory); } } @@ -114,7 +119,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The exception that occured when saving the projects */ private void fireSavingProjectsFailed(String directory, Throwable throwable) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.savingProjectsFailed(directory, throwable); } } @@ -126,18 +131,21 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The project that was added */ private void fireProjectAdded(Project project) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.projectAdded(project); } } - + /** * Notifies all listeners that a project was cloned. - * @param clonedProject The project that was cloned - * @param projectClone The clone of the project + * + * @param clonedProject + * The project that was cloned + * @param projectClone + * The clone of the project */ private void fireProjectCloned(Project clonedProject, Project projectClone) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.projectCloned(clonedProject, projectClone); } } @@ -149,7 +157,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The project that was removed */ private void fireProjectRemoved(Project project) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.projectRemoved(project); } } @@ -161,7 +169,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The directory the nodes were loaded from */ private void fireLoadingNodesDone(String directory) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.loadingNodesDone(directory); } } @@ -175,7 +183,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The exception that occured while loading the nodes */ private void fireLoadingNodesFailed(String directory, Throwable throwable) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.loadingNodesFailed(directory, throwable); } } @@ -187,7 +195,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The directory the nodes were saved to */ private void fireSavingNodesDone(String directory) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.savingNodesDone(directory); } } @@ -201,7 +209,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The exception that occured while saving the nodes */ private void fireSavingNodesFailed(String directory, Throwable throwable) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.savingProjectsFailed(directory, throwable); } } @@ -210,7 +218,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * Notifies all core listeners that the core has loaded and is ready to run. */ private void fireCoreLoaded() { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.coreLoaded(); } } @@ -219,7 +227,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * Notifies all listeners that the core was stopped. */ private void fireCoreStopped() { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.coreStopped(); } } @@ -231,7 +239,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The node that was added */ private void fireNodeAdded(Node node) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.nodeAdded(node); } } @@ -243,7 +251,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The node that was removed */ private void fireNodeRemoved(Node node) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.nodeRemoved(node); } } @@ -256,7 +264,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The node that is being connected to */ private void fireNodeConnecting(Node node) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.nodeConnecting(node); } } @@ -268,7 +276,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The node that is now connected */ private void fireNodeConnected(Node node) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.nodeConnected(node); } } @@ -282,7 +290,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The cause of the failure */ private void fireNodeConnectionFailed(Node node, Throwable cause) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.nodeConnectionFailed(node, cause); } } @@ -297,7 +305,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * if there was no exception */ private void fireNodeDisconnected(Node node, Throwable throwable) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.nodeDisconnected(node, throwable); } } @@ -307,6 +315,13 @@ public class CoreImpl implements Core, NodeListener, RequestListener { // /** + * {@inheritDoc} + */ + public Executor getThreadPool() { + return threadPool; + } + + /** * Returns the project manager. * * @return The project manager @@ -461,7 +476,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { Project projectClone = projectManager.cloneProject(project); fireProjectCloned(project, projectClone); } - + /** * {@inheritDoc} */ @@ -469,7 +484,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { projectManager.removeProject(project); fireProjectRemoved(project); } - + // // PRIVATE METHODS // -- 2.7.4