/*
- * jFCPlib - FcpListenerManager.java - Copyright © 2009 David Roden
+ * jFCPlib - FcpListenerManager.java - Copyright © 2009–2016 David Roden
*
- * This program is free software; you can redistribute it and/or modify
+ * 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
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.pterodactylus.fcp;
-import net.pterodactylus.util.event.AbstractListenerManager;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
/**
* Manages FCP listeners and event firing.
*
* @author David ‘Bombe’ Roden <bombe@pterodactylus.net>
*/
-public class FcpListenerManager extends AbstractListenerManager<FcpConnection, FcpListener> {
+public class FcpListenerManager {
+
+ private final FcpConnection source;
+ private final List<FcpListener> listeners = new CopyOnWriteArrayList<FcpListener>();
/**
* Creates a new listener manager.
* The source FCP connection
*/
public FcpListenerManager(FcpConnection fcpConnection) {
- super(fcpConnection);
+ this.source = fcpConnection;
+ }
+
+ public void addListener(FcpListener fcpListener) {
+ listeners.add(fcpListener);
+ }
+
+ public void removeListener(FcpListener fcpListener) {
+ listeners.remove(fcpListener);
+ }
+
+ private FcpConnection getSource() {
+ return source;
+ }
+
+ private List<FcpListener> getListeners() {
+ return listeners;
}
/**
*
* @see FcpListener#receivedPeerNote(FcpConnection, PeerNote)
* @param peerNote
+ * The “PeerNote” message
*/
public void fireReceivedPeerNote(PeerNote peerNote) {
for (FcpListener fcpListener : getListeners()) {
}
/**
- * Notifies all listeners that a “FinishedCompression” message was received.
+ * Notifies all listeners that a “FinishedCompression” message was
+ * received.
*
* @see FcpListener#receivedFinishedCompression(FcpConnection,
* FinishedCompression)
}
}
+ public void fireReceivedSubscribedUSK(SubscribedUSK subscribedUSK) {
+ for (FcpListener fcpListener : getListeners()) {
+ fcpListener.receivedSubscribedUSK(getSource(), subscribedUSK);
+ }
+ }
+
/**
- * Notifies all listeners that a “SubscribedUSKUpdate” message was received.
+ * Notifies all listeners that a “SubscribedUSKUpdate” message was
+ * received.
*
* @see FcpListener#receivedSubscribedUSKUpdate(FcpConnection,
* SubscribedUSKUpdate)
}
}
+ public void fireReceivedPluginRemoved(PluginRemoved pluginRemoved) {
+ for (FcpListener fcpListener : getListeners()) {
+ fcpListener.receivedPluginRemoved(getSource(), pluginRemoved);
+ }
+ }
+
/**
* Notifies all listeners that an “FCPPluginReply” message was received.
*
* Notifies all listeners that the connection to the node was closed.
*
* @param throwable
- * The exception that caused the disconnect, or <code>null</code>
- * if there was no exception
+ * The exception that caused the disconnect, or
+ * <code>null</code> if there was no exception
* @see FcpListener#connectionClosed(FcpConnection, Throwable)
*/
public void fireConnectionClosed(Throwable throwable) {