Reformatting.
[jSite2.git] / src / net / pterodactylus / jsite / core / Core.java
index 7c37808..53cd6b7 100644 (file)
 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<CoreListener> coreListeners = new ArrayList<CoreListener>();
-
-       /** The project manager. */
-       private ProjectManager projectManager;
-
-       /** The node list. */
-       private List<Node> configuredNodes = new ArrayList<Node>();
-
-       /** List of currently connected nodes. */
-       private List<Node> connectedNodes = new ArrayList<Node>();
-
-       //
-       // 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,141 +45,61 @@ 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
-        */
-       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 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
+        * @param node
+        *            The node to add
+        * @return <code>true</code> if the node was added, <code>false</code> 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.
+        * Removes the given node from the core.
         *
-        * @param projectManager
-        *            The project manager to use
+        * @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<Node> getNodes() {
-               return configuredNodes;
-       }
+       public List<Node> getNodes();
 
        /**
         * Returns whether the core is currently connected to the given node.
         *
         * @param node
         *            The node to check
-        * @return <code>true</code> if the core is currently connected to the
-        *         node, <code>false</code> otherwise
+        * @return <code>true</code> if the core is currently connected to the node,
+        *         <code>false</code> 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.
@@ -205,28 +107,49 @@ public class Core {
         * @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);
 
-       //
-       // PRIVATE METHODS
-       //
+       /**
+        * 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;
 
        /**
-        * Loads the configuration.
+        * 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
         */
-       @SuppressWarnings("unused")
-       private void loadConfig() {
-               /* TODO */
-       }
+       public void cloneProject(Project project);
 
        /**
-        * Saves the configuration.
+        * Removes the given project.
+        *
+        * @param project
+        *            The project to remove
+        */
+       public void removeProject(Project project);
+
+       /**
+        * Returns a list of all projects.
+        *
+        * @return A list of all projects
         */
-       @SuppressWarnings("unused")
-       private void saveConfig() {
-               /* TODO */
-       }
+       public List<Project> getProjects();
 
 }