Update license to GPLv3, fix header comments
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / FcpListenerManager.java
index 4f3b9dd..b9f0bc8 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * 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 &lt;bombe@pterodactylus.net&gt;
  */
-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 +37,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;
        }
 
        /**
@@ -418,6 +437,12 @@ 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.
@@ -446,6 +471,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.
         *