X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FCore.java;h=53cd6b7b0ef8959de6560f5611e86b34f0ca6e1f;hb=6bb73948c60f63571115c6556f6b90293fd99432;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..53cd6b7 100644 --- a/src/net/pterodactylus/jsite/core/Core.java +++ b/src/net/pterodactylus/jsite/core/Core.java @@ -20,29 +20,16 @@ package net.pterodactylus.jsite.core; import java.io.IOException; -import java.util.ArrayList; +import java.net.UnknownHostException; import java.util.List; +import java.util.concurrent.Executor; /** - * 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 +37,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,266 +45,111 @@ 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); - } - } + public void removeCoreListener(CoreListener coreListener); /** - * Notifies all core listeners that loading the projects from the given - * directory has failed. + * Returns a thread pool. * - * @param directory - * The directory the projects were tried to load from - * @param throwable - * The exception that occured when loading projects + * @return A thread pool */ - private void fireLoadingProjectsFailed(String directory, Throwable throwable) { - for (CoreListener coreListener: coreListeners) { - coreListener.loadingProjectsFailed(directory, throwable); - } - } + public Executor getThreadPool(); /** - * Notifies all listeners that the projects were successfully saved. + * Adds the given node to the core. * - * @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 + * @param node + * The node to add + * @return true if the node was added, false if it + * was not added because it was already known + * @throws UnknownHostException + * if the hostname of the node can not be resolved */ - private void fireLoadingNodesDone(String directory) { - for (CoreListener coreListener: coreListeners) { - coreListener.loadingNodesDone(directory); - } - } + public boolean addNode(Node node) throws UnknownHostException; /** - * Notifies all listeners that loading the nodes has failed. + * Removes the given node from the core. * - * @param directory - * The directory the nodes were loaded from - * @param throwable - * The exception that occured while loading the nodes + * @param node + * The node to remove */ - private void fireLoadingNodesFailed(String directory, Throwable throwable) { - for (CoreListener coreListener: coreListeners) { - coreListener.loadingNodesFailed(directory, throwable); - } - } + public void removeNode(Node node); /** - * Notifies all listeners that the nodes were saved successfully. + * Returns the list of all configured nodes. * - * @param directory - * The directory the nodes were saved to + * @return All configured nodes */ - private void fireSavingNodesDone(String directory) { - for (CoreListener coreListener: coreListeners) { - coreListener.savingNodesDone(directory); - } - } + public List getNodes(); /** - * Notifies all listeners that saving the nodes has failed. + * Returns whether the core is currently connected to the given node. * - * @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. + * @param node + * The node to check + * @return true if the core is currently connected to the node, + * false otherwise */ - private void fireCoreLoaded() { - for (CoreListener coreListener: coreListeners) { - coreListener.coreLoaded(); - } - } + public boolean isNodeConnected(Node node); /** - * Notifies all listeners that the core was stopped. + * Starts the core. */ - private void fireCoreStopped() { - for (CoreListener coreListener: coreListeners) { - coreListener.coreStopped(); - } - } - - // - // ACCESSORS - // + public void start(); /** - * Returns the project manager. - * - * @return The project manager + * Stops the core. */ - public ProjectManager getProjectManager() { - return projectManager; - } + public void stop(); /** - * Sets the project manager to use. + * Connects to the given node. * - * @param projectManager - * The project manager to use + * @param node + * The node to connect to */ - public void setProjectManager(ProjectManager projectManager) { - this.projectManager = projectManager; - } + public void connectToNode(Node node); /** - * Returns the node manager. + * Disconnects from the given node. * - * @return The node manager + * @param node + * The node to disconnect from */ - public NodeManager getNodeManager() { - return nodeManager; - } + public void disconnectFromNode(Node node); /** - * Sets the node manager to use. + * Creates a new project. * - * @param nodeManager - * The node manager to use + * @throws IOException + * if an I/O error occured communicating with the node + * @throws JSiteException + * if there is a problem with the node */ - public void setNodeManager(NodeManager nodeManager) { - this.nodeManager = nodeManager; - } + public void createProject() throws IOException, JSiteException; /** - * Returns the list of all configured nodes. + * Clones the given project. {@link CoreListener}s will be notified of the + * new clone via the {@link CoreListener#projectCloned(Project, Project)} + * event. * - * @return All configured nodes + * @param project + * The project to clone */ - public List getNodes() { - return nodeManager.getNodes(); - } + public void cloneProject(Project project); /** - * Returns whether the core is currently connected to the given node. + * Removes the given project. * - * @param node - * The node to check - * @return true if the core is currently connected to the - * node, false otherwise - */ - public boolean isNodeConnected(Node node) { - return nodeManager.hasNode(node); - } - - // - // ACTIONS - // - - /** - * Starts the core. + * @param project + * The project to remove */ - 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 removeProject(Project project); /** - * 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(); - } - - /** - * Connects to the given node. + * Returns a list of all projects. * - * @param node - * The node to connect to - */ - public void connectToNode(Node node) { - /* TODO */ - } - - // - // PRIVATE METHODS - // - - /** - * Loads the configuration. - */ - @SuppressWarnings("unused") - private void loadConfig() { - /* TODO */ - } - - /** - * Saves the configuration. + * @return A list of all projects */ - @SuppressWarnings("unused") - private void saveConfig() { - /* TODO */ - } + public List getProjects(); }