From f35aa413bce1d18c6f822719f7864ea6838cd043 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:18:42 +0100 Subject: [PATCH] =?utf8?q?Convert=20=E2=80=9CSone=20was=20inserted?= =?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/SoneInsertedEvent.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/SoneInsertedEvent.java diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index deac566..9cf0e99 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.SoneInsertedEvent; import net.pterodactylus.sone.core.event.SoneInsertingEvent; import net.pterodactylus.sone.core.event.SoneLockedEvent; import net.pterodactylus.sone.core.event.SoneRemovedEvent; @@ -2471,7 +2472,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis */ @Override public void insertFinished(Sone sone, long insertDuration) { - coreListenerManager.fireSoneInserted(sone, insertDuration); + eventBus.post(new SoneInsertedEvent(sone, insertDuration)); } /** diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListener.java b/src/main/java/net/pterodactylus/sone/core/CoreListener.java index 5f8df75..7b5c15c 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListener.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListener.java @@ -32,18 +32,6 @@ import net.pterodactylus.util.version.Version; public interface CoreListener extends EventListener { /** - * Notifies a listener that the insert of the given Sone has finished - * successfully. - * - * @see SoneInsertListener#insertFinished(Sone, long) - * @param sone - * The Sone that has been inserted - * @param insertDuration - * The insert duration (in milliseconds) - */ - public void soneInserted(Sone sone, long insertDuration); - - /** * Notifies a listener that the insert of the given Sone was aborted. * * @see SoneInsertListener#insertAborted(Sone, Throwable) diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java index e9c08ed..a4c3b78 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java @@ -44,22 +44,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} was inserted. + * + * @author David ‘Bombe’ Roden + */ +public class SoneInsertedEvent extends SoneEvent { + + /** The duration of the insert. */ + private final long insertDuration; + + /** + * Creates a new “Sone was inserted” event. + * + * @param sone + * The Sone that was inserted + * @param insertDuration + * The duration of the insert (in milliseconds) + */ + public SoneInsertedEvent(Sone sone, long insertDuration) { + super(sone); + this.insertDuration = insertDuration; + } + + // + // ACCESSORS + // + + /** + * Returns the duration of the insert. + * + * @return The duration of the insert (in milliseconds) + */ + public long insertDuration() { + return insertDuration; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 886383c..1c58bd3 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.SoneInsertedEvent; import net.pterodactylus.sone.core.event.SoneInsertingEvent; import net.pterodactylus.sone.core.event.SoneLockedEvent; import net.pterodactylus.sone.core.event.SoneRemovedEvent; @@ -988,23 +989,26 @@ public class WebInterface implements CoreListener { } } - // - // CORELISTENER METHODS - // - /** - * {@inheritDoc} + * Notifies the web interface that a {@link Sone} was inserted. + * + * @param soneInsertedEvent + * The event */ - @Override - public void soneInserted(Sone sone, long insertDuration) { - TemplateNotification soneInsertNotification = getSoneInsertNotification(sone); + @Subscribe + public void soneInserted(SoneInsertedEvent soneInsertedEvent) { + TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertedEvent.sone()); soneInsertNotification.set("soneStatus", "inserted"); - soneInsertNotification.set("insertDuration", insertDuration / 1000); - if (sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) { + soneInsertNotification.set("insertDuration", soneInsertedEvent.insertDuration() / 1000); + if (soneInsertedEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) { notificationManager.addNotification(soneInsertNotification); } } + // + // CORELISTENER METHODS + // + /** * {@inheritDoc} */ -- 2.7.4