add request management
[jSite2.git] / src / net / pterodactylus / jsite / core / CoreImpl.java
index 8fe64da..9c68d44 100644 (file)
@@ -25,11 +25,11 @@ import java.util.List;
 
 /**
  * The core of jSite.
- *
+ * 
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  * @version $Id$
  */
-public class CoreImpl implements Core, NodeListener {
+public class CoreImpl implements Core, NodeListener, RequestListener {
 
        /** The core listeners. */
        private final List<CoreListener> coreListeners = new ArrayList<CoreListener>();
@@ -40,6 +40,11 @@ public class CoreImpl implements Core, NodeListener {
        /** The node manager. */
        private NodeManager nodeManager;
 
+       /** The request manager. */
+       /* TODO - remove */
+       @SuppressWarnings("unused")
+       private RequestManager requestManager;
+
        //
        // LISTENER MANAGEMENT
        //
@@ -60,7 +65,7 @@ public class CoreImpl implements Core, NodeListener {
 
        /**
         * Notifies all listeners that the projects were loaded successfully.
-        *
+        * 
         * @param directory
         *            The directory the projects were loaded from
         */
@@ -73,7 +78,7 @@ public class CoreImpl implements Core, NodeListener {
        /**
         * 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
@@ -87,7 +92,7 @@ public class CoreImpl implements Core, NodeListener {
 
        /**
         * Notifies all listeners that the projects were successfully saved.
-        *
+        * 
         * @param directory
         *            The directory the projects were saved to
         */
@@ -99,7 +104,7 @@ public class CoreImpl implements Core, NodeListener {
 
        /**
         * Notifies all listeners that the projects could not be saved.
-        *
+        * 
         * @param directory
         *            The directory the projects were to be saved to
         * @param throwable
@@ -113,7 +118,7 @@ public class CoreImpl implements Core, NodeListener {
 
        /**
         * Notifies all listeners that the nodes were successfully loaded.
-        *
+        * 
         * @param directory
         *            The directory the nodes were loaded from
         */
@@ -125,7 +130,7 @@ public class CoreImpl implements Core, NodeListener {
 
        /**
         * Notifies all listeners that loading the nodes has failed.
-        *
+        * 
         * @param directory
         *            The directory the nodes were loaded from
         * @param throwable
@@ -139,7 +144,7 @@ public class CoreImpl implements Core, NodeListener {
 
        /**
         * Notifies all listeners that the nodes were saved successfully.
-        *
+        * 
         * @param directory
         *            The directory the nodes were saved to
         */
@@ -151,7 +156,7 @@ public class CoreImpl implements Core, NodeListener {
 
        /**
         * Notifies all listeners that saving the nodes has failed.
-        *
+        * 
         * @param directory
         *            The directory the nodes were saved to
         * @param throwable
@@ -184,7 +189,7 @@ public class CoreImpl implements Core, NodeListener {
        /**
         * Notifies all listeners that a connection to the given node is now being
         * established.
-        *
+        * 
         * @param node
         *            The node that is being connected to
         */
@@ -196,7 +201,7 @@ public class CoreImpl implements Core, NodeListener {
 
        /**
         * Notifies all listeners that the given node is now connected.
-        *
+        * 
         * @param node
         *            The node that is now connected
         */
@@ -208,7 +213,7 @@ public class CoreImpl implements Core, NodeListener {
 
        /**
         * Notifies all listeners that the given node was disconnected.
-        *
+        * 
         * @param node
         *            The node that is now disconnected
         * @param throwable
@@ -221,13 +226,27 @@ public class CoreImpl implements Core, NodeListener {
                }
        }
 
+       /**
+        * Notifies all listeners that a request was added to a node.
+        * 
+        * @param node
+        *            The node the request was added to
+        * @param request
+        *            The request that was added
+        */
+       private void fireRequestAdded(Node node, Request request) {
+               for (CoreListener coreListener: coreListeners) {
+                       coreListener.requestAdded(node, request);
+               }
+       }
+
        //
        // ACCESSORS
        //
 
        /**
         * Returns the project manager.
-        *
+        * 
         * @return The project manager
         */
        public ProjectManager getProjectManager() {
@@ -236,7 +255,7 @@ public class CoreImpl implements Core, NodeListener {
 
        /**
         * Sets the project manager to use.
-        *
+        * 
         * @param projectManager
         *            The project manager to use
         */
@@ -246,7 +265,7 @@ public class CoreImpl implements Core, NodeListener {
 
        /**
         * Returns the node manager.
-        *
+        * 
         * @return The node manager
         */
        public NodeManager getNodeManager() {
@@ -255,7 +274,7 @@ public class CoreImpl implements Core, NodeListener {
 
        /**
         * Sets the node manager to use.
-        *
+        * 
         * @param nodeManager
         *            The node manager to use
         */
@@ -264,6 +283,16 @@ public class CoreImpl implements Core, NodeListener {
        }
 
        /**
+        * Sets the request manager to use.
+        * 
+        * @param requestManager
+        *            The request manager to use
+        */
+       public void setRequestManager(RequestManager requestManager) {
+               this.requestManager = requestManager;
+       }
+
+       /**
         * {@inheritDoc}
         */
        public List<Node> getNodes() {
@@ -373,4 +402,15 @@ public class CoreImpl implements Core, NodeListener {
                fireNodeDisconnected(node, throwable);
        }
 
+       //
+       // INTERFACE RequestListener
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       public void requestAdded(Node node, Request request) {
+               fireRequestAdded(node, request);
+       }
+
 }