remove request events from core listener
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 23 May 2008 15:49:14 +0000 (15:49 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 23 May 2008 15:49:14 +0000 (15:49 +0000)
complete requests with more progress stuff

git-svn-id: http://trooper/svn/projects/jSite/trunk@939 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/jsite/core/CoreImpl.java
src/net/pterodactylus/jsite/core/CoreListener.java
src/net/pterodactylus/jsite/core/Request.java
src/net/pterodactylus/jsite/core/RequestListener.java
src/net/pterodactylus/jsite/core/RequestManager.java
src/net/pterodactylus/jsite/gui/SwingInterface.java

index cf5a941..15f217d 100644 (file)
@@ -268,42 +268,6 @@ public class CoreImpl implements Core, NodeListener, RequestListener {
                }
        }
 
-       /**
-        * Notifies all listeners that a request was added to a node.
-        * 
-        * @param request
-        *            The request that was added
-        */
-       private void fireRequestAdded(Request request) {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.requestAdded(request);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a request progressed.
-        * 
-        * @param request
-        *            The request
-        */
-       private void fireRequestProgressed(Request request) {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.requestProgressed(request);
-               }
-       }
-
-       /**
-        * Notifies all listeners that a request was removed.
-        * 
-        * @param request
-        *            The request that was removed
-        */
-       private void fireRequestRemoved(Request request) {
-               for (CoreListener coreListener: coreListeners) {
-                       coreListener.requestRemoved(request);
-               }
-       }
-
        //
        // ACCESSORS
        //
@@ -522,21 +486,35 @@ public class CoreImpl implements Core, NodeListener, RequestListener {
         * {@inheritDoc}
         */
        public void requestAdded(Request request) {
-               fireRequestAdded(request);
+               /* TODO - find project and process request */
        }
 
        /**
         * @see net.pterodactylus.jsite.core.RequestListener#requestProgressed(Request)
         */
        public void requestProgressed(Request request) {
-               fireRequestProgressed(request);
+               /* TODO - find project and process request */
        }
 
        /**
         * @see net.pterodactylus.jsite.core.RequestListener#requestRemoved(net.pterodactylus.jsite.core.Request)
         */
        public void requestRemoved(Request request) {
-               fireRequestRemoved(request);
+               /* TODO - find project and process request */
+       }
+
+       /**
+        * @see net.pterodactylus.jsite.core.RequestListener#requestGeneratedURI(net.pterodactylus.jsite.core.Request, java.lang.String)
+        */
+       public void requestGeneratedURI(Request request, String uri) {
+               /* TODO - find project and process request */
        }
+       
+       /**
+     * @see net.pterodactylus.jsite.core.RequestListener#requestFinished(net.pterodactylus.jsite.core.Request)
+     */
+    public void requestFinished(Request request) {
+               /* TODO - find project and process request */
+    }
 
 }
index d5d8cdc..e2d4946 100644 (file)
@@ -19,6 +19,8 @@
 
 package net.pterodactylus.jsite.core;
 
+import net.pterodactylus.jsite.project.Project;
+
 /**
  * Interface definition for user interfaces.
  * 
@@ -184,31 +186,58 @@ public interface CoreListener {
        public void nodeDisconnected(Node node, Throwable throwable);
 
        //
-       // request stuff
+       // project insertion stuff
        //
 
        /**
-        * Notifies a listener that a request was added to a node.
+        * Notifies a listener that a project insert started.
+        * 
+        * @param project
+        *            The project that is now inserting
+        */
+       public void projectInsertStarted(Project project);
+
+       /**
+        * Notifies a listener that a project insert made progress.
         * 
-        * @param request
-        *            The request that was added
+        * @param project
+        *            The project that made progress
+        * @param totalBlocks
+        *            The number of total blocks
+        * @param requiredBlocks
+        *            The number of required blocks
+        * @param successfulBlocks
+        *            The number of successfully inserted blocks
+        * @param failedBlocks
+        *            The number of blocks that could not be inserted
+        * @param fatallyFailedBlocks
+        *            The number of blocks that can not be inserted even with
+        *            retries
+        * @param finalizedTotal
+        *            <code>true</code> if the number of total blocks is already
+        *            finalized, <code>false</code> otherwise
         */
-       public void requestAdded(Request request);
+       public void projectInsertProgressed(Project project, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean finalizedTotal);
 
        /**
-        * Notifies a listener that a request made some progress.
+        * Notifies a listener that a project insert has generated a URI.
         * 
-        * @param request
-        *            The request that made the progress
+        * @param project
+        *            The project that generated a URI
+        * @param uri
+        *            The URI that was generated
         */
-       public void requestProgressed(Request request);
+       public void projectInsertGeneratedURI(Project project, String uri);
 
        /**
-        * Notifies a listener that a request was removed.
+        * Notifies a listener that a project insert has finished.
         * 
-        * @param request
-        *            The request that was removed
+        * @param project
+        *            The project that has finished
+        * @param success
+        *            <code>true</code> if the project was inserted successfully,
+        *            <code>false</code> otherwise
         */
-       public void requestRemoved(Request request);
+       public void projectInsertFinished(Project project, boolean success);
 
 }
index 6f05e7b..702e135 100644 (file)
@@ -66,6 +66,9 @@ public class Request extends AbstractBean {
        /** Name of the “fetchable” property. */
        public static final String PROPERTY_FETCHABLE = "fetchable";
 
+       /** Name of the “URI” property. */
+       public static final String PROPERTY_URI = "uri";
+
        /** Name of the “total blocks” property. */
        public static final String PROPERTY_TOTAL_BLOCKS = "totalBlocks";
 
@@ -105,6 +108,9 @@ public class Request extends AbstractBean {
        /** Whether the data is already fetchable (in case of put requests). */
        private boolean fetchable;
 
+       /** The generated URI. */
+       private String uri;
+
        /** The total number of blocks. */
        private int totalBlocks;
 
@@ -275,6 +281,25 @@ public class Request extends AbstractBean {
        }
 
        /**
+        * Returns the URI generated by this request.
+        * 
+        * @return The generated URI
+        */
+       public String getURI() {
+               return uri;
+       }
+
+       /**
+        * Sets the URI generated by this request.
+        * 
+        * @param uri
+        *            The generated URI
+        */
+       void setURI(String uri) {
+               this.uri = uri;
+       }
+
+       /**
         * Returns the total number of blocks of a request. Until
         * {@link #isTotalFinalized()} returns <code>true</code> this value may
         * change!
index 27ce517..b7ba758 100644 (file)
@@ -53,4 +53,22 @@ public interface RequestListener extends EventListener {
         */
        public void requestRemoved(Request request);
 
+       /**
+        * Notifies a listener that a Put request has generated a URI.
+        * 
+        * @param request
+        *            The request that generated a URI
+        * @param uri
+        *            The generated URI
+        */
+       public void requestGeneratedURI(Request request, String uri);
+
+       /**
+        * Notifies a listener that a request has completed.
+        * 
+        * @param request
+        *            The finished request
+        */
+       public void requestFinished(Request request);
+
 }
index 4e23d79..8f73b8d 100644 (file)
@@ -126,6 +126,34 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
                }
        }
 
+       /**
+        * Notifies all listeners that a request has finished.
+        * 
+        * @see RequestListener#requestFinished(Request)
+        * @param request
+        *            The request that has finished
+        */
+       private void fireRequestFinished(Request request) {
+               for (RequestListener requestListener: requestListeners) {
+                       requestListener.requestFinished(request);
+               }
+       }
+
+       /**
+        * Notifies all listeners that a request has generated a URI.
+        * 
+        * @see RequestListener#requestGeneratedURI(Request, String)
+        * @param request
+        *            The request that has generated a URI
+        * @param uri
+        *            The generated URI
+        */
+       private void fireRequestGeneratedURI(Request request, String uri) {
+               for (RequestListener requestListener: requestListeners) {
+                       requestListener.requestGeneratedURI(request, uri);
+               }
+       }
+
        //
        // ACCESSORS
        //
@@ -308,13 +336,24 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
                        identifierRequests.put(identifier, request);
                        fireRequestAdded(request);
                }
-               request.setTotalBlocks(highLevelProgress.getTotalBlocks());
-               request.setRequiredBlocks(highLevelProgress.getRequiredBlocks());
-               request.setSuccessfulBlocks(highLevelProgress.getSuccessfulBlocks());
-               request.setFailedBlocks(highLevelProgress.getFailedBlocks());
-               request.setFatallyFailedBlocks(highLevelProgress.getFatallyFailedBlocks());
-               request.setTotalFinalized(highLevelProgress.isTotalFinalized());
-               fireRequestProgressed(request);
+               if (highLevelProgress.isFinished()) {
+                       request.setFinished(true);
+                       request.setSuccessful(!highLevelProgress.isFailed());
+                       fireRequestFinished(request);
+               } else if (highLevelProgress.isFetchable()) {
+                       /* TODO - ignore? */
+               } else if (highLevelProgress.getURI() != null) {
+                       request.setURI(highLevelProgress.getURI());
+                       fireRequestGeneratedURI(request, highLevelProgress.getURI());
+               } else {
+                       request.setTotalBlocks(highLevelProgress.getTotalBlocks());
+                       request.setRequiredBlocks(highLevelProgress.getRequiredBlocks());
+                       request.setSuccessfulBlocks(highLevelProgress.getSuccessfulBlocks());
+                       request.setFailedBlocks(highLevelProgress.getFailedBlocks());
+                       request.setFatallyFailedBlocks(highLevelProgress.getFatallyFailedBlocks());
+                       request.setTotalFinalized(highLevelProgress.isTotalFinalized());
+                       fireRequestProgressed(request);
+               }
        }
 
 }
index b32694c..3c073be 100644 (file)
@@ -48,7 +48,6 @@ import net.pterodactylus.jsite.core.Core;
 import net.pterodactylus.jsite.core.CoreListener;
 import net.pterodactylus.jsite.core.JSiteException;
 import net.pterodactylus.jsite.core.Node;
-import net.pterodactylus.jsite.core.Request;
 import net.pterodactylus.jsite.i18n.I18n;
 import net.pterodactylus.jsite.i18n.gui.I18nAction;
 import net.pterodactylus.jsite.project.Project;
@@ -978,25 +977,34 @@ public class SwingInterface implements CoreListener, LoggingListener {
        }
 
        /**
-        * {@inheritDoc}
+        * @see net.pterodactylus.jsite.core.CoreListener#projectInsertStarted(net.pterodactylus.jsite.project.Project)
         */
-       public void requestAdded(Request request) {
-               logger.log(Level.INFO, "request added to node: " + request + ", " + request.getNode());
-               /* TODO - implement */
+       public void projectInsertStarted(Project project) {
+               /* TODO - show in interface */
        }
 
        /**
-        * {@inheritDoc}
+        * @see net.pterodactylus.jsite.core.CoreListener#projectInsertProgressed(net.pterodactylus.jsite.project.Project,
+        *      int, int, int, int, int, boolean)
+        */
+       public void projectInsertProgressed(Project project, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean finalizedTotal) {
+               /* TODO - show in interface */
+       }
+
+       /**
+        * @see net.pterodactylus.jsite.core.CoreListener#projectInsertGeneratedURI(net.pterodactylus.jsite.project.Project,
+        *      java.lang.String)
         */
-       public void requestProgressed(Request request) {
-               /* TODO - implement */
+       public void projectInsertGeneratedURI(Project project, String uri) {
+               /* TODO - show in interface */
        }
 
        /**
-        * @see net.pterodactylus.jsite.core.CoreListener#requestRemoved(net.pterodactylus.jsite.core.Request)
+        * @see net.pterodactylus.jsite.core.CoreListener#projectInsertFinished(net.pterodactylus.jsite.project.Project,
+        *      boolean)
         */
-       public void requestRemoved(Request request) {
-               /* TODO - implement */
+       public void projectInsertFinished(Project project, boolean success) {
+               /* TODO - show in interface */
        }
 
        //