X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FCoreImpl.java;h=cd65bf45bccded461a6ce310ed5ba4bfce9b0666;hb=fcaa97bae5d6ca064d194900f8275701326950a4;hp=dbc59977475b1bb28eb727be51f6db1d51965aa8;hpb=03d89340924164e1158490999186383217e9d2bd;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/core/CoreImpl.java b/src/net/pterodactylus/jsite/core/CoreImpl.java index dbc5997..cd65bf4 100644 --- a/src/net/pterodactylus/jsite/core/CoreImpl.java +++ b/src/net/pterodactylus/jsite/core/CoreImpl.java @@ -23,9 +23,9 @@ 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; /** * The core of jSite. @@ -37,6 +37,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 +76,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 +91,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 +103,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 +117,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,19 +129,33 @@ 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 + */ + private void fireProjectCloned(Project clonedProject, Project projectClone) { + for (CoreListener coreListener : coreListeners) { + coreListener.projectCloned(clonedProject, projectClone); + } + } + + /** * Notifies all listeners that a project was removed. * * @param project * The project that was removed */ private void fireProjectRemoved(Project project) { - for (CoreListener coreListener: coreListeners) { + for (CoreListener coreListener : coreListeners) { coreListener.projectRemoved(project); } } @@ -150,7 +167,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); } } @@ -164,7 +181,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); } } @@ -176,7 +193,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); } } @@ -190,7 +207,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); } } @@ -199,7 +216,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(); } } @@ -208,7 +225,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(); } } @@ -220,7 +237,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); } } @@ -232,7 +249,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); } } @@ -245,7 +262,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); } } @@ -257,7 +274,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); } } @@ -271,7 +288,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); } } @@ -286,7 +303,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); } } @@ -296,6 +313,13 @@ public class CoreImpl implements Core, NodeListener, RequestListener { // /** + * {@inheritDoc} + */ + public Executor getThreadPool() { + return threadPool; + } + + /** * Returns the project manager. * * @return The project manager @@ -373,17 +397,17 @@ public class CoreImpl implements Core, NodeListener, RequestListener { */ public void start() { try { - projectManager.load(); - fireLoadingProjectsDone(projectManager.getDirectory()); - } catch (IOException ioe1) { - fireLoadingProjectsFailed(projectManager.getDirectory(), ioe1); - } - try { nodeManager.load(); fireLoadingNodesDone(nodeManager.getDirectory()); } catch (IOException ioe1) { fireLoadingNodesFailed(nodeManager.getDirectory(), ioe1); } + try { + projectManager.load(); + fireLoadingProjectsDone(projectManager.getDirectory()); + } catch (IOException ioe1) { + fireLoadingProjectsFailed(projectManager.getDirectory(), ioe1); + } fireCoreLoaded(); } @@ -446,11 +470,19 @@ public class CoreImpl implements Core, NodeListener, RequestListener { /** * {@inheritDoc} */ + public void cloneProject(Project project) { + Project projectClone = projectManager.cloneProject(project); + fireProjectCloned(project, projectClone); + } + + /** + * {@inheritDoc} + */ public void removeProject(Project project) { projectManager.removeProject(project); fireProjectRemoved(project); } - + // // PRIVATE METHODS //