Convert “new Sound found” into EventBus-based event.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 14:27:57 +0000 (15:27 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 18:04:11 +0000 (19:04 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/CoreListener.java
src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java
src/main/java/net/pterodactylus/sone/core/event/NewSoneFoundEvent.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java

index b21a087..629c2d5 100644 (file)
@@ -35,6 +35,7 @@ import java.util.logging.Logger;
 import net.pterodactylus.sone.core.Options.DefaultOption;
 import net.pterodactylus.sone.core.Options.Option;
 import net.pterodactylus.sone.core.Options.OptionWatcher;
 import net.pterodactylus.sone.core.Options.DefaultOption;
 import net.pterodactylus.sone.core.Options.Option;
 import net.pterodactylus.sone.core.Options.OptionWatcher;
+import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Client;
 import net.pterodactylus.sone.data.Image;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Client;
 import net.pterodactylus.sone.data.Image;
@@ -892,7 +893,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                                }
                                sone.setKnown(!newSone);
                                if (newSone) {
                                }
                                sone.setKnown(!newSone);
                                if (newSone) {
-                                       coreListenerManager.fireNewSoneFound(sone);
+                                       eventBus.post(new NewSoneFoundEvent(sone));
                                        for (Sone localSone : getLocalSones()) {
                                                if (localSone.getOptions().getBooleanOption("AutoFollow").get()) {
                                                        followSone(localSone, sone);
                                        for (Sone localSone : getLocalSones()) {
                                                if (localSone.getOptions().getBooleanOption("AutoFollow").get()) {
                                                        followSone(localSone, sone);
index b56bff5..2edbef5 100644 (file)
@@ -34,14 +34,6 @@ import net.pterodactylus.util.version.Version;
 public interface CoreListener extends EventListener {
 
        /**
 public interface CoreListener extends EventListener {
 
        /**
-        * Notifies a listener that a new Sone has been discovered.
-        *
-        * @param sone
-        *            The new Sone
-        */
-       public void newSoneFound(Sone sone);
-
-       /**
         * Notifies a listener that a new post has been found.
         *
         * @param post
         * Notifies a listener that a new post has been found.
         *
         * @param post
index 0385698..52953f5 100644 (file)
@@ -46,19 +46,6 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
        //
 
        /**
        //
 
        /**
-        * Notifies all listeners that a new Sone has been discovered.
-        *
-        * @see CoreListener#newSoneFound(Sone)
-        * @param sone
-        *            The discovered sone
-        */
-       void fireNewSoneFound(Sone sone) {
-               for (CoreListener coreListener : getListeners()) {
-                       coreListener.newSoneFound(sone);
-               }
-       }
-
-       /**
         * Notifies all listeners that a new post has been found.
         *
         * @see CoreListener#newPostFound(Post)
         * Notifies all listeners that a new post has been found.
         *
         * @see CoreListener#newPostFound(Post)
diff --git a/src/main/java/net/pterodactylus/sone/core/event/NewSoneFoundEvent.java b/src/main/java/net/pterodactylus/sone/core/event/NewSoneFoundEvent.java
new file mode 100644 (file)
index 0000000..32c6b71
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Sone - NewSoneFoundEvent.java - Copyright © 2013 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
+ * 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,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.core.event;
+
+import net.pterodactylus.sone.data.Sone;
+
+/**
+ * Event that signals that a new remote Sone was found.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class NewSoneFoundEvent extends SoneEvent {
+
+       /**
+        * Creates a new “new Sone found” event.
+        *
+        * @param sone
+        *            The Sone that was found
+        */
+       public NewSoneFoundEvent(Sone sone) {
+               super(sone);
+       }
+
+}
index 188cc7f..98b2f46 100644 (file)
@@ -37,6 +37,7 @@ import java.util.logging.Logger;
 
 import net.pterodactylus.sone.core.Core;
 import net.pterodactylus.sone.core.CoreListener;
 
 import net.pterodactylus.sone.core.Core;
 import net.pterodactylus.sone.core.CoreListener;
+import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
 import net.pterodactylus.sone.data.Post;
@@ -132,6 +133,7 @@ import net.pterodactylus.util.web.TemplatePage;
 
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableSet;
 
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableSet;
+import com.google.common.eventbus.Subscribe;
 import com.google.inject.Inject;
 
 import freenet.clients.http.SessionManager;
 import com.google.inject.Inject;
 
 import freenet.clients.http.SessionManager;
@@ -774,20 +776,24 @@ public class WebInterface implements CoreListener {
        }
 
        //
        }
 
        //
-       // CORELISTENER METHODS
+       // EVENT HANDLERS
        //
 
        /**
         * {@inheritDoc}
         */
        //
 
        /**
         * {@inheritDoc}
         */
-       @Override
-       public void newSoneFound(Sone sone) {
-               newSoneNotification.add(sone);
+       @Subscribe
+       public void newSoneFound(NewSoneFoundEvent newSoneFoundEvent) {
+               newSoneNotification.add(newSoneFoundEvent.sone());
                if (!hasFirstStartNotification()) {
                        notificationManager.addNotification(newSoneNotification);
                }
        }
 
                if (!hasFirstStartNotification()) {
                        notificationManager.addNotification(newSoneNotification);
                }
        }
 
+       //
+       // CORELISTENER METHODS
+       //
+
        /**
         * {@inheritDoc}
         */
        /**
         * {@inheritDoc}
         */