import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.sone.data.LocalSone;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Reply;
/** Locked local Sones. */
/* synchronize on itself. */
- private final Set<Sone> lockedSones = new HashSet<Sone>();
+ private final Set<LocalSone> lockedSones = new HashSet<LocalSone>();
/** Sone inserters. */
/* synchronize access on this on sones. */
- private final Map<Sone, SoneInserter> soneInserters = new HashMap<Sone, SoneInserter>();
+ private final Map<LocalSone, SoneInserter> soneInserters = new HashMap<LocalSone, SoneInserter>();
/** Sone rescuers. */
/* synchronize access on this on sones. */
- private final Map<Sone, SoneRescuer> soneRescuers = new HashMap<Sone, SoneRescuer>();
+ private final Map<LocalSone, SoneRescuer> soneRescuers = new HashMap<LocalSone, SoneRescuer>();
/** All known Sones. */
private final Set<String> knownSones = new HashSet<String>();
* The local Sone to get the rescuer for
* @return The Sone rescuer for the given Sone
*/
- public SoneRescuer getSoneRescuer(Sone sone) {
+ public SoneRescuer getSoneRescuer(LocalSone sone) {
checkNotNull(sone, "sone must not be null");
- checkArgument(sone.isLocal(), "sone must be local");
synchronized (soneRescuers) {
SoneRescuer soneRescuer = soneRescuers.get(sone);
if (soneRescuer == null) {
* The sone to check
* @return {@code true} if the Sone is locked, {@code false} if it is not
*/
- public boolean isLocked(Sone sone) {
+ public boolean isLocked(LocalSone sone) {
synchronized (lockedSones) {
return lockedSones.contains(sone);
}
return database.getSone(id);
}
- /**
- * {@inheritDocs}
- */
@Override
- public Collection<Sone> getLocalSones() {
+ public Collection<LocalSone> getLocalSones() {
return database.getLocalSones();
}
- /**
- * Returns the local Sone with the given ID, optionally creating a new Sone.
- *
- * @param id
- * The ID of the Sone
- * @return The Sone with the given ID, or {@code null}
- */
- public Sone getLocalSone(String id) {
- Optional<Sone> sone = database.getSone(id);
- if (sone.isPresent() && sone.get().isLocal()) {
- return sone.get();
- }
- return null;
+ public Optional<LocalSone> getLocalSone(String id) {
+ return database.getLocalSone(id);
}
/**
* @return {@code true} if a modification has been detected in the Sone,
* {@code false} otherwise
*/
- public boolean isModifiedSone(Sone sone) {
+ public boolean isModifiedSone(LocalSone sone) {
return soneInserters.containsKey(sone) && soneInserters.get(sone).isModified();
}
/**
* Locks the given Sone. A locked Sone will not be inserted by
- * {@link SoneInserter} until it is {@link #unlockSone(Sone) unlocked}
+ * {@link SoneInserter} until it is {@link #unlockSone(LocalSone) unlocked}
* again.
*
* @param sone
* The sone to lock
*/
- public void lockSone(Sone sone) {
+ public void lockSone(LocalSone sone) {
synchronized (lockedSones) {
if (lockedSones.add(sone)) {
eventBus.post(new SoneLockedEvent(sone));
/**
* Unlocks the given Sone.
*
- * @see #lockSone(Sone)
+ * @see #lockSone(LocalSone)
* @param sone
* The sone to unlock
*/
- public void unlockSone(Sone sone) {
+ public void unlockSone(LocalSone sone) {
synchronized (lockedSones) {
if (lockedSones.remove(sone)) {
eventBus.post(new SoneUnlockedEvent(sone));
return null;
}
logger.info(String.format("Adding Sone from OwnIdentity: %s", ownIdentity));
- Sone sone = database.registerLocalSone(ownIdentity);
+ LocalSone sone = database.registerLocalSone(ownIdentity);
SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, ownIdentity.getId());
eventBus.register(soneInserter);
synchronized (soneInserters) {
public void serviceStop() {
localElementTicker.shutdownNow();
synchronized (soneInserters) {
- for (Entry<Sone, SoneInserter> soneInserter : soneInserters.entrySet()) {
+ for (Entry<LocalSone, SoneInserter> soneInserter : soneInserters.entrySet()) {
soneInserter.getValue().stop();
}
}