projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Convert “Sone marked as known” into EventBus-based event.
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
core
/
Core.java
diff --git
a/src/main/java/net/pterodactylus/sone/core/Core.java
b/src/main/java/net/pterodactylus/sone/core/Core.java
index
fcde685
..
ab6623b
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/core/Core.java
+++ b/
src/main/java/net/pterodactylus/sone/core/Core.java
@@
-35,6
+35,10
@@
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.Options.DefaultOption;
import net.pterodactylus.sone.core.Options.Option;
import net.pterodactylus.sone.core.Options.OptionWatcher;
+import net.pterodactylus.sone.core.event.MarkSoneKnownEvent;
+import net.pterodactylus.sone.core.event.NewPostFoundEvent;
+import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
+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;
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.data.Image;
@@
-70,6
+74,9
@@
import net.pterodactylus.util.version.Version;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
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;
/**
import freenet.keys.FreenetURI;
/**
@@
-94,6
+101,9
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
/** The core listener manager. */
private final CoreListenerManager coreListenerManager = new CoreListenerManager(this);
/** The core listener manager. */
private final CoreListenerManager coreListenerManager = new CoreListenerManager(this);
+ /** The event bus. */
+ private final EventBus eventBus;
+
/** The configuration. */
private Configuration configuration;
/** The configuration. */
private Configuration configuration;
@@
-191,8
+201,11
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
* The identity manager
* @param webOfTrustUpdater
* The WebOfTrust updater
* 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;
super("Sone Core");
this.configuration = configuration;
this.freenetInterface = freenetInterface;
@@
-201,6
+214,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
this.imageInserter = new ImageInserter(this, freenetInterface);
this.updateChecker = new UpdateChecker(freenetInterface);
this.webOfTrustUpdater = webOfTrustUpdater;
this.imageInserter = new ImageInserter(this, freenetInterface);
this.updateChecker = new UpdateChecker(freenetInterface);
this.webOfTrustUpdater = webOfTrustUpdater;
+ this.eventBus = eventBus;
}
//
}
//
@@
-416,7
+430,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
sone = new Sone(id, true);
sones.put(id, sone);
}
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);
}
sone = new Sone(id, true);
sones.put(id, sone);
}
@@
-882,7
+896,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
}
sone.setKnown(!newSone);
if (newSone) {
}
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);
for (Sone localSone : getLocalSones()) {
if (localSone.getOptions().getBooleanOption("AutoFollow").get()) {
followSone(localSone, sone);
@@
-1103,7
+1117,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
knownPosts.add(post.getId());
post.setKnown(true);
} else if (!knownPosts.contains(post.getId())) {
knownPosts.add(post.getId());
post.setKnown(true);
} else if (!knownPosts.contains(post.getId())) {
-
coreListenerManager.fireNewPostFound(post
);
+
eventBus.post(new NewPostFoundEvent(post)
);
}
}
posts.put(post.getId(), post);
}
}
posts.put(post.getId(), post);
@@
-1128,7
+1142,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
knownReplies.add(reply.getId());
reply.setKnown(true);
} else if (!knownReplies.contains(reply.getId())) {
knownReplies.add(reply.getId());
reply.setKnown(true);
} else if (!knownReplies.contains(reply.getId())) {
-
coreListenerManager.fireNewReplyFound(reply
);
+
eventBus.post(new NewPostReplyFoundEvent(reply)
);
}
}
replies.put(reply.getId(), reply);
}
}
replies.put(reply.getId(), reply);
@@
-1230,7
+1244,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
synchronized (knownSones) {
knownSones.add(sone.getId());
}
synchronized (knownSones) {
knownSones.add(sone.getId());
}
-
coreListenerManager.fireMarkSoneKnown(sone
);
+
eventBus.post(new MarkSoneKnownEvent(sone)
);
touchConfiguration();
}
}
touchConfiguration();
}
}
@@
-1532,7
+1546,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
synchronized (posts) {
posts.put(post.getId(), post);
}
synchronized (posts) {
posts.put(post.getId(), post);
}
-
coreListenerManager.fireNewPostFound(post
);
+
eventBus.post(new NewPostFoundEvent(post)
);
sone.addPost(post);
touchConfiguration();
localElementTicker.registerEvent(System.currentTimeMillis() + 10 * 1000, new Runnable() {
sone.addPost(post);
touchConfiguration();
localElementTicker.registerEvent(System.currentTimeMillis() + 10 * 1000, new Runnable() {
@@
-1671,7
+1685,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
replies.put(reply.getId(), reply);
}
synchronized (knownReplies) {
replies.put(reply.getId(), reply);
}
synchronized (knownReplies) {
-
coreListenerManager.fireNewReplyFound(reply
);
+
eventBus.post(new NewPostReplyFoundEvent(reply)
);
}
sone.addReply(reply);
touchConfiguration();
}
sone.addReply(reply);
touchConfiguration();
@@
-1893,6
+1907,9
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
loadConfiguration();
updateChecker.addUpdateListener(this);
updateChecker.start();
loadConfiguration();
updateChecker.addUpdateListener(this);
updateChecker.start();
+ identityManager.addIdentityListener(this);
+ identityManager.start();
+ webOfTrustUpdater.init();
webOfTrustUpdater.start();
}
webOfTrustUpdater.start();
}
@@
-1932,6
+1949,8
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
updateChecker.stop();
updateChecker.removeUpdateListener(this);
soneDownloader.stop();
updateChecker.stop();
updateChecker.removeUpdateListener(this);
soneDownloader.stop();
+ identityManager.removeIdentityListener(this);
+ identityManager.stop();
}
//
}
//