From b9e631fc3d6577df59d1660dfa37502e0e08de29 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 19 Mar 2009 21:45:33 +0100 Subject: [PATCH] Add removePeer() method. --- src/net/pterodactylus/fcp/highlevel/FcpClient.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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. * -- 2.7.4