/* synchronize access on this on sones. */
private final Map<Sone, SoneRescuer> soneRescuers = new HashMap<Sone, SoneRescuer>();
- /** All Sones. */
- /* synchronize access on this on itself. */
- private final Map<String, Sone> sones = new HashMap<String, Sone>();
-
/** All known Sones. */
private final Set<String> knownSones = new HashSet<String>();
public SoneRescuer getSoneRescuer(Sone sone) {
checkNotNull(sone, "sone must not be null");
checkArgument(sone.isLocal(), "sone must be local");
- synchronized (sones) {
+ synchronized (soneRescuers) {
SoneRescuer soneRescuer = soneRescuers.get(sone);
if (soneRescuer == null) {
soneRescuer = new SoneRescuer(this, soneDownloader, sone);
@Override
public Collection<Sone> getSones() {
- synchronized (sones) {
- return ImmutableSet.copyOf(sones.values());
- }
+ return database.getSones();
}
@Override
@Override
public Optional<Sone> getSone(String id) {
- synchronized (sones) {
- return Optional.fromNullable(sones.get(id));
- }
+ return database.getSone(id);
}
@Override
public Collection<Sone> getLocalSones() {
- synchronized (sones) {
- return from(sones.values()).filter(new Predicate<Sone>() {
-
- @Override
- public boolean apply(Sone sone) {
- return sone.isLocal();
- }
- }).toSet();
- }
+ return database.getLocalSones();
}
/**
@Override
public Collection<Sone> getRemoteSones() {
- synchronized (sones) {
- return from(sones.values()).filter(new Predicate<Sone>() {
-
- @Override
- public boolean apply(Sone sone) {
- return !sone.isLocal();
- }
- }).toSet();
- }
+ return database.getRemoteSones();
}
/**
return null;
}
logger.info(String.format("Adding Sone from OwnIdentity: %s", ownIdentity));
- synchronized (sones) {
+ synchronized (soneRescuers) {
final Sone sone;
sone = database.newSoneBuilder().by(ownIdentity.getId()).local().using(new Client("Sone", SonePlugin.VERSION.toString())).build(Optional.<SoneCreated>absent());
sone.modify().setLatestEdition(Numbers.safeParseLong(ownIdentity.getProperty("Sone.LatestEdition"), (long) 0)).update();
sone.setKnown(true);
/* TODO - load posts ’n stuff */
- sones.put(ownIdentity.getId(), sone);
+ database.storeSone(sone);
final SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, sone);
soneInserters.put(sone, soneInserter);
sone.setStatus(SoneStatus.idle);
logger.log(Level.WARNING, "Given Identity is null!");
return null;
}
- synchronized (sones) {
+ synchronized (soneRescuers) {
Optional<Sone> existingSone = database.getSone(identity.getId());
if (existingSone.isPresent() && existingSone.get().isLocal()) {
return existingSone.get();
database.storeImage(image);
}
}
- synchronized (sones) {
+ synchronized (soneRescuers) {
sone.setOptions(storedSone.get().getOptions());
sone.setKnown(storedSone.get().isKnown());
sone.setStatus((sone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);
soneInserters.get(storedSone.get()).setSone(sone);
touchConfiguration();
}
- sones.put(sone.getId(), sone);
+ database.storeSone(sone);
}
}
}
logger.log(Level.WARNING, String.format("Tried to delete Sone of non-own identity: %s", sone));
return;
}
- synchronized (sones) {
+ synchronized (soneRescuers) {
if (!getLocalSones().contains(sone)) {
logger.log(Level.WARNING, String.format("Tried to delete non-local Sone: %s", sone));
return;
}
- sones.remove(sone.getId());
SoneInserter soneInserter = soneInserters.remove(sone);
soneInserter.stop();
}
@Override
public void serviceStop() {
localElementTicker.shutdownNow();
- synchronized (sones) {
+ synchronized (soneRescuers) {
for (Entry<Sone, SoneInserter> soneInserter : soneInserters.entrySet()) {
soneInserter.getValue().stop();
saveSone(soneInserter.getKey());
for (PostReply reply : sone.get().getReplies()) {
eventBus.post(new PostReplyRemovedEvent(reply));
}
- synchronized (sones) {
- sones.remove(identity.getId());
- }
eventBus.post(new SoneRemovedEvent(sone.get()));
}