Implement InsertListener interface in CoreImpl.
[jSite2.git] / src / net / pterodactylus / jsite / core / Core.java
index 3f00678..27d87d9 100644 (file)
 
 package net.pterodactylus.jsite.core;
 
-import java.util.ArrayList;
+import java.io.IOException;
+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 node list. */
-       private List<Node> nodeList = new ArrayList<Node>();
-
-       /**
-        * Creates a new core.
-        */
-       public Core() {
-       }
-
-       //
-       // 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);
-       }
+       public void removeCoreListener(CoreListener coreListener);
+
+       /**
+        * Returns a thread pool.
+        *
+        * @return A thread pool
+        */
+       public Executor getThreadPool();
 
        /**
-        * Notifies all core listeners that the core has loaded and is ready to run.
+        * 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
         */
-       private void fireCoreLoaded() {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.coreLoaded();
-               }
-       }
+       public boolean addNode(Node node) throws UnknownHostException;
 
-       //
-       // ACCESSORS
-       //
+       /**
+        * Removes the given node from the core.
+        *
+        * @param node
+        *            The node to remove
+        */
+       public void removeNode(Node node);
 
        /**
         * Returns the list of all configured nodes.
-        * 
+        *
         * @return All configured nodes
         */
-       public List<Node> getNodeList() {
-               return nodeList;
-       }
+       public List<Node> getNodes();
 
-       //
-       // ACTIONS
-       //
+       /**
+        * 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);
 
        /**
         * Starts the core.
         */
-       public void start() {
-               fireCoreLoaded();
-       }
+       public void start();
+
+       /**
+        * Stops the core.
+        */
+       public void stop();
 
        /**
         * Connects to the given node.
-        * 
+        *
         * @param node
         *            The node to connect to
         */
-       public void connectToNode(Node node) {
-       }
+       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;
+
+       /**
+        * 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 insertProject(Node node, Project project);
+
+       /**
+        * 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);
+
+       /**
+        * 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
+        */
+       public List<Project> getProjects();
 
 }