From: David ‘Bombe’ Roden Date: Fri, 11 Apr 2008 00:13:49 +0000 (+0000) Subject: add SimpleProgress X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=321147d4c7eeeccd114a83225ef15fe1d13efa27;p=jSite2.git add SimpleProgress git-svn-id: http://trooper/svn/projects/jSite/trunk@700 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/src/net/pterodactylus/util/fcp/FcpAdapter.java b/src/net/pterodactylus/util/fcp/FcpAdapter.java index 7111176..f0f4876 100644 --- a/src/net/pterodactylus/util/fcp/FcpAdapter.java +++ b/src/net/pterodactylus/util/fcp/FcpAdapter.java @@ -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) */ diff --git a/src/net/pterodactylus/util/fcp/FcpConnection.java b/src/net/pterodactylus/util/fcp/FcpConnection.java index 96f2ea0..815e45e 100644 --- a/src/net/pterodactylus/util/fcp/FcpConnection.java +++ b/src/net/pterodactylus/util/fcp/FcpConnection.java @@ -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)); diff --git a/src/net/pterodactylus/util/fcp/FcpListener.java b/src/net/pterodactylus/util/fcp/FcpListener.java index 61c1292..c090602 100644 --- a/src/net/pterodactylus/util/fcp/FcpListener.java +++ b/src/net/pterodactylus/util/fcp/FcpListener.java @@ -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 index 0000000..caf8065 --- /dev/null +++ b/src/net/pterodactylus/util/fcp/SimpleProgress.java @@ -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 <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 false. + * + * @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 false. + * + * @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 true. + * + * @return true if the number of total blocks has been + * finalized, false 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"); + } + +}