import net.pterodactylus.fcp.highlevel.HighLevelCallback;
import net.pterodactylus.fcp.highlevel.HighLevelCallbackListener;
import net.pterodactylus.fcp.highlevel.HighLevelClient;
+import net.pterodactylus.fcp.highlevel.HighLevelProgress;
+import net.pterodactylus.fcp.highlevel.HighLevelProgressListener;
import net.pterodactylus.fcp.highlevel.RequestListResult;
import net.pterodactylus.fcp.highlevel.RequestResult;
import net.pterodactylus.util.logging.Logging;
* @author David ‘Bombe’ Roden <bombe@freenetproject.org>
* @version $Id$
*/
-public class RequestManager implements NodeListener {
+public class RequestManager implements NodeListener, HighLevelProgressListener {
/** Logger. */
private static final Logger logger = Logging.getLogger(RequestManager.class.getName());
}
}
+ /**
+ * Notifies all listeners that a request progressed.
+ *
+ * @param node
+ * The node that runs the request
+ * @param request
+ * 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 finalizedTotal
+ * <code>true</code> if the total number of blocks in final,
+ * <code>false</code> otherwise
+ */
+ private void fireRequestProgressed(Node node, Request request, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean finalizedTotal) {
+ for (RequestListener requestListener: requestListeners) {
+ requestListener.requestProgressed(node, request, totalBlocks, requiredBlocks, successfulBlocks, failedBlocks, fatallyFailedBlocks, finalizedTotal);
+ }
+ }
+
//
// ACCESSORS
//
* {@inheritDoc}
*/
public void nodeAdded(Node node) {
- /* ignore. */
+ HighLevelClient highLevelClient = nodeManager.borrowHighLevelClient(node);
+ if (highLevelClient == null) {
+ return;
+ }
+ try {
+ highLevelClient.addHighLevelProgressListener(this);
+ } finally {
+ nodeManager.returnHighLevelClient(highLevelClient);
+ }
}
/**
/* TODO - remove all requests. */
}
+ //
+ // INTERFACE HighLevelProgressListener
+ //
+
+ /**
+ * @see net.pterodactylus.fcp.highlevel.HighLevelProgressListener#progressReceived(java.lang.String,
+ * net.pterodactylus.fcp.highlevel.HighLevelProgress)
+ */
+ public void progressReceived(String identifier, HighLevelProgress highLevelProgress) {
+ fireRequestProgressed(null, new Request(identifier), highLevelProgress.getTotalBlocks(), highLevelProgress.getRequiredBlocks(), highLevelProgress.getSuccessfulBlocks(), highLevelProgress.getFailedBlocks(), highLevelProgress.getFatallyFailedBlocks(), highLevelProgress.isTotalFinalized());
+ }
+
}