From b3071020f22e1af7226809351a5dbea2a44ebc16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 16 Jan 2013 22:31:58 +0100 Subject: [PATCH] =?utf8?q?Convert=20=E2=80=9Cimage=20insert=20failed?= =?utf8?q?=E2=80=9D=20into=20EventBus-based=20event.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/core/Core.java | 3 +- .../sone/core/event/ImageInsertFailedEvent.java | 58 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 21 ++++---- 3 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.java diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index c40fd0f..ab27f67 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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 index 0000000..7800537 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/core/event/ImageInsertFailedEvent.java @@ -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 . + */ + +package net.pterodactylus.sone.core.event; + +import net.pterodactylus.sone.data.Image; + +/** + * Event that signals that an {@link Image} insert has failed. + * + * @author David ‘Bombe’ Roden + */ +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; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 9f0e8d9..0863fee 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -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 David ‘Bombe’ Roden */ -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); } -- 2.7.4