/** The listener for the connection. */
private HighLevelClientFcpListener highLevelClientFcpListener = new HighLevelClientFcpListener();
+ /** The listeners for progress events. */
+ private List<HighLevelProgressListener> highLevelProgressListeners = Collections.synchronizedList(new ArrayList<HighLevelProgressListener>());
+
/** The callback for {@link #connect()}. */
private HighLevelCallback<ConnectResult> connectCallback;
}
}
+ /**
+ * Adds a high-level progress listener.
+ *
+ * @param highLevelProgressListener
+ * The high-level progress listener to add
+ */
+ public void addHighLevelProgressListener(HighLevelProgressListener highLevelProgressListener) {
+ highLevelProgressListeners.add(highLevelProgressListener);
+ }
+
+ /**
+ * Removes a high-level progress listener.
+ *
+ * @param highLevelProgressListener
+ * The high-level progress listener to remove
+ */
+ public void removeHighLevelProgressListener(HighLevelProgressListener highLevelProgressListener) {
+ highLevelProgressListeners.remove(highLevelProgressListener);
+ }
+
+ /**
+ * Notifies all listeners that the request with the given identifier made
+ * some progress.
+ *
+ * @param identifier
+ * The identifier of the request
+ * @param highLevelProgress
+ * The progress of the request
+ */
+ private void fireProgressReceived(String identifier, HighLevelProgress highLevelProgress) {
+ for (HighLevelProgressListener highLevelProgressListener: highLevelProgressListeners) {
+ highLevelProgressListener.progressReceived(identifier, highLevelProgress);
+ }
+ }
+
//
// ACCESSORS
//
downloadCallback.progressUpdated();
return;
}
- /* unknown identifier? */
- logger.warning("unknown identifier for SimpleProgress: " + identifier);
+ HighLevelProgress highLevelProgress = new HighLevelProgress(identifier, simpleProgress.getTotal(), simpleProgress.getRequired(), simpleProgress.getSucceeded(), simpleProgress.getFailed(), simpleProgress.getFatallyFailed(), simpleProgress.isFinalizedTotal());
+ fireProgressReceived(identifier, highLevelProgress);
}
/**
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
-public abstract class HighLevelProgress extends HighLevelResult {
+public class HighLevelProgress extends HighLevelResult {
/** The number of total blocks. */
private int totalBlocks;
}
/**
+ * Creates a new high-level progress with the given values.
+ *
+ * @param identifier
+ * The identifier of the request
+ * @param totalBlocks
+ * The total number of blocks
+ * @param requiredBlocks
+ * The number of required blocks
+ * @param successfulBlocks
+ * The number of successful blocks
+ * @param failedBlocks
+ * The number of failed blocks
+ * @param fatallyFailedBlocks
+ * The number of fatally failed blocks
+ * @param totalFinalized
+ * <code>true</code> if the total number of blocks is
+ * finalized, <code>false</code> otherwise
+ */
+ public HighLevelProgress(String identifier, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean totalFinalized) {
+ this(identifier);
+ this.totalBlocks = totalBlocks;
+ this.requiredBlocks = requiredBlocks;
+ this.successfulBlocks = successfulBlocks;
+ this.failedBlocks = failedBlocks;
+ this.fatallyFailedBlocks = fatallyFailedBlocks;
+ this.totalFinalized = totalFinalized;
+ }
+
+ /**
* Returns the number of total blocks.
*
* @return The number of total blocks
--- /dev/null
+/*
+ * jFCPlib-high-level-client - HighLevelProgressListener.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.fcp.highlevel;
+
+import java.util.EventListener;
+
+/**
+ * Interface for objects that want to observe the progression of requests.
+ *
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
+ * @version $Id$
+ */
+public interface HighLevelProgressListener extends EventListener {
+
+ /**
+ * Notifies a listener that the request with the given identifier has made
+ * some progress.
+ *
+ * @param identifier
+ * The identifier of the request
+ * @param highLevelProgress
+ * The progress of the request
+ */
+ public void progressReceived(String identifier, HighLevelProgress highLevelProgress);
+
+}