Add removePeer() method.
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 19 Mar 2009 20:45:33 +0000 (21:45 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 19 Mar 2009 22:09:10 +0000 (23:09 +0100)
src/net/pterodactylus/fcp/highlevel/FcpClient.java

index 7694485..78a5064 100644 (file)
@@ -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.
         *