Convert “Sone is being inserted” into EventBus-based event.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 18:14:56 +0000 (19:14 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 18:14:56 +0000 (19:14 +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/SoneInsertingEvent.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java

index 07db844..deac566 100644 (file)
@@ -43,6 +43,7 @@ import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
 import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
 import net.pterodactylus.sone.core.event.PostRemovedEvent;
 import net.pterodactylus.sone.core.event.PostReplyRemovedEvent;
+import net.pterodactylus.sone.core.event.SoneInsertingEvent;
 import net.pterodactylus.sone.core.event.SoneLockedEvent;
 import net.pterodactylus.sone.core.event.SoneRemovedEvent;
 import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
@@ -2462,7 +2463,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
         */
        @Override
        public void insertStarted(Sone sone) {
-               coreListenerManager.fireSoneInserting(sone);
+               eventBus.post(new SoneInsertingEvent(sone));
        }
 
        /**
index aa6996f..5f8df75 100644 (file)
@@ -32,15 +32,6 @@ import net.pterodactylus.util.version.Version;
 public interface CoreListener extends EventListener {
 
        /**
-        * Notifies a listener that the insert of the given Sone has started.
-        *
-        * @see SoneInsertListener#insertStarted(Sone)
-        * @param sone
-        *            The Sone that is being inserted
-        */
-       public void soneInserting(Sone sone);
-
-       /**
         * Notifies a listener that the insert of the given Sone has finished
         * successfully.
         *
index d485b12..e9c08ed 100644 (file)
@@ -44,19 +44,6 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
        //
 
        /**
-        * Notifies all listeners that the insert of the given Sone has started.
-        *
-        * @see SoneInsertListener#insertStarted(Sone)
-        * @param sone
-        *            The Sone being inserted
-        */
-       void fireSoneInserting(Sone sone) {
-               for (CoreListener coreListener : getListeners()) {
-                       coreListener.soneInserting(sone);
-               }
-       }
-
-       /**
         * Notifies all listeners that the insert of the given Sone has finished
         * successfully.
         *
diff --git a/src/main/java/net/pterodactylus/sone/core/event/SoneInsertingEvent.java b/src/main/java/net/pterodactylus/sone/core/event/SoneInsertingEvent.java
new file mode 100644 (file)
index 0000000..37effe9
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Sone - SoneInsertingEvent.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 {@link Sone} is now being inserted.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class SoneInsertingEvent extends SoneEvent {
+
+       /**
+        * Creates a new “Sone is being inserted” event.
+        *
+        * @param sone
+        *            The Sone that is being inserted
+        */
+       public SoneInsertingEvent(Sone sone) {
+               super(sone);
+       }
+
+}
index 96b42b0..886383c 100644 (file)
@@ -45,6 +45,7 @@ import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
 import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
 import net.pterodactylus.sone.core.event.PostRemovedEvent;
 import net.pterodactylus.sone.core.event.PostReplyRemovedEvent;
+import net.pterodactylus.sone.core.event.SoneInsertingEvent;
 import net.pterodactylus.sone.core.event.SoneLockedEvent;
 import net.pterodactylus.sone.core.event.SoneRemovedEvent;
 import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
@@ -972,22 +973,25 @@ public class WebInterface implements CoreListener {
                Ticker.getInstance().deregisterEvent(lockedSonesTickerObjects.remove(soneUnlockedEvent.sone()));
        }
 
-       //
-       // CORELISTENER METHODS
-       //
-
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link Sone} is being inserted.
+        *
+        * @param soneInsertingEvent
+        *            The event
         */
-       @Override
-       public void soneInserting(Sone sone) {
-               TemplateNotification soneInsertNotification = getSoneInsertNotification(sone);
+       @Subscribe
+       public void soneInserting(SoneInsertingEvent soneInsertingEvent) {
+               TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertingEvent.sone());
                soneInsertNotification.set("soneStatus", "inserting");
-               if (sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
+               if (soneInsertingEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
                        notificationManager.addNotification(soneInsertNotification);
                }
        }
 
+       //
+       // CORELISTENER METHODS
+       //
+
        /**
         * {@inheritDoc}
         */