X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FCore.java;h=731076b8e794ee44434939168960d41a968b3e18;hb=b9455984497cc0e9bc58d7b33eaf951e992eb141;hp=9aa60cf9da4f93b4cac4cd7c9c4fac920ad3cf2d;hpb=029548705a1fa60731ad7f492103333acdd48001;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/core/Core.java b/src/net/pterodactylus/jsite/core/Core.java index 9aa60cf..731076b 100644 --- a/src/net/pterodactylus/jsite/core/Core.java +++ b/src/net/pterodactylus/jsite/core/Core.java @@ -19,30 +19,15 @@ package net.pterodactylus.jsite.core; -import java.io.IOException; -import java.util.ArrayList; import java.util.List; /** - * The core of jSite. + * Interface for the core. * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> * @version $Id$ */ -public class Core { - - /** The core listeners. */ - private final List coreListeners = new ArrayList(); - - /** The project manager. */ - private ProjectManager projectManager; - - /** The node manager. */ - private NodeManager nodeManager; - - // - // LISTENER MANAGEMENT - // +public interface Core { /** * Adds the given listener to the list of registered listeners. @@ -50,9 +35,7 @@ public class Core { * @param coreListener * The listener to add */ - public void addCoreListener(CoreListener coreListener) { - coreListeners.add(coreListener); - } + public void addCoreListener(CoreListener coreListener); /** * Removes the given listener from the list of registered listeners. @@ -60,183 +43,14 @@ public class Core { * @param coreListener * The listener to remove */ - public void removeCoreListener(CoreListener coreListener) { - coreListeners.remove(coreListener); - } - - /** - * Notifies all listeners that the projects were loaded successfully. - * - * @param directory - * The directory the projects were loaded from - */ - private void fireLoadingProjectsDone(String directory) { - for (CoreListener coreListener: coreListeners) { - coreListener.loadingProjectsDone(directory); - } - } - - /** - * Notifies all core listeners that loading the projects from the given - * directory has failed. - * - * @param directory - * The directory the projects were tried to load from - * @param throwable - * The exception that occured when loading projects - */ - private void fireLoadingProjectsFailed(String directory, Throwable throwable) { - for (CoreListener coreListener: coreListeners) { - coreListener.loadingProjectsFailed(directory, throwable); - } - } - - /** - * Notifies all listeners that the projects were successfully saved. - * - * @param directory - * The directory the projects were saved to - */ - private void fireSavingProjectsDone(String directory) { - for (CoreListener coreListener: coreListeners) { - coreListener.savingProjectsDone(directory); - } - } - - /** - * Notifies all listeners that the projects could not be saved. - * - * @param directory - * The directory the projects were to be saved to - * @param throwable - * The exception that occured when saving the projects - */ - private void fireSavingProjectsFailed(String directory, Throwable throwable) { - for (CoreListener coreListener: coreListeners) { - coreListener.savingProjectsFailed(directory, throwable); - } - } - - /** - * Notifies all listeners that the nodes were successfully loaded. - * - * @param directory - * The directory the nodes were loaded from - */ - private void fireLoadingNodesDone(String directory) { - for (CoreListener coreListener: coreListeners) { - coreListener.loadingNodesDone(directory); - } - } - - /** - * Notifies all listeners that loading the nodes has failed. - * - * @param directory - * The directory the nodes were loaded from - * @param throwable - * The exception that occured while loading the nodes - */ - private void fireLoadingNodesFailed(String directory, Throwable throwable) { - for (CoreListener coreListener: coreListeners) { - coreListener.loadingNodesFailed(directory, throwable); - } - } - - /** - * Notifies all listeners that the nodes were saved successfully. - * - * @param directory - * The directory the nodes were saved to - */ - private void fireSavingNodesDone(String directory) { - for (CoreListener coreListener: coreListeners) { - coreListener.savingNodesDone(directory); - } - } - - /** - * Notifies all listeners that saving the nodes has failed. - * - * @param directory - * The directory the nodes were saved to - * @param throwable - * The exception that occured while saving the nodes - */ - private void fireSavingNodesFailed(String directory, Throwable throwable) { - for (CoreListener coreListener: coreListeners) { - coreListener.savingProjectsFailed(directory, throwable); - } - } - - /** - * Notifies all core listeners that the core has loaded and is ready to run. - */ - private void fireCoreLoaded() { - for (CoreListener coreListener: coreListeners) { - coreListener.coreLoaded(); - } - } - - /** - * Notifies all listeners that the core was stopped. - */ - private void fireCoreStopped() { - for (CoreListener coreListener: coreListeners) { - coreListener.coreStopped(); - } - } - - // - // ACCESSORS - // - - /** - * Returns the project manager. - * - * @return The project manager - */ - public ProjectManager getProjectManager() { - return projectManager; - } - - /** - * Sets the project manager to use. - * - * @param projectManager - * The project manager to use - */ - public void setProjectManager(ProjectManager projectManager) { - this.projectManager = projectManager; - } - - /** - * Returns the node manager. - * - * @return The node manager - */ - public NodeManager getNodeManager() { - return nodeManager; - } - - /** - * Sets the node manager to use. - * - * @param nodeManager - * The node manager to use - */ - public void setNodeManager(NodeManager nodeManager) { - this.nodeManager = nodeManager; - } + public void removeCoreListener(CoreListener coreListener); /** * Returns the list of all configured nodes. * * @return All configured nodes */ - public List getNodes() { - return nodeManager.getNodes(); - } + public List getNodes(); /** * Returns whether the core is currently connected to the given node. @@ -246,51 +60,17 @@ public class Core { * @return true if the core is currently connected to the * node, false otherwise */ - public boolean isNodeConnected(Node node) { - return nodeManager.hasNode(node); - } - - // - // ACTIONS - // + public boolean isNodeConnected(Node node); /** * Starts the core. */ - 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); - } - fireCoreLoaded(); - } + public void start(); /** * Stops the core. */ - public void stop() { - try { - projectManager.save(); - fireSavingProjectsDone(projectManager.getDirectory()); - } catch (IOException ioe1) { - fireSavingProjectsFailed(projectManager.getDirectory(), ioe1); - } - try { - nodeManager.save(); - fireSavingNodesDone(nodeManager.getDirectory()); - } catch (IOException ioe1) { - fireSavingNodesFailed(nodeManager.getDirectory(), ioe1); - } - fireCoreStopped(); - } + public void stop(); /** * Connects to the given node. @@ -298,28 +78,14 @@ public class Core { * @param node * The node to connect to */ - public void connectToNode(Node node) { - /* TODO */ - } - - // - // PRIVATE METHODS - // - - /** - * Loads the configuration. - */ - @SuppressWarnings("unused") - private void loadConfig() { - /* TODO */ - } + public void connectToNode(Node node); /** - * Saves the configuration. + * Disconnects from the given node. + * + * @param node + * The node to disconnect from */ - @SuppressWarnings("unused") - private void saveConfig() { - /* TODO */ - } + public void disconnectFromNode(Node node); -} +} \ No newline at end of file