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

index 9cf0e99..b69c866 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.NewSoneFoundEvent;
 import net.pterodactylus.sone.core.event.PostRemovedEvent;
 import net.pterodactylus.sone.core.event.PostReplyRemovedEvent;
+import net.pterodactylus.sone.core.event.SoneInsertAbortedEvent;
 import net.pterodactylus.sone.core.event.SoneInsertedEvent;
 import net.pterodactylus.sone.core.event.SoneInsertingEvent;
 import net.pterodactylus.sone.core.event.SoneLockedEvent;
 import net.pterodactylus.sone.core.event.SoneInsertedEvent;
 import net.pterodactylus.sone.core.event.SoneInsertingEvent;
 import net.pterodactylus.sone.core.event.SoneLockedEvent;
@@ -2480,7 +2481,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
         */
        @Override
        public void insertAborted(Sone sone, Throwable cause) {
         */
        @Override
        public void insertAborted(Sone sone, Throwable cause) {
-               coreListenerManager.fireSoneInsertAborted(sone, cause);
+               eventBus.post(new SoneInsertAbortedEvent(sone, cause));
        }
 
        //
        }
 
        //
index 7b5c15c..80c31c2 100644 (file)
@@ -20,7 +20,6 @@ package net.pterodactylus.sone.core;
 import java.util.EventListener;
 
 import net.pterodactylus.sone.data.Image;
 import java.util.EventListener;
 
 import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.util.version.Version;
 
 /**
 import net.pterodactylus.util.version.Version;
 
 /**
@@ -32,17 +31,6 @@ import net.pterodactylus.util.version.Version;
 public interface CoreListener extends EventListener {
 
        /**
 public interface CoreListener extends EventListener {
 
        /**
-        * Notifies a listener that the insert of the given Sone was aborted.
-        *
-        * @see SoneInsertListener#insertAborted(Sone, Throwable)
-        * @param sone
-        *            The Sone that was inserted
-        * @param cause
-        *            The cause for the abortion (may be {@code null})
-        */
-       public void soneInsertAborted(Sone sone, Throwable cause);
-
-       /**
         * Notifies a listener that a new version has been found.
         *
         * @param version
         * Notifies a listener that a new version has been found.
         *
         * @param version
index a4c3b78..b8df010 100644 (file)
@@ -18,7 +18,6 @@
 package net.pterodactylus.sone.core;
 
 import net.pterodactylus.sone.data.Image;
 package net.pterodactylus.sone.core;
 
 import net.pterodactylus.sone.data.Image;
-import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.util.event.AbstractListenerManager;
 import net.pterodactylus.util.version.Version;
 
 import net.pterodactylus.util.event.AbstractListenerManager;
 import net.pterodactylus.util.version.Version;
 
@@ -44,21 +43,6 @@ public class CoreListenerManager extends AbstractListenerManager<Core, CoreListe
        //
 
        /**
        //
 
        /**
-        * Notifies all listeners that the insert of the given Sone was aborted.
-        *
-        * @see SoneInsertListener#insertStarted(Sone)
-        * @param sone
-        *            The Sone being inserted
-        * @param cause
-        *            The cause for the abortion (may be {@code null}
-        */
-       void fireSoneInsertAborted(Sone sone, Throwable cause) {
-               for (CoreListener coreListener : getListeners()) {
-                       coreListener.soneInsertAborted(sone, cause);
-               }
-       }
-
-       /**
         * Notifies all listeners that a new version was found.
         *
         * @see CoreListener#updateFound(Version, long, long)
         * Notifies all listeners that a new version was found.
         *
         * @see CoreListener#updateFound(Version, long, long)
diff --git a/src/main/java/net/pterodactylus/sone/core/event/SoneInsertAbortedEvent.java b/src/main/java/net/pterodactylus/sone/core/event/SoneInsertAbortedEvent.java
new file mode 100644 (file)
index 0000000..5884839
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Sone - SoneInsertAbortedEvent.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} insert was aborted.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class SoneInsertAbortedEvent extends SoneEvent {
+
+       /** The cause of the abortion. */
+       private final Throwable cause;
+
+       /**
+        * Creates a new “Sone was inserted” event.
+        *
+        * @param sone
+        *            The Sone that was inserted
+        * @param cause
+        *            The cause of the abortion
+        */
+       public SoneInsertAbortedEvent(Sone sone, Throwable cause) {
+               super(sone);
+               this.cause = cause;
+       }
+
+       //
+       // ACCESSORS
+       //
+
+       /**
+        * Returns the cause of the abortion.
+        *
+        * @return The cause of the abortion (may be {@code null})
+        */
+       public Throwable cause() {
+               return cause;
+       }
+
+}
index 1c58bd3..7c16c09 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.NewSoneFoundEvent;
 import net.pterodactylus.sone.core.event.PostRemovedEvent;
 import net.pterodactylus.sone.core.event.PostReplyRemovedEvent;
+import net.pterodactylus.sone.core.event.SoneInsertAbortedEvent;
 import net.pterodactylus.sone.core.event.SoneInsertedEvent;
 import net.pterodactylus.sone.core.event.SoneInsertingEvent;
 import net.pterodactylus.sone.core.event.SoneLockedEvent;
 import net.pterodactylus.sone.core.event.SoneInsertedEvent;
 import net.pterodactylus.sone.core.event.SoneInsertingEvent;
 import net.pterodactylus.sone.core.event.SoneLockedEvent;
@@ -1005,23 +1006,26 @@ public class WebInterface implements CoreListener {
                }
        }
 
                }
        }
 
-       //
-       // CORELISTENER METHODS
-       //
-
        /**
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that a {@link Sone} insert was aborted.
+        *
+        * @param soneInsertAbortedEvent
+        *            The event
         */
         */
-       @Override
-       public void soneInsertAborted(Sone sone, Throwable cause) {
-               TemplateNotification soneInsertNotification = getSoneInsertNotification(sone);
+       @Subscribe
+       public void soneInsertAborted(SoneInsertAbortedEvent soneInsertAbortedEvent) {
+               TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertAbortedEvent.sone());
                soneInsertNotification.set("soneStatus", "insert-aborted");
                soneInsertNotification.set("soneStatus", "insert-aborted");
-               soneInsertNotification.set("insert-error", cause);
-               if (sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
+               soneInsertNotification.set("insert-error", soneInsertAbortedEvent.cause());
+               if (soneInsertAbortedEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
                        notificationManager.addNotification(soneInsertNotification);
                }
        }
 
                        notificationManager.addNotification(soneInsertNotification);
                }
        }
 
+       //
+       // CORELISTENER METHODS
+       //
+
        /**
         * {@inheritDoc}
         */
        /**
         * {@inheritDoc}
         */