X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FCore.java;h=27d87d97f3f1498418f975d26b416308fea85e7a;hb=e7fd217d2304bc11716525992ec6c8f22ae54914;hp=7c37808a3705400c93c617127cef30b773d68331;hpb=c7561c631f4bbb94ee0ac9047e953ce56f1df8bb;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/core/Core.java b/src/net/pterodactylus/jsite/core/Core.java index 7c37808..27d87d9 100644 --- a/src/net/pterodactylus/jsite/core/Core.java +++ b/src/net/pterodactylus/jsite/core/Core.java @@ -20,32 +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 list. */ - private List configuredNodes = new ArrayList(); - - /** List of currently connected nodes. */ - private List connectedNodes = new ArrayList(); - - // - // LISTENER MANAGEMENT - // +public interface Core { /** * Adds the given listener to the list of registered listeners. @@ -53,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. @@ -63,170 +45,121 @@ public class Core { * @param coreListener * The listener to remove */ - public void removeCoreListener(CoreListener coreListener) { - coreListeners.remove(coreListener); - } + 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 + * @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 fireSavingProjectsDone(String directory) { - for (CoreListener coreListener: coreListeners) { - coreListener.savingProjectsDone(directory); - } - } + public boolean addNode(Node node) throws UnknownHostException; /** - * Notifies all listeners that the projects could not be saved. + * Removes the given node from the core. * - * @param directory - * The directory the projects were to be saved to - * @param throwable - * The exception that occured when saving the projects + * @param node + * The node to remove */ - private void fireSavingProjectsFailed(String directory, Throwable throwable) { - for (CoreListener coreListener: coreListeners) { - coreListener.savingProjectsFailed(directory, throwable); - } - } + public void removeNode(Node node); /** - * Notifies all core listeners that the core has loaded and is ready to run. + * Returns the list of all configured nodes. + * + * @return All configured nodes */ - private void fireCoreLoaded() { - for (CoreListener coreListener: coreListeners) { - coreListener.coreLoaded(); - } - } + public List getNodes(); /** - * Notifies all listeners that the core was stopped. + * Returns whether the core is currently connected to the given node. + * + * @param node + * The node to check + * @return true if the core is currently connected to the node, + * false otherwise */ - private void fireCoreStopped() { - for (CoreListener coreListener: coreListeners) { - coreListener.coreStopped(); - } - } - - // - // ACCESSORS - // + public boolean isNodeConnected(Node node); /** - * Returns the project manager. - * - * @return The project manager + * Starts the core. */ - public ProjectManager getProjectManager() { - return projectManager; - } + public void start(); /** - * Sets the project manager to use. - * - * @param projectManager - * The project manager to use + * Stops the core. */ - public void setProjectManager(ProjectManager projectManager) { - this.projectManager = projectManager; - } + public void stop(); /** - * Returns the list of all configured nodes. + * Connects to the given node. * - * @return All configured nodes + * @param node + * The node to connect to */ - public List getNodes() { - return configuredNodes; - } + public void connectToNode(Node node); /** - * Returns whether the core is currently connected to the given node. + * Disconnects from the given node. * * @param node - * The node to check - * @return true if the core is currently connected to the - * node, false otherwise + * The node to disconnect from */ - public boolean isNodeConnected(Node node) { - return connectedNodes.contains(node); - } - - // - // ACTIONS - // + public void disconnectFromNode(Node node); /** - * Starts the core. + * Creates a new project. + * + * @throws IOException + * if an I/O error occured communicating with the node + * @throws JSiteException + * if there is a problem with the node */ - public void start() { - try { - projectManager.load(); - } catch (IOException ioe1) { - fireLoadingProjectsFailed(projectManager.getDirectory(), ioe1); - } - fireCoreLoaded(); - } + public void createProject() throws IOException, JSiteException; /** - * Stops the core. + * Inserts the given project on the given node. + * + * @param node + * The node to use for the insert + * @param project + * The project to insert */ - public void stop() { - try { - projectManager.save(); - fireSavingProjectsDone(projectManager.getDirectory()); - } catch (IOException ioe1) { - fireSavingProjectsFailed(projectManager.getDirectory(), ioe1); - } - fireCoreStopped(); - } + public void insertProject(Node node, Project project); /** - * Connects to the given node. + * Clones the given project. {@link CoreListener}s will be notified of the + * new clone via the {@link CoreListener#projectCloned(Project, Project)} + * event. * - * @param node - * The node to connect to + * @param project + * The project to clone */ - public void connectToNode(Node node) { - /* TODO */ - } - - // - // PRIVATE METHODS - // + public void cloneProject(Project project); /** - * Loads the configuration. + * Removes the given project. + * + * @param project + * The project to remove */ - @SuppressWarnings("unused") - private void loadConfig() { - /* TODO */ - } + public void removeProject(Project project); /** - * Saves the configuration. + * Returns a list of all projects. + * + * @return A list of all projects */ - @SuppressWarnings("unused") - private void saveConfig() { - /* TODO */ - } + public List getProjects(); }