From: David ‘Bombe’ Roden Date: Thu, 19 Mar 2009 20:45:33 +0000 (+0100) Subject: Add removePeer() method. X-Git-Tag: v0.1.1~84 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b9e631fc3d6577df59d1660dfa37502e0e08de29;p=jFCPlib.git Add removePeer() method. --- diff --git a/src/net/pterodactylus/fcp/highlevel/FcpClient.java b/src/net/pterodactylus/fcp/highlevel/FcpClient.java index 7694485..78a5064 100644 --- a/src/net/pterodactylus/fcp/highlevel/FcpClient.java +++ b/src/net/pterodactylus/fcp/highlevel/FcpClient.java @@ -39,7 +39,9 @@ import net.pterodactylus.fcp.ModifyPeer; import net.pterodactylus.fcp.NodeHello; import net.pterodactylus.fcp.NodeRef; import net.pterodactylus.fcp.Peer; +import net.pterodactylus.fcp.PeerRemoved; import net.pterodactylus.fcp.ProtocolError; +import net.pterodactylus.fcp.RemovePeer; /** * High-level FCP client that hides the details of the underlying FCP @@ -359,6 +361,39 @@ public class FcpClient { } /** + * Removes the given peer. + * + * @param peer + * The peer to remove + * @throws IOException + * if an I/O error occurs + * @throws FcpException + * if an FCP error occurs + */ + public void removePeer(final Peer peer) throws IOException, FcpException { + ExtendedFcpAdapter fcpListener = new ExtendedFcpAdapter() { + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("synthetic-access") + public void run() throws IOException { + fcpConnection.sendMessage(new RemovePeer(peer.getIdentity())); + } + + /** + * {@inheritDoc} + */ + @Override + public void receivedPeerRemoved(FcpConnection fcpConnection, PeerRemoved peerRemoved) { + completionLatch.countDown(); + } + }; + fcpListener.execute(); + } + + /** * Implementation of an {@link FcpListener} that can store an * {@link FcpException} and wait for the arrival of a certain command. *