From ff012b8b8f162b1d2f9f471455f43545d63f7d4a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 20 Jul 2009 07:57:40 +0200 Subject: [PATCH] Implement firing of fcp-client-disconnected event. --- src/net/pterodactylus/fcp/highlevel/FcpClient.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/net/pterodactylus/fcp/highlevel/FcpClient.java b/src/net/pterodactylus/fcp/highlevel/FcpClient.java index 78a7c1f..f2a80a1 100644 --- a/src/net/pterodactylus/fcp/highlevel/FcpClient.java +++ b/src/net/pterodactylus/fcp/highlevel/FcpClient.java @@ -81,6 +81,9 @@ public class FcpClient { /** Object used for synchronization. */ private final Object syncObject = new Object(); + /** Listener management. */ + private final FcpClientListenerManager fcpClientListenerManager = new FcpClientListenerManager(this); + /** The name of this client. */ private final String name; @@ -157,6 +160,41 @@ public class FcpClient { public FcpClient(String name, InetAddress host, int port) { this.name = name; fcpConnection = new FcpConnection(host, port); + fcpConnection.addFcpListener(new FcpAdapter() { + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("synthetic-access") + public void connectionClosed(FcpConnection fcpConnection, Throwable throwable) { + fcpClientListenerManager.fireFcpClientDisconnected(); + } + }); + } + + // + // LISTENER MANAGEMENT + // + + /** + * Adds an FCP client listener to the list of registered listeners. + * + * @param fcpClientListener + * The FCP client listener to add + */ + public void addFcpClientListener(FcpClientListener fcpClientListener) { + fcpClientListenerManager.addListener(fcpClientListener); + } + + /** + * Removes an FCP client listener from the list of registered listeners. + * + * @param fcpClientListener + * The FCP client listener to remove + */ + public void removeFcpClientListener(FcpClientListener fcpClientListener) { + fcpClientListenerManager.removeListener(fcpClientListener); } // -- 2.7.4