Recognized “SubscribedUSK” event
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / FcpListenerManager.java
index 4e1cce6..a25f3bf 100644 (file)
 
 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.
@@ -34,7 +38,23 @@ public class FcpListenerManager extends AbstractListenerManager<FcpConnection, F
         *            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;
        }
 
        /**
@@ -109,6 +129,7 @@ public class FcpListenerManager extends AbstractListenerManager<FcpConnection, F
         *
         * @see FcpListener#receivedPeerNote(FcpConnection, PeerNote)
         * @param peerNote
+        *            The “PeerNote” message
         */
        public void fireReceivedPeerNote(PeerNote peerNote) {
                for (FcpListener fcpListener : getListeners()) {
@@ -290,7 +311,8 @@ public class FcpListenerManager extends AbstractListenerManager<FcpConnection, F
        }
 
        /**
-        * Notifies all listeners that a “FinishedCompression” message was received.
+        * Notifies all listeners that a “FinishedCompression” message was
+        * received.
         *
         * @see FcpListener#receivedFinishedCompression(FcpConnection,
         *      FinishedCompression)
@@ -416,8 +438,15 @@ public class FcpListenerManager extends AbstractListenerManager<FcpConnection, F
                }
        }
 
+       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)
@@ -443,6 +472,12 @@ public class FcpListenerManager extends AbstractListenerManager<FcpConnection, F
                }
        }
 
+       public void fireReceivedPluginRemoved(PluginRemoved pluginRemoved) {
+               for (FcpListener fcpListener : getListeners()) {
+                       fcpListener.receivedPluginRemoved(getSource(), pluginRemoved);
+               }
+       }
+
        /**
         * Notifies all listeners that an “FCPPluginReply” message was received.
         *
@@ -555,8 +590,8 @@ public class FcpListenerManager extends AbstractListenerManager<FcpConnection, F
         * 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) {