add SimpleProgress
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 11 Apr 2008 00:13:49 +0000 (00:13 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 11 Apr 2008 00:13:49 +0000 (00:13 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@700 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/util/fcp/FcpAdapter.java
src/net/pterodactylus/util/fcp/FcpConnection.java
src/net/pterodactylus/util/fcp/FcpListener.java
src/net/pterodactylus/util/fcp/SimpleProgress.java [new file with mode: 0644]

index 7111176..f0f4876 100644 (file)
@@ -136,6 +136,14 @@ public class FcpAdapter implements FcpListener {
        }
 
        /**
+        * @see net.pterodactylus.util.fcp.FcpListener#receivedSimpleProgress(net.pterodactylus.util.fcp.FcpConnection,
+        *      net.pterodactylus.util.fcp.SimpleProgress)
+        */
+       public void receivedSimpleProgress(FcpConnection fcpConnection, SimpleProgress simpleProgress) {
+               /* empty. */
+       }
+
+       /**
         * @see net.pterodactylus.util.fcp.FcpListener#receivedProtocolError(net.pterodactylus.util.fcp.FcpConnection,
         *      net.pterodactylus.util.fcp.ProtocolError)
         */
index 96f2ea0..815e45e 100644 (file)
@@ -336,6 +336,18 @@ public class FcpConnection {
        }
 
        /**
+        * Notifies all listeners that a “SimpleProgress” message was received.
+        * 
+        * @param simpleProgress
+        *            The “SimpleProgress” message
+        */
+       private void fireReceivedSimpleProgress(SimpleProgress simpleProgress) {
+               for (FcpListener fcpListener: fcpListeners) {
+                       fcpListener.receivedSimpleProgress(this, simpleProgress);
+               }
+       }
+
+       /**
         * Notifies all listeners that a “ProtocolError” message was received.
         * 
         * @param protocolError
@@ -421,7 +433,9 @@ public class FcpConnection {
         */
        void handleMessage(FcpMessage fcpMessage) {
                String messageName = fcpMessage.getName();
-               if ("ProtocolError".equals(messageName)) {
+               if ("SimpleProgress".equals(messageName)) {
+                       fireReceivedSimpleProgress(new SimpleProgress(fcpMessage));
+               } else if ("ProtocolError".equals(messageName)) {
                        fireReceivedProtocolError(new ProtocolError(fcpMessage));
                } else if ("PersistentPut".equals(messageName)) {
                        fireReceivedPersistentPut(new PersistentPut(fcpMessage));
index 61c1292..c090602 100644 (file)
@@ -181,6 +181,16 @@ public interface FcpListener extends EventListener {
        public void receivedAllData(FcpConnection fcpConnection, AllData allData);
 
        /**
+        * Notifies a listener that a “SimpleProgress” was received.
+        * 
+        * @param fcpConnection
+        *            The connection that received the event
+        * @param simpleProgress
+        *            The “Simple Progress” message
+        */
+       public void receivedSimpleProgress(FcpConnection fcpConnection, SimpleProgress simpleProgress);
+
+       /**
         * Notifies a listener that a “ProtocolError” was received.
         * 
         * @param fcpConnection
diff --git a/src/net/pterodactylus/util/fcp/SimpleProgress.java b/src/net/pterodactylus/util/fcp/SimpleProgress.java
new file mode 100644 (file)
index 0000000..caf8065
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * jSite2 - SimpleProgress.java -
+ * Copyright © 2008 David Roden
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package net.pterodactylus.util.fcp;
+
+/**
+ * A “SimpleProgress” message tells the client about the progress of a
+ * {@link ClientGet} or {@link ClientPut} operation.
+ * 
+ * @author David Roden &lt;droden@gmail.com&gt;
+ * @version $Id$
+ */
+public class SimpleProgress extends BaseMessage {
+
+       /**
+        * Creates a new “SimpleProgress” message that wraps the received message.
+        * 
+        * @param receivedMessage
+        *            The received message
+        */
+       public SimpleProgress(FcpMessage receivedMessage) {
+               super(receivedMessage);
+       }
+
+       /**
+        * Returns the total number of blocks. This number may increase as long as
+        * {@link #isFinalizedTotal()} returns <code>false</code>.
+        * 
+        * @return The total number of blocks
+        */
+       public int getTotal() {
+               try {
+                       return Integer.valueOf(getField("Total"));
+               } catch (NumberFormatException nfe1) {
+                       return -1;
+               }
+       }
+
+       /**
+        * Returns the number of blocks that are required to completet the request.
+        * This number might actually be lower than {@link #getTotal} because of
+        * redundancy information. This number may also increase as long as
+        * {@link #isFinalizedTotal()} returns <code>false</code>.
+        * 
+        * @return The number of required blocks
+        */
+       public int getRequired() {
+               try {
+                       return Integer.valueOf(getField("Required"));
+               } catch (NumberFormatException nfe1) {
+                       return -1;
+               }
+       }
+
+       /**
+        * Returns the number of blocks that have failed and run out of retries.
+        * 
+        * @return The number of failed blocks
+        */
+       public int getFailed() {
+               try {
+                       return Integer.valueOf(getField("Failed"));
+               } catch (NumberFormatException nfe1) {
+                       return -1;
+               }
+       }
+
+       /**
+        * Returns the number of fatally failed blocks. A block that failed fatally
+        * can never be completed, even with infinite retries.
+        * 
+        * @return The number of fatally failed blocks
+        */
+       public int getFatallyFailed() {
+               try {
+                       return Integer.valueOf(getField("FatallyFailed"));
+               } catch (NumberFormatException nfe1) {
+                       return -1;
+               }
+       }
+
+       /**
+        * Returns the number of blocks that have been successfully processed.
+        * 
+        * @return The number of succeeded blocks
+        */
+       public int getSucceeded() {
+               try {
+                       return Integer.valueOf(getField("Succeeded"));
+               } catch (NumberFormatException nfe1) {
+                       return -1;
+               }
+       }
+
+       /**
+        * Returns whether the total number of blocks (see {@link #getTotal()} has
+        * been finalized. Once the total number of blocks has been finalized for a
+        * request it will not change any more, and this method of every further
+        * SimpleProgress message will always return <code>true</code>.
+        * 
+        * @return <code>true</code> if the number of total blocks has been
+        *         finalized, <code>false</code> otherwise
+        */
+       public boolean isFinalizedTotal() {
+               return Boolean.valueOf(getField("FinalizedTotal"));
+       }
+
+       /**
+        * Returns the identifier of the request.
+        * 
+        * @return The identifier of the request
+        */
+       public String getIdentifier() {
+               return getField("Identifier");
+       }
+
+}