From ba4c1d2a5995657d48dce310ea854fa1f164a481 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:10:27 +0100 Subject: [PATCH] =?utf8?q?Convert=20=E2=80=9CSone=20unlocked=E2=80=9D=20in?= =?utf8?q?to=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 | 8 ----- .../sone/core/CoreListenerManager.java | 13 ------- .../sone/core/event/SoneUnlockedEvent.java | 40 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 22 +++++++----- 5 files changed, 55 insertions(+), 31 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sone/core/event/SoneUnlockedEvent.java diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index ed8cc72..07db844 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -45,6 +45,7 @@ import net.pterodactylus.sone.core.event.PostRemovedEvent; import net.pterodactylus.sone.core.event.PostReplyRemovedEvent; 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.data.Album; import net.pterodactylus.sone.data.Client; import net.pterodactylus.sone.data.Image; @@ -814,7 +815,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis public void unlockSone(Sone sone) { synchronized (lockedSones) { if (lockedSones.remove(sone)) { - coreListenerManager.fireSoneUnlocked(sone); + eventBus.post(new SoneUnlockedEvent(sone)); } } } diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListener.java b/src/main/java/net/pterodactylus/sone/core/CoreListener.java index a826e64..aa6996f 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListener.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListener.java @@ -32,14 +32,6 @@ import net.pterodactylus.util.version.Version; public interface CoreListener extends EventListener { /** - * Notifies a listener that a Sone was unlocked. - * - * @param sone - * The Sone that was unlocked - */ - public void soneUnlocked(Sone sone); - - /** * Notifies a listener that the insert of the given Sone has started. * * @see SoneInsertListener#insertStarted(Sone) diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java index 44fb67b..d485b12 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java @@ -44,19 +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 unlocked. Only + * {@link Sone#isLocal() local Sones} can be locked. + * + * @author David ‘Bombe’ Roden + */ +public class SoneUnlockedEvent extends SoneEvent { + + /** + * Creates a new “Sone unlocked” event. + * + * @param sone + * The Sone that was unlocked + */ + public SoneUnlockedEvent(Sone sone) { + super(sone); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 9e5e0eb..96b42b0 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -47,6 +47,7 @@ import net.pterodactylus.sone.core.event.PostRemovedEvent; import net.pterodactylus.sone.core.event.PostReplyRemovedEvent; 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.data.Album; import net.pterodactylus.sone.data.Image; import net.pterodactylus.sone.data.Post; @@ -959,19 +960,22 @@ public class WebInterface implements CoreListener { lockedSonesTickerObjects.put(sone, tickerObject); } - // - // CORELISTENER METHODS - // - /** - * {@inheritDoc} + * Notifies the web interface that a Sone was unlocked. + * + * @param soneUnlockedEvent + * The event */ - @Override - public void soneUnlocked(Sone sone) { - lockedSonesNotification.remove(sone); - Ticker.getInstance().deregisterEvent(lockedSonesTickerObjects.remove(sone)); + @Subscribe + public void soneUnlocked(SoneUnlockedEvent soneUnlockedEvent) { + lockedSonesNotification.remove(soneUnlockedEvent.sone()); + Ticker.getInstance().deregisterEvent(lockedSonesTickerObjects.remove(soneUnlockedEvent.sone())); } + // + // CORELISTENER METHODS + // + /** * {@inheritDoc} */ -- 2.7.4