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;
*
* @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);
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);
}
sones.remove(sone.getId());
SoneInserter soneInserter = soneInserters.remove(sone);
- soneInserter.removeSoneInsertListener(this);
soneInserter.stop();
}
webOfTrustUpdater.removeContext((OwnIdentity) sone.getIdentity(), "Sone");
public void serviceStop() {
synchronized (sones) {
for (Entry<Sone, SoneInserter> soneInserter : soneInserters.entrySet()) {
- soneInserter.getValue().removeSoneInsertListener(this);
soneInserter.getValue().stop();
saveSone(soneInserter.getKey());
}
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.
*
+++ /dev/null
-/*
- * 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);
-
-}
+++ /dev/null
-/*
- * 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);
- }
- }
-
-}
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.util.template.XmlFilter;
import com.google.common.collect.Ordering;
+import com.google.common.eventbus.EventBus;
import freenet.client.async.ManifestElement;
import freenet.keys.FreenetURI;
/** 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 insert listener manager. */
- private SoneInsertListenerManager soneInsertListenerManager;
-
/** Whether a modification has been detected. */
private volatile boolean modified = false;
*
* @param core
* The core
+ * @param eventBus
+ * The event bus
* @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;
+ this.eventBus = eventBus;
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);
}
//