/** 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.
*
* The Freenet node’s FCP port
*/
public FcpClient(InetAddress host, int port) {
- this(new FcpConnection(host, port));
+ this(new FcpConnection(host, port), false);
}
/**
public FcpClient(FcpConnection fcpConnection, boolean connected) {
this.fcpConnection = fcpConnection;
this.connected = connected;
- fcpConnection.addFcpListener(new FcpAdapter() {
+ connectionClosedListener = new FcpAdapter() {
/**
* {@inheritDoc}
FcpClient.this.connected = false;
fcpClientListenerManager.fireFcpClientDisconnected();
}
- });
+ };
+ fcpConnection.addFcpListener(connectionClosedListener);
}
//
return connected;
}
+ /**
+ * Detaches this client from its underlying FCP connection.
+ */
+ public void detach() {
+ fcpConnection.removeFcpListener(connectionClosedListener);
+ }
+
//
// PEER MANAGEMENT
//