X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=629c2d54dde88b52085358b2e73fa8e667d7d93b;hb=68eb3683d2dda01e06c03d7e77d38b99be2b748f;hp=fcde6854053cfa14660f5664eb56379e505a24a5;hpb=a88e930a23b550dae75116d7759924d760941776;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index fcde685..629c2d5 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -35,6 +35,7 @@ import java.util.logging.Logger; import net.pterodactylus.sone.core.Options.DefaultOption; import net.pterodactylus.sone.core.Options.Option; import net.pterodactylus.sone.core.Options.OptionWatcher; +import net.pterodactylus.sone.core.event.NewSoneFoundEvent; import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Client; import net.pterodactylus.sone.data.Image; @@ -70,6 +71,9 @@ import net.pterodactylus.util.version.Version; import com.google.common.base.Predicate; import com.google.common.collect.Collections2; +import com.google.common.eventbus.EventBus; +import com.google.inject.Inject; + import freenet.keys.FreenetURI; /** @@ -94,6 +98,9 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis /** The core listener manager. */ private final CoreListenerManager coreListenerManager = new CoreListenerManager(this); + /** The event bus. */ + private final EventBus eventBus; + /** The configuration. */ private Configuration configuration; @@ -191,8 +198,11 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * The identity manager * @param webOfTrustUpdater * The WebOfTrust updater + * @param eventBus + * The event bus */ - public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, WebOfTrustUpdater webOfTrustUpdater) { + @Inject + public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus) { super("Sone Core"); this.configuration = configuration; this.freenetInterface = freenetInterface; @@ -201,6 +211,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis this.imageInserter = new ImageInserter(this, freenetInterface); this.updateChecker = new UpdateChecker(freenetInterface); this.webOfTrustUpdater = webOfTrustUpdater; + this.eventBus = eventBus; } // @@ -416,7 +427,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis sone = new Sone(id, true); sones.put(id, sone); } - if (!sone.isLocal()) { + if ((sone != null) && !sone.isLocal()) { sone = new Sone(id, true); sones.put(id, sone); } @@ -882,7 +893,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis } sone.setKnown(!newSone); if (newSone) { - coreListenerManager.fireNewSoneFound(sone); + eventBus.post(new NewSoneFoundEvent(sone)); for (Sone localSone : getLocalSones()) { if (localSone.getOptions().getBooleanOption("AutoFollow").get()) { followSone(localSone, sone); @@ -1893,6 +1904,9 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis loadConfiguration(); updateChecker.addUpdateListener(this); updateChecker.start(); + identityManager.addIdentityListener(this); + identityManager.start(); + webOfTrustUpdater.init(); webOfTrustUpdater.start(); } @@ -1932,6 +1946,8 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis updateChecker.stop(); updateChecker.removeUpdateListener(this); soneDownloader.stop(); + identityManager.removeIdentityListener(this); + identityManager.stop(); } //