From 8b6ea0e3f05c3b9f3041158f3bc54ed00828b207 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 16 Jan 2013 19:22:45 +0100 Subject: [PATCH] =?utf8?q?Convert=20=E2=80=9CSone=20insert=20was=20aborted?= =?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 +- .../net/pterodactylus/sone/core/CoreListener.java | 12 ----- .../sone/core/CoreListenerManager.java | 16 ------ .../sone/core/event/SoneInsertAbortedEvent.java | 58 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 24 +++++---- 5 files changed, 74 insertions(+), 39 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sone/core/event/SoneInsertAbortedEvent.java diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 9cf0e99..b69c866 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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.SoneInsertAbortedEvent; 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) { - coreListenerManager.fireSoneInsertAborted(sone, cause); + eventBus.post(new SoneInsertAbortedEvent(sone, cause)); } // diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListener.java b/src/main/java/net/pterodactylus/sone/core/CoreListener.java index 7b5c15c..80c31c2 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListener.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListener.java @@ -20,7 +20,6 @@ package net.pterodactylus.sone.core; import java.util.EventListener; import net.pterodactylus.sone.data.Image; -import net.pterodactylus.sone.data.Sone; import net.pterodactylus.util.version.Version; /** @@ -32,17 +31,6 @@ import net.pterodactylus.util.version.Version; 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 diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java index a4c3b78..b8df010 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java @@ -18,7 +18,6 @@ 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; @@ -44,21 +43,6 @@ public class CoreListenerManager extends AbstractListenerManager. + */ + +package net.pterodactylus.sone.core.event; + +import net.pterodactylus.sone.data.Sone; + +/** + * Event that signals that a {@link Sone} insert was aborted. + * + * @author David ‘Bombe’ Roden + */ +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; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 1c58bd3..7c16c09 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -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.SoneInsertAbortedEvent; 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("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); } } + // + // CORELISTENER METHODS + // + /** * {@inheritDoc} */ -- 2.7.4