Include Sone ID in downloader thread name.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / FreenetInterface.java
index ec16e19..8766485 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.pterodactylus.sone.core;
 
+import static java.lang.String.format;
 import static net.pterodactylus.sone.data.Sone.TO_FREENET_URI;
 
 import java.net.MalformedURLException;
@@ -256,24 +257,7 @@ public class FreenetInterface {
         *            The callback to call
         */
        public void registerUsk(FreenetURI uri, final Callback callback) {
-               USKCallback uskCallback = new USKCallback() {
-
-                       @Override
-                       public void onFoundEdition(long edition, USK key, ObjectContainer objectContainer, ClientContext clientContext, boolean metadata, short codec, byte[] data, boolean newKnownGood, boolean newSlotToo) {
-                               callback.editionFound(key.getURI(), edition, newKnownGood, newSlotToo);
-                       }
-
-                       @Override
-                       public short getPollingPriorityNormal() {
-                               return RequestStarter.PREFETCH_PRIORITY_CLASS;
-                       }
-
-                       @Override
-                       public short getPollingPriorityProgress() {
-                               return RequestStarter.INTERACTIVE_PRIORITY_CLASS;
-                       }
-
-               };
+               USKCallback uskCallback = new CallbackWrapper(callback);
                try {
                        uskManager.subscribe(USK.create(uri), uskCallback, true, requestClient);
                        uriUskCallbacks.put(uri, uskCallback);
@@ -397,7 +381,7 @@ public class FreenetInterface {
                                        public void run() {
                                                soneDownloader.fetchSone(sone);
                                        }
-                               }, "Sone Downloader").start();
+                               }, format("Sone Downloader for %s", sone.getId())).start();
                        }
                }
 
@@ -412,6 +396,31 @@ public class FreenetInterface {
                }
        }
 
+       private static class CallbackWrapper implements USKCallback {
+
+               private final Callback callback;
+
+               public CallbackWrapper(Callback callback) {
+                       this.callback = callback;
+               }
+
+               @Override
+               public void onFoundEdition(long edition, USK key, ObjectContainer objectContainer, ClientContext clientContext, boolean metadata, short codec, byte[] data, boolean newKnownGood, boolean newSlotToo) {
+                       callback.editionFound(key.getURI(), edition, newKnownGood, newSlotToo);
+               }
+
+               @Override
+               public short getPollingPriorityNormal() {
+                       return RequestStarter.PREFETCH_PRIORITY_CLASS;
+               }
+
+               @Override
+               public short getPollingPriorityProgress() {
+                       return RequestStarter.INTERACTIVE_PRIORITY_CLASS;
+               }
+
+       }
+
        /**
         * Insert token that can cancel a running insert and sends events.
         *