From 9e9841452e9d17fe0b104b20e64bfe97cea6a302 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:27:47 +0100 Subject: [PATCH] =?utf8?q?Convert=20=E2=80=9Cupdate=20found=E2=80=9D=20int?= =?utf8?q?o=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 | 13 ---- .../sone/core/CoreListenerManager.java | 18 ----- .../sone/core/event/UpdateFoundEvent.java | 86 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 25 ++++--- 5 files changed, 102 insertions(+), 43 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sone/core/event/UpdateFoundEvent.java diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index b69c866..8318d03 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -49,6 +49,7 @@ import net.pterodactylus.sone.core.event.SoneInsertingEvent; import net.pterodactylus.sone.core.event.SoneLockedEvent; import net.pterodactylus.sone.core.event.SoneRemovedEvent; import net.pterodactylus.sone.core.event.SoneUnlockedEvent; +import net.pterodactylus.sone.core.event.UpdateFoundEvent; import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Client; import net.pterodactylus.sone.data.Image; @@ -2453,7 +2454,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis */ @Override public void updateFound(Version version, long releaseTime, long latestEdition) { - coreListenerManager.fireUpdateFound(version, releaseTime, latestEdition); + eventBus.post(new UpdateFoundEvent(version, releaseTime, latestEdition)); } // diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListener.java b/src/main/java/net/pterodactylus/sone/core/CoreListener.java index 80c31c2..f644f50 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.util.version.Version; /** * Listener interface for objects that want to be notified on certain @@ -31,18 +30,6 @@ import net.pterodactylus.util.version.Version; public interface CoreListener extends EventListener { /** - * Notifies a listener that a new version has been found. - * - * @param version - * The version that was found - * @param releaseTime - * The release time of the new version - * @param latestEdition - * The latest edition of the Sone homepage - */ - public void updateFound(Version version, long releaseTime, long latestEdition); - - /** * Notifies a listener that an image has started being inserted. * * @param image diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java index b8df010..bb93fd7 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java @@ -19,7 +19,6 @@ package net.pterodactylus.sone.core; import net.pterodactylus.sone.data.Image; import net.pterodactylus.util.event.AbstractListenerManager; -import net.pterodactylus.util.version.Version; /** * Manager for {@link CoreListener}s. @@ -43,23 +42,6 @@ public class CoreListenerManager extends AbstractListenerManager. + */ + +package net.pterodactylus.sone.core.event; + +import net.pterodactylus.util.version.Version; + +/** + * Event that signals that an update for Sone was found. + * + * @author David ‘Bombe’ Roden + */ +public class UpdateFoundEvent { + + /** The version that was found. */ + private final Version version; + + /** The time the update was released. */ + private final long releaseTime; + + /** The latest edition of the update page. */ + private final long latestEdition; + + /** + * Creates a new “update found” event. + * + * @param version + * The version of the update + * @param releaseTime + * The release time of the update + * @param latestEdition + * The latest edition of the update page + */ + public UpdateFoundEvent(Version version, long releaseTime, long latestEdition) { + this.version = version; + this.releaseTime = releaseTime; + this.latestEdition = latestEdition; + } + + // + // ACCESSORS + // + + /** + * Returns the version of the update. + * + * @return The version of the update + */ + public Version version() { + return version; + } + + /** + * Returns the release time of the update. + * + * @return The releae time of the update (in milliseconds since Jan 1, 1970 + * UTC) + */ + public long releaseTime() { + return releaseTime; + } + + /** + * Returns the latest edition of the update page. + * + * @return The latest edition of the update page + */ + public long latestEdition() { + return latestEdition; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 7c16c09..dc4c4f0 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -51,6 +51,7 @@ import net.pterodactylus.sone.core.event.SoneInsertingEvent; import net.pterodactylus.sone.core.event.SoneLockedEvent; import net.pterodactylus.sone.core.event.SoneRemovedEvent; import net.pterodactylus.sone.core.event.SoneUnlockedEvent; +import net.pterodactylus.sone.core.event.UpdateFoundEvent; import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Image; import net.pterodactylus.sone.data.Post; @@ -139,7 +140,6 @@ import net.pterodactylus.util.template.TemplateParser; import net.pterodactylus.util.template.TemplateProvider; import net.pterodactylus.util.template.XmlFilter; import net.pterodactylus.util.thread.Ticker; -import net.pterodactylus.util.version.Version; import net.pterodactylus.util.web.RedirectPage; import net.pterodactylus.util.web.StaticPage; import net.pterodactylus.util.web.TemplatePage; @@ -1022,21 +1022,24 @@ public class WebInterface implements CoreListener { } } - // - // CORELISTENER METHODS - // - /** - * {@inheritDoc} + * Notifies the web interface that a new Sone version was found. + * + * @param updateFoundEvent + * The event */ - @Override - public void updateFound(Version version, long releaseTime, long latestEdition) { - newVersionNotification.getTemplateContext().set("latestVersion", version); - newVersionNotification.getTemplateContext().set("latestEdition", latestEdition); - newVersionNotification.getTemplateContext().set("releaseTime", releaseTime); + @Subscribe + public void updateFound(UpdateFoundEvent updateFoundEvent) { + newVersionNotification.getTemplateContext().set("latestVersion", updateFoundEvent.version()); + newVersionNotification.getTemplateContext().set("latestEdition", updateFoundEvent.latestEdition()); + newVersionNotification.getTemplateContext().set("releaseTime", updateFoundEvent.releaseTime()); notificationManager.addNotification(newVersionNotification); } + // + // CORELISTENER METHODS + // + /** * {@inheritDoc} */ -- 2.7.4