/** 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.
*
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
//