}
/**
+ * 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
*/
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));
--- /dev/null
+/*
+ * 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 <droden@gmail.com>
+ * @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");
+ }
+
+}