X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fnet%2Fpterodactylus%2Ffcp%2Fhighlevel%2FHighLevelClient.java;h=e62c4286b9a5a38ea9f68965306a816225e8bb88;hb=fe63c7b7081dec41b85df862cb8358fcfbeb452e;hp=d139ce2ee95f6a8b8e29c8ddf06f8f69dfa2ddd8;hpb=17c6a031550816e0976f0c61ca5854092357e73c;p=jFCPlib.git diff --git a/src/net/pterodactylus/fcp/highlevel/HighLevelClient.java b/src/net/pterodactylus/fcp/highlevel/HighLevelClient.java index d139ce2..e62c428 100644 --- a/src/net/pterodactylus/fcp/highlevel/HighLevelClient.java +++ b/src/net/pterodactylus/fcp/highlevel/HighLevelClient.java @@ -85,6 +85,7 @@ import net.pterodactylus.fcp.TestDDAResponse; import net.pterodactylus.fcp.URIGenerated; import net.pterodactylus.fcp.UnknownNodeIdentifier; import net.pterodactylus.fcp.UnknownPeerNoteType; +import net.pterodactylus.fcp.WatchGlobal; /** * A high-level client that allows simple yet full-featured access to a Freenet @@ -119,6 +120,9 @@ public class HighLevelClient { /** The listener for the connection. */ private HighLevelClientFcpListener highLevelClientFcpListener = new HighLevelClientFcpListener(); + /** The listeners for progress events. */ + private List highLevelProgressListeners = Collections.synchronizedList(new ArrayList()); + /** The callback for {@link #connect()}. */ private HighLevelCallback connectCallback; @@ -248,6 +252,41 @@ public class HighLevelClient { } } + /** + * 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 // @@ -308,6 +347,21 @@ public class HighLevelClient { } /** + * Sets whether to watch the global queue. + * + * @param enabled + * true to watch the global queue in addition to + * the client-local queue, false to only watch the + * client-local queue + * @throws IOException + * if an I/O error occurs communicating with the node + */ + public void setWatchGlobal(boolean enabled) throws IOException { + WatchGlobal watchGlobal = new WatchGlobal(enabled); + fcpConnection.sendMessage(watchGlobal); + } + + /** * Gets a list of all peers from the node. * * @return A callback with the peer list @@ -471,7 +525,9 @@ public class HighLevelClient { * if there was no exception */ private void disconnect(Throwable throwable) { - fcpConnection.close(); + if (fcpConnection != null) { + fcpConnection.close(); + } fireClientDisconnected(throwable); } @@ -1019,8 +1075,8 @@ public class HighLevelClient { 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); } /**