X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Ffcp%2Fhighlevel%2FFcpClient.java;h=3012e0011c1fc9b262921c3190b6ba2e5162fc5f;hb=dd605aee444057a874fabf7fb0045b8448b0d1cd;hp=78a7c1f91c9b9b2707dfb367f89a8ecf84a96695;hpb=1b240fc2b238ac15b0e20e5b2828bb1fecbfa31a;p=jFCPlib.git diff --git a/src/net/pterodactylus/fcp/highlevel/FcpClient.java b/src/net/pterodactylus/fcp/highlevel/FcpClient.java index 78a7c1f..3012e00 100644 --- a/src/net/pterodactylus/fcp/highlevel/FcpClient.java +++ b/src/net/pterodactylus/fcp/highlevel/FcpClient.java @@ -1,6 +1,5 @@ /* - * jFCPlib - FcpClient.java - - * Copyright © 2009 David Roden + * jFCPlib - FcpClient.java - Copyright © 2009 David Roden * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -81,6 +80,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 +159,62 @@ 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) { + connected = false; + fcpClientListenerManager.fireFcpClientDisconnected(); + } + }); + } + + // + // LISTENER MANAGEMENT + // + + /** + * Adds an FCP listener to the underlying connection. + * + * @param fcpListener + * The FCP listener to add + */ + public void addFcpListener(FcpListener fcpListener) { + fcpConnection.addFcpListener(fcpListener); + } + + /** + * Removes an FCP listener from the underlying connection. + * + * @param fcpListener + * The FCP listener to remove + */ + public void removeFcpListener(FcpListener fcpListener) { + fcpConnection.removeFcpListener(fcpListener); + } + + /** + * 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); } //