Allow detaching the client from its connection.
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 15 Jan 2010 11:25:40 +0000 (12:25 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 15 Jan 2010 11:25:40 +0000 (12:25 +0100)
src/main/java/net/pterodactylus/fcp/highlevel/FcpClient.java

index b738e26..78cb198 100644 (file)
@@ -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
        //