move project stuff again
[jSite2.git] / src / net / pterodactylus / jsite / core / Core.java
index 9aa60cf..4a3531a 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 manager. */
-       private NodeManager nodeManager;
-
-       //
-       // 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 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;
-       }
+       public void removeCoreListener(CoreListener coreListener);
 
        /**
-        * Sets the project manager to use.
-        *
-        * @param projectManager
-        *            The project manager to use
+        * Returns a thread pool.
+        * 
+        * @return A thread pool
         */
-       public void setProjectManager(ProjectManager projectManager) {
-               this.projectManager = projectManager;
-       }
+       public Executor getThreadPool();
 
        /**
-        * Returns the node manager.
-        *
-        * @return The node manager
+        * Adds the given node to the core.
+        * 
+        * @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 NodeManager getNodeManager() {
-               return nodeManager;
-       }
+       public boolean addNode(Node node) throws UnknownHostException;
 
        /**
-        * Sets the node manager to use.
-        *
-        * @param nodeManager
-        *            The node manager to use
+        * Removes the given node from the core.
+        * 
+        * @param node
+        *            The node to remove
         */
-       public void setNodeManager(NodeManager nodeManager) {
-               this.nodeManager = nodeManager;
-       }
+       public void removeNode(Node node);
 
        /**
         * Returns the list of all configured nodes.
-        *
+        * 
         * @return All configured nodes
         */
-       public List<Node> getNodes() {
-               return nodeManager.getNodes();
-       }
+       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
         */
-       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.
-        *
+        * 
         * @param node
         *            The node to connect to
         */
-       public void connectToNode(Node node) {
-               /* TODO */
-       }
+       public void connectToNode(Node node);
 
-       //
-       // PRIVATE METHODS
-       //
+       /**
+        * 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;
+
+       /**
+        * 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<Project> getProjects();
 
 }