import net.pterodactylus.sone.data.Profile;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.data.Sone.ShowCustomAvatars;
import net.pterodactylus.sone.data.TemporaryImage;
import net.pterodactylus.sone.data.Profile.Field;
+import net.pterodactylus.sone.data.Sone.ShowCustomAvatars;
+import net.pterodactylus.sone.data.Sone.SoneStatus;
import net.pterodactylus.sone.fcp.FcpInterface;
import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
import net.pterodactylus.sone.freenet.wot.Identity;
*/
public class Core extends AbstractService implements IdentityListener, UpdateListener, SoneProvider, PostProvider, SoneInsertListener, ImageInsertListener {
- /**
- * Enumeration for the possible states of a {@link Sone}.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
- public enum SoneStatus {
-
- /** The Sone is unknown, i.e. not yet downloaded. */
- unknown,
-
- /** The Sone is idle, i.e. not being downloaded or inserted. */
- idle,
-
- /** The Sone is currently being inserted. */
- inserting,
-
- /** The Sone is currently being downloaded. */
- downloading,
- }
-
/** The logger. */
private static final Logger logger = Logging.getLogger(Core.class);
/** The FCP interface. */
private volatile FcpInterface fcpInterface;
- /** The Sones’ statuses. */
- /* synchronize access on itself. */
- private final Map<Sone, SoneStatus> soneStatuses = new HashMap<Sone, SoneStatus>();
-
/** The times Sones were followed. */
private final Map<Sone, Long> soneFollowingTimes = new HashMap<Sone, Long>();
}
/**
- * Returns the status of the given Sone.
- *
- * @param sone
- * The Sone to get the status for
- * @return The status of the Sone
- */
- public SoneStatus getSoneStatus(Sone sone) {
- synchronized (soneStatuses) {
- return soneStatuses.get(sone);
- }
- }
-
- /**
- * Sets the status of the given Sone.
- *
- * @param sone
- * The Sone to set the status of
- * @param soneStatus
- * The status to set
- */
- public void setSoneStatus(Sone sone, SoneStatus soneStatus) {
- synchronized (soneStatuses) {
- soneStatuses.put(sone, soneStatus);
- }
- }
-
- /**
* Returns the Sone rescuer for the given local Sone.
*
* @param sone
if ((sone == null) && create) {
sone = new Sone(id);
localSones.put(id, sone);
- setSoneStatus(sone, SoneStatus.unknown);
}
return sone;
}
if ((sone == null) && create && (id != null) && (id.length() == 43)) {
sone = new Sone(id);
remoteSones.put(id, sone);
- setSoneStatus(sone, SoneStatus.unknown);
}
return sone;
}
final SoneInserter soneInserter = new SoneInserter(this, freenetInterface, sone);
soneInserter.addSoneInsertListener(this);
soneInserters.put(sone, soneInserter);
- setSoneStatus(sone, SoneStatus.idle);
+ sone.setStatus(SoneStatus.idle);
loadSone(sone);
soneInserter.start();
return sone;
}
}
soneDownloader.addSone(sone);
- setSoneStatus(sone, SoneStatus.unknown);
soneDownloaders.execute(new Runnable() {
@Override
import java.util.logging.Level;
import java.util.logging.Logger;
-import net.pterodactylus.sone.core.Core.SoneStatus;
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Client;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Profile;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.data.Sone.SoneStatus;
import net.pterodactylus.util.collection.Pair;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.util.logging.Logging;
public Sone fetchSone(Sone sone, FreenetURI soneUri, boolean fetchOnly) {
logger.log(Level.FINE, "Starting fetch for Sone “%s” from %s…", new Object[] { sone, soneUri });
FreenetURI requestUri = soneUri.setMetaString(new String[] { "sone.xml" });
- core.setSoneStatus(sone, SoneStatus.downloading);
+ sone.setStatus(SoneStatus.downloading);
try {
Pair<FreenetURI, FetchResult> fetchResults = freenetInterface.fetchUri(requestUri);
if (fetchResults == null) {
}
return parsedSone;
} finally {
- core.setSoneStatus(sone, (sone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);
+ sone.setStatus((sone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);
}
}
import java.util.logging.Level;
import java.util.logging.Logger;
-import net.pterodactylus.sone.core.Core.SoneStatus;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.data.Sone.SoneStatus;
import net.pterodactylus.sone.freenet.StringBucket;
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.util.collection.ListBuilder;
boolean success = false;
try {
- core.setSoneStatus(sone, SoneStatus.inserting);
+ sone.setStatus(SoneStatus.inserting);
long insertTime = System.currentTimeMillis();
insertInformation.setTime(insertTime);
soneInsertListenerManager.fireInsertStarted();
soneInsertListenerManager.fireInsertAborted(se1);
logger.log(Level.WARNING, "Could not insert Sone “" + sone.getName() + "”!", se1);
} finally {
- core.setSoneStatus(sone, SoneStatus.idle);
+ sone.setStatus(SoneStatus.idle);
}
/*
public class Sone implements Fingerprintable, Comparable<Sone> {
/**
+ * Enumeration for the possible states of a {@link Sone}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+ public enum SoneStatus {
+
+ /** The Sone is unknown, i.e. not yet downloaded. */
+ unknown,
+
+ /** The Sone is idle, i.e. not being downloaded or inserted. */
+ idle,
+
+ /** The Sone is currently being inserted. */
+ inserting,
+
+ /** The Sone is currently being downloaded. */
+ downloading,
+ }
+
+ /**
* The possible values for the “show custom avatars” option.
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
/** The time of the last inserted update. */
private volatile long time;
+ /** The status of this Sone. */
+ private volatile SoneStatus status = SoneStatus.unknown;
+
/** The profile of this Sone. */
private volatile Profile profile = new Profile(this);
}
/**
+ * Returns the status of this Sone.
+ *
+ * @return The status of this Sone
+ */
+ public SoneStatus getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the new status of this Sone.
+ *
+ * @param status
+ * The new status of this Sone
+ * @return This Sone
+ * @throws IllegalArgumentException
+ * if {@code status} is {@code null}
+ */
+ public Sone setStatus(SoneStatus status) {
+ Validation.begin().isNotNull("Sone Status", status).check();
+ this.status = status;
+ return this;
+ }
+
+ /**
* Returns a copy of the profile. If you want to update values in the
* profile of this Sone, update the values in the returned {@link Profile}
* and use {@link #setProfile(Profile)} to change the profile in this Sone.
import java.util.logging.Logger;
import net.pterodactylus.sone.core.Core;
-import net.pterodactylus.sone.core.Core.SoneStatus;
import net.pterodactylus.sone.data.Profile;
import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.data.Sone.SoneStatus;
import net.pterodactylus.sone.freenet.wot.Trust;
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.web.ajax.GetTimesAjaxPage;
} else if (member.equals("modified")) {
return core.isModifiedSone(sone);
} else if (member.equals("status")) {
- return core.getSoneStatus(sone);
+ return sone.getStatus();
} else if (member.equals("unknown")) {
- return core.getSoneStatus(sone) == SoneStatus.unknown;
+ return sone.getStatus() == SoneStatus.unknown;
} else if (member.equals("idle")) {
- return core.getSoneStatus(sone) == SoneStatus.idle;
+ return sone.getStatus() == SoneStatus.idle;
} else if (member.equals("inserting")) {
- return core.getSoneStatus(sone) == SoneStatus.inserting;
+ return sone.getStatus() == SoneStatus.inserting;
} else if (member.equals("downloading")) {
- return core.getSoneStatus(sone) == SoneStatus.downloading;
+ return sone.getStatus() == SoneStatus.downloading;
} else if (member.equals("new")) {
return core.isNewSone(sone.getId());
} else if (member.equals("locked")) {
jsonSone.put("id", sone.getId());
jsonSone.put("name", SoneAccessor.getNiceName(sone));
jsonSone.put("local", sone.getInsertUri() != null);
- jsonSone.put("status", webInterface.getCore().getSoneStatus(sone).name());
+ jsonSone.put("status", sone.getStatus().name());
jsonSone.put("modified", webInterface.getCore().isModifiedSone(sone));
jsonSone.put("locked", webInterface.getCore().isLocked(sone));
jsonSone.put("lastUpdatedUnknown", sone.getTime() == 0);