Move callback wrapper to inner class.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 5 Mar 2014 18:45:49 +0000 (19:45 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 5 Mar 2014 18:45:49 +0000 (19:45 +0100)
src/main/java/net/pterodactylus/sone/core/FreenetInterface.java

index ec16e19..93580a3 100644 (file)
@@ -256,24 +256,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);
@@ -412,6 +395,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.
         *