From 93895a33c778a8660c7f8ea09d2566a567c1890a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 1 Sep 2010 19:52:36 +0200 Subject: [PATCH] Hand down progress listener. --- src/de/todesbaum/util/freenet/fcp2/Client.java | 39 +++++++++++++++++++++- src/de/todesbaum/util/freenet/fcp2/Connection.java | 19 ++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/de/todesbaum/util/freenet/fcp2/Client.java b/src/de/todesbaum/util/freenet/fcp2/Client.java index 9376159..63fa418 100644 --- a/src/de/todesbaum/util/freenet/fcp2/Client.java +++ b/src/de/todesbaum/util/freenet/fcp2/Client.java @@ -23,6 +23,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import de.todesbaum.util.io.StreamCopier.ProgressListener; + /** * A Client executes {@link Command}s over a {@link Connection} to a * {@link Node} and delivers resulting {@link Message}s. @@ -113,6 +115,23 @@ public class Client implements ConnectionListener { } /** + * Executes the specified command. This will also clear the queue of + * messages, discarding all messages that resulted from the previous + * command and have not yet been read. + * + * @param command + * The command to execute + * @param progressListener + * The progress listener for payload transfers + * @throws IOException + * if an I/O error occurs + * @see #execute(Command, boolean) + */ + public void execute(Command command, ProgressListener progressListener) throws IOException { + execute(command, true, progressListener); + } + + /** * Executes the specified command and optionally clears the list of * identifiers this clients listens to before starting the command. * @@ -125,6 +144,24 @@ public class Client implements ConnectionListener { * if an I/O error occurs */ public void execute(Command command, boolean removeExistingIdentifiers) throws IOException { + execute(command, removeExistingIdentifiers, null); + } + + /** + * Executes the specified command and optionally clears the list of + * identifiers this clients listens to before starting the command. + * + * @param command + * The command to execute + * @param removeExistingIdentifiers + * If true, the list of identifiers that this + * clients listens to is cleared + * @param progressListener + * The progress listener for payload transfers + * @throws IOException + * if an I/O error occurs + */ + public void execute(Command command, boolean removeExistingIdentifiers, ProgressListener progressListener) throws IOException { synchronized (messageQueue) { messageQueue.clear(); if (removeExistingIdentifiers) { @@ -132,7 +169,7 @@ public class Client implements ConnectionListener { } identifiers.add(command.getIdentifier()); } - connection.execute(command); + connection.execute(command, progressListener); } /** diff --git a/src/de/todesbaum/util/freenet/fcp2/Connection.java b/src/de/todesbaum/util/freenet/fcp2/Connection.java index 3fd39f6..5ae344c 100644 --- a/src/de/todesbaum/util/freenet/fcp2/Connection.java +++ b/src/de/todesbaum/util/freenet/fcp2/Connection.java @@ -34,6 +34,7 @@ import java.util.List; import de.todesbaum.util.io.Closer; import de.todesbaum.util.io.LineInputStream; import de.todesbaum.util.io.StreamCopier; +import de.todesbaum.util.io.StreamCopier.ProgressListener; import de.todesbaum.util.io.TempFileInputStream; /** @@ -260,6 +261,22 @@ public class Connection { * if an I/O error occurs */ public synchronized void execute(Command command) throws IllegalStateException, IOException { + execute(command, null); + } + + /** + * Executes the specified command. + * + * @param command + * The command to execute + * @param progressListener + * A progress listener for a payload transfer + * @throws IllegalStateException + * if the connection is not connected + * @throws IOException + * if an I/O error occurs + */ + public synchronized void execute(Command command, ProgressListener progressListener) throws IllegalStateException, IOException { if (nodeSocket == null) { throw new IllegalStateException("connection is not connected"); } @@ -271,7 +288,7 @@ public class Connection { InputStream payloadInputStream = null; try { payloadInputStream = command.getPayload(); - StreamCopier.copy(payloadInputStream, nodeOutputStream, command.getPayloadLength()); + StreamCopier.copy(payloadInputStream, nodeOutputStream, command.getPayloadLength(), progressListener); } finally { Closer.close(payloadInputStream); } -- 2.7.4