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;
import net.pterodactylus.util.validation.IntegerRangeValidator;
import net.pterodactylus.util.validation.OrValidator;
import net.pterodactylus.util.validation.Validation;
-import net.pterodactylus.util.version.Version;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
-public class Core extends AbstractService implements IdentityListener, UpdateListener, SoneProvider, PostProvider {
+public class Core extends AbstractService implements IdentityListener, SoneProvider, PostProvider {
/** The logger. */
private static final Logger logger = Logging.getLogger(Core.class);
this.identityManager = identityManager;
this.soneDownloader = new SoneDownloader(this, freenetInterface);
this.imageInserter = new ImageInserter(freenetInterface);
- this.updateChecker = new UpdateChecker(freenetInterface);
+ this.updateChecker = new UpdateChecker(eventBus, freenetInterface);
this.webOfTrustUpdater = webOfTrustUpdater;
this.eventBus = eventBus;
}
@Override
public void serviceStart() {
loadConfiguration();
- updateChecker.addUpdateListener(this);
updateChecker.start();
identityManager.addIdentityListener(this);
identityManager.start();
saveConfiguration();
webOfTrustUpdater.stop();
updateChecker.stop();
- updateChecker.removeUpdateListener(this);
soneDownloader.stop();
identityManager.removeIdentityListener(this);
identityManager.stop();
eventBus.post(new SoneRemovedEvent(sone));
}
- //
- // INTERFACE UpdateListener
- //
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void updateFound(Version version, long releaseTime, long latestEdition) {
- eventBus.post(new UpdateFoundEvent(version, releaseTime, latestEdition));
- }
-
/**
* Deletes the temporary image.
*
import java.util.logging.Logger;
import net.pterodactylus.sone.core.FreenetInterface.Fetched;
+import net.pterodactylus.sone.core.event.UpdateFoundEvent;
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.version.Version;
+
+import com.google.common.eventbus.EventBus;
+import com.google.inject.Inject;
+
import freenet.keys.FreenetURI;
import freenet.support.api.Bucket;
/** The current latest known edition. */
private static final int LATEST_EDITION = 55;
+ /** The event bus. */
+ private final EventBus eventBus;
+
/** The Freenet interface. */
private final FreenetInterface freenetInterface;
- /** The update listener manager. */
- private final UpdateListenerManager updateListenerManager = new UpdateListenerManager();
-
/** The current URI of the homepage. */
private FreenetURI currentUri;
/**
* Creates a new update checker.
*
+ * @param eventBus
+ * The event bus
* @param freenetInterface
* The freenet interface to use
*/
- public UpdateChecker(FreenetInterface freenetInterface) {
+ @Inject
+ public UpdateChecker(EventBus eventBus, FreenetInterface freenetInterface) {
+ this.eventBus = eventBus;
this.freenetInterface = freenetInterface;
}
//
- // EVENT LISTENER MANAGEMENT
- //
-
- /**
- * Adds the given listener to the list of registered listeners.
- *
- * @param updateListener
- * The listener to add
- */
- public void addUpdateListener(UpdateListener updateListener) {
- updateListenerManager.addListener(updateListener);
- }
-
- /**
- * Removes the given listener from the list of registered listeners.
- *
- * @param updateListener
- * The listener to remove
- */
- public void removeUpdateListener(UpdateListener updateListener) {
- updateListenerManager.removeListener(updateListener);
- }
-
- //
// ACCESSORS
//
* Parses the properties of the latest version and fires events, if
* necessary.
*
- * @see UpdateListener#updateFound(Version, long, long)
- * @see UpdateListenerManager#fireUpdateFound(Version, long, long)
+ * @see UpdateFoundEvent
* @param propertiesInputStream
* The input stream to parse
* @param edition
currentLatestVersion = version;
latestVersionDate = releaseTime;
logger.log(Level.INFO, String.format("Found new version: %s (%tc)", version, new Date(releaseTime)));
- updateListenerManager.fireUpdateFound(version, releaseTime, edition);
+ eventBus.post(new UpdateFoundEvent(version, releaseTime, edition));
}
}
+++ /dev/null
-/*
- * Sone - UpdateListener.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.util.version.Version;
-
-/**
- * Listener interface for {@link UpdateChecker} events.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public interface UpdateListener extends EventListener {
-
- /**
- * Notifies a listener that a newer version than the current version was
- * found.
- *
- * @param version
- * The version that was found
- * @param releaseTime
- * The release time of the version
- * @param latestEdition
- * The latest edition of the Sone homepage
- */
- public void updateFound(Version version, long releaseTime, long latestEdition);
-
-}
+++ /dev/null
-/*
- * Sone - UpdateListenerManager.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.util.event.AbstractListenerManager;
-import net.pterodactylus.util.version.Version;
-
-/**
- * Listener manager for {@link UpdateListener} events.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class UpdateListenerManager extends AbstractListenerManager<Void, UpdateListener> {
-
- /**
- * Creates a new update listener manager.
- */
- public UpdateListenerManager() {
- super(null);
- }
-
- //
- // ACTIONS
- //
-
- /**
- * Notifies all listeners that a new version has been found.
- *
- * @param version
- * The new version
- * @param releaseTime
- * The release time of the new version
- * @param latestEdition
- * The latest edition of the Sone homepage
- */
- void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
- for (UpdateListener updateListener : getListeners()) {
- updateListener.updateFound(version, releaseTime, latestEdition);
- }
- }
-
-}