Use local Sone with the Sone inserters.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index b485445..2d23de3 100644 (file)
@@ -148,15 +148,15 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
 
        /** 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>();
@@ -269,9 +269,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
         *            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) {
@@ -290,7 +289,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
         *            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);
                }
@@ -573,13 +572,13 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
 
        /**
         * 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));
@@ -590,11 +589,11 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
        /**
         * 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));
@@ -615,7 +614,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                        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) {
@@ -1251,7 +1250,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
        public void serviceStop() {
                localElementTicker.shutdownNow();
                synchronized (soneInserters) {
-                       for (Entry<Sone, SoneInserter> soneInserter : soneInserters.entrySet()) {
+                       for (Entry<LocalSone, SoneInserter> soneInserter : soneInserters.entrySet()) {
                                soneInserter.getValue().stop();
                        }
                }