X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FCore.java;h=4a3531a98cef33a6a7c8b8f03788adb5792eb3f1;hb=dc37f1e959fe36099d157e6d09b5790d4e06897c;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..4a3531a 100644 --- a/src/net/pterodactylus/jsite/core/Core.java +++ b/src/net/pterodactylus/jsite/core/Core.java @@ -20,213 +20,137 @@ 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. - * + * * @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. - * + * * @param coreListener * The listener to remove */ - public void removeCoreListener(CoreListener coreListener) { - coreListeners.remove(coreListener); - } - - /** - * 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); - } - } + public void removeCoreListener(CoreListener coreListener); /** - * Notifies all core listeners that the core has loaded and is ready to run. + * Returns a thread pool. + * + * @return A thread pool */ - private void fireCoreLoaded() { - for (CoreListener coreListener: coreListeners) { - coreListener.coreLoaded(); - } - } + public Executor getThreadPool(); /** - * 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 + * Adds the given node to the core. + * + * @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 */ - public ProjectManager getProjectManager() { - return projectManager; - } + public boolean addNode(Node node) throws UnknownHostException; /** - * Sets the project manager to use. - * - * @param projectManager - * The project manager to use + * Removes the given node from the core. + * + * @param node + * The node to remove */ - public void setProjectManager(ProjectManager projectManager) { - this.projectManager = projectManager; - } + public void removeNode(Node node); /** * Returns the list of all configured nodes. - * + * * @return All configured nodes */ - public List getNodes() { - return configuredNodes; - } + public List getNodes(); /** * 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 */ - public boolean isNodeConnected(Node node) { - return connectedNodes.contains(node); - } - - // - // ACTIONS - // + public boolean isNodeConnected(Node node); /** * Starts the core. */ - public void start() { - try { - projectManager.load(); - } catch (IOException ioe1) { - fireLoadingProjectsFailed(projectManager.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); - } - fireCoreStopped(); - } + public void stop(); /** * Connects to the given node. - * + * * @param node * The node to connect to */ - public void connectToNode(Node node) { - /* TODO */ - } + public void connectToNode(Node node); + + /** + * Disconnects from the given node. + * + * @param node + * The node to disconnect from + */ + public void disconnectFromNode(Node node); + + /** + * 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 createProject() throws IOException, JSiteException; - // - // PRIVATE METHODS - // + /** + * Clones the given project. {@link CoreListener}s will be notified of the + * new clone via the {@link CoreListener#projectCloned(Project, Project)} + * event. + * + * @param project + * The project to clone + */ + 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(); }