X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Ffcp%2Fhighlevel%2FFcpClient.java;h=f2a80a16470c6cd6e82acc4fd764952866cd1fbc;hb=ff012b8b8f162b1d2f9f471455f43545d63f7d4a;hp=4bbcded65930c87f23b33b7a1f03e7d54d29b9af;hpb=37dac9ebe3384ef47140e25bd17d32c41e0d1056;p=jFCPlib.git diff --git a/src/net/pterodactylus/fcp/highlevel/FcpClient.java b/src/net/pterodactylus/fcp/highlevel/FcpClient.java index 4bbcded..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); } // @@ -923,6 +961,7 @@ public class FcpClient { @Override public void receivedNodeData(FcpConnection fcpConnection, NodeData nodeData) { nodeDataWrapper.set(nodeData); + completionLatch.countDown(); } }.execute(); return nodeDataWrapper.get();