X-Git-Url: https://git.pterodactylus.net/?p=jFCPlib.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Ffcp%2Fhighlevel%2FFcpClient.java;h=78cb1984489fa86d27170783e365f62004132415;hp=b738e262ca8431c69246d4188e4a38d2ca4b9096;hb=c66c2899de040c50abc2c8638ca242fe0bc1af1b;hpb=ccd328332da86e58a98e991c3d4e31e56e906547 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 //