projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'next' into new-database-38
[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
0b1379a
..
1bb638a
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/core/Core.java
+++ b/
src/main/java/net/pterodactylus/sone/core/Core.java
@@
-61,6
+61,7
@@
import net.pterodactylus.util.config.ConfigurationException;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.service.AbstractService;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.service.AbstractService;
+import net.pterodactylus.util.thread.NamedThreadFactory;
import net.pterodactylus.util.thread.Ticker;
import net.pterodactylus.util.validation.EqualityValidator;
import net.pterodactylus.util.validation.IntegerRangeValidator;
import net.pterodactylus.util.thread.Ticker;
import net.pterodactylus.util.validation.EqualityValidator;
import net.pterodactylus.util.validation.IntegerRangeValidator;
@@
-79,6
+80,9
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
/** The logger. */
private static final Logger logger = Logging.getLogger(Core.class);
/** The logger. */
private static final Logger logger = Logging.getLogger(Core.class);
+ /** The start time. */
+ private final long startupTime = System.currentTimeMillis();
+
/** The options. */
private final Options options = new Options();
/** The options. */
private final Options options = new Options();
@@
-110,7
+114,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
private final ImageInserter imageInserter;
/** Sone downloader thread-pool. */
private final ImageInserter imageInserter;
/** Sone downloader thread-pool. */
- private final ExecutorService soneDownloaders = Executors.newFixedThreadPool(10);
+ private final ExecutorService soneDownloaders = Executors.newFixedThreadPool(10
, new NamedThreadFactory("Sone Downloader %2$d")
);
/** The update checker. */
private final UpdateChecker updateChecker;
/** The update checker. */
private final UpdateChecker updateChecker;
@@
-228,6
+232,15
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
//
/**
//
/**
+ * Returns the time Sone was started.
+ *
+ * @return The startup time (in milliseconds since Jan 1, 1970 UTC)
+ */
+ public long getStartupTime() {
+ return startupTime;
+ }
+
+ /**
* Sets the configuration to use. This will automatically save the current
* configuration to the given configuration.
*
* Sets the configuration to use. This will automatically save the current
* configuration to the given configuration.
*
@@
-1056,8
+1069,8
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
if (!storedPosts.contains(post)) {
if (post.getTime() < getSoneFollowingTime(sone)) {
knownPosts.add(post.getId());
if (!storedPosts.contains(post)) {
if (post.getTime() < getSoneFollowingTime(sone)) {
knownPosts.add(post.getId());
+ post.setKnown(true);
} else if (!knownPosts.contains(post.getId())) {
} else if (!knownPosts.contains(post.getId())) {
- sone.setKnown(false);
coreListenerManager.fireNewPostFound(post);
}
}
coreListenerManager.fireNewPostFound(post);
}
}
@@
-1081,8
+1094,8
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
if (!storedReplies.contains(reply)) {
if (reply.getTime() < getSoneFollowingTime(sone)) {
knownReplies.add(reply.getId());
if (!storedReplies.contains(reply)) {
if (reply.getTime() < getSoneFollowingTime(sone)) {
knownReplies.add(reply.getId());
+ reply.setKnown(true);
} else if (!knownReplies.contains(reply.getId())) {
} else if (!knownReplies.contains(reply.getId())) {
- reply.setKnown(false);
coreListenerManager.fireNewReplyFound(reply);
}
}
coreListenerManager.fireNewReplyFound(reply);
}
}
@@
-1429,6
+1442,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
* @return The created post
*/
public Post createPost(Sone sone, Sone recipient, long time, String text) {
* @return The created post
*/
public Post createPost(Sone sone, Sone recipient, long time, String text) {
+ Validation.begin().isNotNull("Text", text).check().isGreater("Text Length", text.length(), 0).check();
if (!sone.isLocal()) {
logger.log(Level.FINE, String.format("Tried to create post for non-local Sone: %s", sone));
return null;
if (!sone.isLocal()) {
logger.log(Level.FINE, String.format("Tried to create post for non-local Sone: %s", sone));
return null;
@@
-1569,6
+1583,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
* @return The created reply
*/
public PostReply createReply(Sone sone, Post post, long time, String text) {
* @return The created reply
*/
public PostReply createReply(Sone sone, Post post, long time, String text) {
+ Validation.begin().isNotNull("Text", text).check().isGreater("Text Length", text.trim().length(), 0).check();
if (!sone.isLocal()) {
logger.log(Level.FINE, String.format("Tried to create reply for non-local Sone: %s", sone));
return null;
if (!sone.isLocal()) {
logger.log(Level.FINE, String.format("Tried to create reply for non-local Sone: %s", sone));
return null;
@@
-2260,7
+2275,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
*/
@Override
public void identityUpdated(OwnIdentity ownIdentity, final Identity identity) {
*/
@Override
public void identityUpdated(OwnIdentity ownIdentity, final Identity identity) {
-
new Thread
(new Runnable() {
+
soneDownloaders.execute
(new Runnable() {
@Override
@SuppressWarnings("synthetic-access")
@Override
@SuppressWarnings("synthetic-access")
@@
-2271,7
+2286,7
@@
public class Core extends AbstractService implements IdentityListener, UpdateLis
soneDownloader.addSone(sone);
soneDownloader.fetchSone(sone);
}
soneDownloader.addSone(sone);
soneDownloader.fetchSone(sone);
}
- })
.start()
;
+ });
}
/**
}
/**