From c66c2899de040c50abc2c8638ca242fe0bc1af1b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 15 Jan 2010 12:25:40 +0100 Subject: [PATCH] Allow detaching the client from its connection. --- .../java/net/pterodactylus/fcp/highlevel/FcpClient.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java b/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java index b738e26..78cb198 100644 --- a/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java +++ b/src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java @@ -92,6 +92,9 @@ public class FcpClient { /** Whether the client is currently connected. */ private volatile boolean connected; + /** The listener for “connection closed” events. */ + private FcpListener connectionClosedListener; + /** * Creates an FCP client with the given name. * @@ -173,7 +176,7 @@ public class FcpClient { public FcpClient(FcpConnection fcpConnection, boolean connected) { this.fcpConnection = fcpConnection; this.connected = connected; - fcpConnection.addFcpListener(new FcpAdapter() { + connectionClosedListener = new FcpAdapter() { /** * {@inheritDoc} @@ -184,7 +187,8 @@ public class FcpClient { FcpClient.this.connected = false; fcpClientListenerManager.fireFcpClientDisconnected(); } - }); + }; + fcpConnection.addFcpListener(connectionClosedListener); } // @@ -318,6 +322,13 @@ public class FcpClient { return connected; } + /** + * Detaches this client from its underlying FCP connection. + */ + public void detach() { + fcpConnection.removeFcpListener(connectionClosedListener); + } + // // PEER MANAGEMENT // -- 2.7.4