Convert “image insert failed” into EventBus-based event.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 21:31:58 +0000 (22:31 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 16 Jan 2013 21:31:58 +0000 (22:31 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java

index c40fd0f..ab27f67 100644 (file)
@@ -36,6 +36,7 @@ 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.ImageInsertAbortedEvent;
+import net.pterodactylus.sone.core.event.ImageInsertFailedEvent;
 import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent;
 import net.pterodactylus.sone.core.event.ImageInsertStartedEvent;
 import net.pterodactylus.sone.core.event.MarkPostKnownEvent;
@@ -2528,7 +2529,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
        @Override
        public void imageInsertFailed(Image image, Throwable cause) {
                logger.log(Level.WARNING, String.format("Image insert failed for %s." + image), cause);
-               coreListenerManager.fireImageInsertFailed(image, cause);
+               eventBus.post(new ImageInsertFailedEvent(image, cause));
        }
 
        /**
diff --git a/src/main/java/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.java b/src/main/java/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.java
new file mode 100644 (file)
index 0000000..7800537
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Sone - ImageInsertFailedEvent.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.Image;
+
+/**
+ * Event that signals that an {@link Image} insert has failed.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ImageInsertFailedEvent extends ImageEvent {
+
+       /** The cause of the insert failure. */
+       private final Throwable cause;
+
+       /**
+        * Creates a new “image insert failed” event.
+        *
+        * @param image
+        *            The image whose insert failed
+        * @param cause
+        *            The cause of the insert failure
+        */
+       public ImageInsertFailedEvent(Image image, Throwable cause) {
+               super(image);
+               this.cause = cause;
+       }
+
+       //
+       // ACCESSORS
+       //
+
+       /**
+        * Returns the cause of the insert failure.
+        *
+        * @return The cause of the insert failure
+        */
+       public Throwable cause() {
+               return cause;
+       }
+
+}
index 9f0e8d9..0863fee 100644 (file)
@@ -36,8 +36,8 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import net.pterodactylus.sone.core.Core;
-import net.pterodactylus.sone.core.CoreListener;
 import net.pterodactylus.sone.core.event.ImageInsertAbortedEvent;
+import net.pterodactylus.sone.core.event.ImageInsertFailedEvent;
 import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent;
 import net.pterodactylus.sone.core.event.ImageInsertStartedEvent;
 import net.pterodactylus.sone.core.event.MarkPostKnownEvent;
@@ -165,7 +165,7 @@ import freenet.support.api.HTTPRequest;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class WebInterface implements CoreListener {
+public class WebInterface {
 
        /** The logger. */
        private static final Logger logger = Logging.getLogger(WebInterface.class);
@@ -1075,17 +1075,16 @@ public class WebInterface implements CoreListener {
                notificationManager.addNotification(insertedImagesNotification);
        }
 
-       //
-       // CORELISTENER METHODS
-       //
-
        /**
-        * {@inheritDoc}
+        * Notifies the web interface that an {@link Image} insert has failed.
+        *
+        * @param imageInsertFailedEvent
+        *            The event
         */
-       @Override
-       public void imageInsertFailed(Image image, Throwable cause) {
-               insertingImagesNotification.remove(image);
-               imageInsertFailedNotification.add(image);
+       @Subscribe
+       public void imageInsertFailed(ImageInsertFailedEvent imageInsertFailedEvent) {
+               insertingImagesNotification.remove(imageInsertFailedEvent.image());
+               imageInsertFailedNotification.add(imageInsertFailedEvent.image());
                notificationManager.addNotification(imageInsertFailedNotification);
        }