Convert Sone insert events to EventBus-based events.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 17 Jan 2013 05:32:12 +0000 (06:32 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 17 Jan 2013 05:37:46 +0000 (06:37 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/SoneInsertListener.java [deleted file]
src/main/java/net/pterodactylus/sone/core/SoneInsertListenerManager.java [deleted file]
src/main/java/net/pterodactylus/sone/core/SoneInserter.java

index e278629..57913b2 100644 (file)
@@ -44,9 +44,6 @@ 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.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;
 import net.pterodactylus.sone.core.event.SoneRemovedEvent;
 import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
 import net.pterodactylus.sone.core.event.SoneLockedEvent;
 import net.pterodactylus.sone.core.event.SoneRemovedEvent;
 import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
@@ -97,7 +94,7 @@ import freenet.keys.FreenetURI;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class Core extends AbstractService implements IdentityListener, UpdateListener, SoneProvider, PostProvider, SoneInsertListener {
+public class Core extends AbstractService implements IdentityListener, UpdateListener, SoneProvider, PostProvider {
 
        /** The logger. */
        private static final Logger logger = Logging.getLogger(Core.class);
 
        /** The logger. */
        private static final Logger logger = Logging.getLogger(Core.class);
@@ -824,8 +821,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                        sone.setKnown(true);
                        /* TODO - load posts ’n stuff */
                        sones.put(ownIdentity.getId(), sone);
                        sone.setKnown(true);
                        /* TODO - load posts ’n stuff */
                        sones.put(ownIdentity.getId(), sone);
-                       final SoneInserter soneInserter = new SoneInserter(this, freenetInterface, sone);
-                       soneInserter.addSoneInsertListener(this);
+                       final SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, sone);
                        soneInserters.put(sone, soneInserter);
                        sone.setStatus(SoneStatus.idle);
                        loadSone(sone);
                        soneInserters.put(sone, soneInserter);
                        sone.setStatus(SoneStatus.idle);
                        loadSone(sone);
@@ -1205,7 +1201,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                        }
                        sones.remove(sone.getId());
                        SoneInserter soneInserter = soneInserters.remove(sone);
                        }
                        sones.remove(sone.getId());
                        SoneInserter soneInserter = soneInserters.remove(sone);
-                       soneInserter.removeSoneInsertListener(this);
                        soneInserter.stop();
                }
                webOfTrustUpdater.removeContext((OwnIdentity) sone.getIdentity(), "Sone");
                        soneInserter.stop();
                }
                webOfTrustUpdater.removeContext((OwnIdentity) sone.getIdentity(), "Sone");
@@ -1925,7 +1920,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
        public void serviceStop() {
                synchronized (sones) {
                        for (Entry<Sone, SoneInserter> soneInserter : soneInserters.entrySet()) {
        public void serviceStop() {
                synchronized (sones) {
                        for (Entry<Sone, SoneInserter> soneInserter : soneInserters.entrySet()) {
-                               soneInserter.getValue().removeSoneInsertListener(this);
                                soneInserter.getValue().stop();
                                saveSone(soneInserter.getKey());
                        }
                                soneInserter.getValue().stop();
                                saveSone(soneInserter.getKey());
                        }
@@ -2432,34 +2426,6 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis
                eventBus.post(new UpdateFoundEvent(version, releaseTime, latestEdition));
        }
 
                eventBus.post(new UpdateFoundEvent(version, releaseTime, latestEdition));
        }
 
-       //
-       // INTERFACE ImageInsertListener
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public void insertStarted(Sone sone) {
-               eventBus.post(new SoneInsertingEvent(sone));
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public void insertFinished(Sone sone, long insertDuration) {
-               eventBus.post(new SoneInsertedEvent(sone, insertDuration));
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public void insertAborted(Sone sone, Throwable cause) {
-               eventBus.post(new SoneInsertAbortedEvent(sone, cause));
-       }
-
        /**
         * Deletes the temporary image.
         *
        /**
         * Deletes the temporary image.
         *
diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInsertListener.java b/src/main/java/net/pterodactylus/sone/core/SoneInsertListener.java
deleted file mode 100644 (file)
index 6f99fe6..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Sone - SoneInsertListener.java - Copyright © 2011–2012 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core;
-
-import java.util.EventListener;
-
-import net.pterodactylus.sone.data.Sone;
-
-/**
- * Listener for Sone insert events.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public interface SoneInsertListener extends EventListener {
-
-       /**
-        * Notifies a listener that a Sone is now being inserted.
-        *
-        * @param sone
-        *            The Sone being inserted
-        */
-       public void insertStarted(Sone sone);
-
-       /**
-        * Notifies a listener that a Sone has been successfully inserted.
-        *
-        * @param sone
-        *            The Sone that was inserted
-        * @param insertDuration
-        *            The duration of the insert (in milliseconds)
-        */
-       public void insertFinished(Sone sone, long insertDuration);
-
-       /**
-        * Notifies a listener that the insert of the given Sone was aborted.
-        *
-        * @param sone
-        *            The Sone that was being inserted
-        * @param cause
-        *            The cause of the abortion (may be {@code null})
-        */
-       public void insertAborted(Sone sone, Throwable cause);
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInsertListenerManager.java b/src/main/java/net/pterodactylus/sone/core/SoneInsertListenerManager.java
deleted file mode 100644 (file)
index 6841e7f..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Sone - SoneInsertListenerManager.java - Copyright © 2011–2012 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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core;
-
-import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.util.event.AbstractListenerManager;
-
-/**
- * Manager for {@link SoneInsertListener}s.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class SoneInsertListenerManager extends AbstractListenerManager<Sone, SoneInsertListener> {
-
-       /**
-        * Creates a new Sone insert listener manager.
-        *
-        * @param sone
-        *            The sone being inserted
-        */
-       public SoneInsertListenerManager(Sone sone) {
-               super(sone);
-       }
-
-       //
-       // ACTIONS
-       //
-
-       /**
-        * Notifies all listeners that the insert of the Sone has started.
-        *
-        * @see SoneInsertListener#insertStarted(Sone)
-        */
-       void fireInsertStarted() {
-               for (SoneInsertListener soneInsertListener : getListeners()) {
-                       soneInsertListener.insertStarted(getSource());
-               }
-       }
-
-       /**
-        * Notifies all listeners that the insert of the Sone has finished
-        * successfully.
-        *
-        * @see SoneInsertListener#insertFinished(Sone, long)
-        * @param insertDuration
-        *            The insert duration (in milliseconds)
-        */
-       void fireInsertFinished(long insertDuration) {
-               for (SoneInsertListener soneInsertListener : getListeners()) {
-                       soneInsertListener.insertFinished(getSource(), insertDuration);
-               }
-       }
-
-       /**
-        * Notifies all listeners that the insert of the Sone was aborted.
-        *
-        * @see SoneInsertListener#insertAborted(Sone, Throwable)
-        * @param cause
-        *            The cause of the abortion (may be {@code null}
-        */
-       void fireInsertAborted(Throwable cause) {
-               for (SoneInsertListener soneInsertListener : getListeners()) {
-                       soneInsertListener.insertAborted(getSource(), cause);
-               }
-       }
-
-}
index 69d3db5..80255a1 100644 (file)
@@ -26,6 +26,9 @@ import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+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.data.Post;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
@@ -45,6 +48,7 @@ import net.pterodactylus.util.template.TemplateParser;
 import net.pterodactylus.util.template.XmlFilter;
 
 import com.google.common.collect.Ordering;
 import net.pterodactylus.util.template.XmlFilter;
 
 import com.google.common.collect.Ordering;
+import com.google.common.eventbus.EventBus;
 
 import freenet.client.async.ManifestElement;
 import freenet.keys.FreenetURI;
 
 import freenet.client.async.ManifestElement;
 import freenet.keys.FreenetURI;
@@ -77,15 +81,15 @@ public class SoneInserter extends AbstractService {
        /** The core. */
        private final Core core;
 
        /** The core. */
        private final Core core;
 
+       /** The event bus. */
+       private final EventBus eventBus;
+
        /** The Freenet interface. */
        private final FreenetInterface freenetInterface;
 
        /** The Sone to insert. */
        private final Sone sone;
 
        /** The Freenet interface. */
        private final FreenetInterface freenetInterface;
 
        /** The Sone to insert. */
        private final Sone sone;
 
-       /** The insert listener manager. */
-       private SoneInsertListenerManager soneInsertListenerManager;
-
        /** Whether a modification has been detected. */
        private volatile boolean modified = false;
 
        /** Whether a modification has been detected. */
        private volatile boolean modified = false;
 
@@ -97,41 +101,19 @@ public class SoneInserter extends AbstractService {
         *
         * @param core
         *            The core
         *
         * @param core
         *            The core
+        * @param eventBus
+        *            The event bus
         * @param freenetInterface
         *            The freenet interface
         * @param sone
         *            The Sone to insert
         */
         * @param freenetInterface
         *            The freenet interface
         * @param sone
         *            The Sone to insert
         */
-       public SoneInserter(Core core, FreenetInterface freenetInterface, Sone sone) {
+       public SoneInserter(Core core, EventBus eventBus, FreenetInterface freenetInterface, Sone sone) {
                super("Sone Inserter for “" + sone.getName() + "”", false);
                this.core = core;
                super("Sone Inserter for “" + sone.getName() + "”", false);
                this.core = core;
+               this.eventBus = eventBus;
                this.freenetInterface = freenetInterface;
                this.sone = sone;
                this.freenetInterface = freenetInterface;
                this.sone = sone;
-               this.soneInsertListenerManager = new SoneInsertListenerManager(sone);
-       }
-
-       //
-       // LISTENER MANAGEMENT
-       //
-
-       /**
-        * Adds a listener for Sone insert events.
-        *
-        * @param soneInsertListener
-        *            The Sone insert listener
-        */
-       public void addSoneInsertListener(SoneInsertListener soneInsertListener) {
-               soneInsertListenerManager.addListener(soneInsertListener);
-       }
-
-       /**
-        * Removes a listener for Sone insert events.
-        *
-        * @param soneInsertListener
-        *            The Sone insert listener
-        */
-       public void removeSoneInsertListener(SoneInsertListener soneInsertListener) {
-               soneInsertListenerManager.removeListener(soneInsertListener);
        }
 
        //
        }
 
        //