From e9a40f350a814965b056ff5d2a3f6dbe1f0e663d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 5 Mar 2014 19:45:49 +0100 Subject: [PATCH] Move callback wrapper to inner class. --- .../pterodactylus/sone/core/FreenetInterface.java | 44 +++++++++++++--------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index ec16e19..93580a3 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -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. * -- 2.7.4