From 126dbf62496cbb3ee3d78fe54ab4d588eeca0347 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:44:54 +0100 Subject: [PATCH] Move USK callback to inner class. --- .../pterodactylus/sone/core/FreenetInterface.java | 66 +++++++++++++--------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index 3baaa7d..ec16e19 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -218,34 +218,7 @@ public class FreenetInterface { public void registerUsk(final Sone sone, final SoneDownloader soneDownloader) { try { logger.log(Level.FINE, String.format("Registering Sone “%s” for USK updates at %s…", sone, TO_FREENET_URI.apply(sone).setMetaString(new String[]{"sone.xml"}))); - USKCallback uskCallback = new USKCallback() { - - @Override - @SuppressWarnings("synthetic-access") - public void onFoundEdition(long edition, USK key, ObjectContainer objectContainer, ClientContext clientContext, boolean metadata, short codec, byte[] data, boolean newKnownGood, boolean newSlotToo) { - logger.log(Level.FINE, String.format("Found USK update for Sone “%s” at %s, new known good: %s, new slot too: %s.", sone, key, newKnownGood, newSlotToo)); - if (edition > sone.getLatestEdition()) { - sone.modify().setLatestEdition(edition).update(); - new Thread(new Runnable() { - - @Override - public void run() { - soneDownloader.fetchSone(sone); - } - }, "Sone Downloader").start(); - } - } - - @Override - public short getPollingPriorityProgress() { - return RequestStarter.INTERACTIVE_PRIORITY_CLASS; - } - - @Override - public short getPollingPriorityNormal() { - return RequestStarter.INTERACTIVE_PRIORITY_CLASS; - } - }; + USKCallback uskCallback = new NewEditionFound(sone, soneDownloader); soneUskCallbacks.put(sone.getId(), uskCallback); boolean runBackgroundFetch = (System.currentTimeMillis() - sone.getTime()) < TimeUnit.DAYS.toMillis(7); uskManager.subscribe(USK.create(TO_FREENET_URI.apply(sone)), uskCallback, runBackgroundFetch, requestClient); @@ -402,6 +375,43 @@ public class FreenetInterface { } + private static class NewEditionFound implements USKCallback { + + private final Sone sone; + private final SoneDownloader soneDownloader; + + public NewEditionFound(Sone sone, SoneDownloader soneDownloader) { + this.sone = sone; + this.soneDownloader = soneDownloader; + } + + @Override + @SuppressWarnings("synthetic-access") + public void onFoundEdition(long edition, USK key, ObjectContainer objectContainer, ClientContext clientContext, boolean metadata, short codec, byte[] data, boolean newKnownGood, boolean newSlotToo) { + logger.log(Level.FINE, String.format("Found USK update for Sone “%s” at %s, new known good: %s, new slot too: %s.", sone, key, newKnownGood, newSlotToo)); + if (edition > sone.getLatestEdition()) { + sone.modify().setLatestEdition(edition).update(); + new Thread(new Runnable() { + + @Override + public void run() { + soneDownloader.fetchSone(sone); + } + }, "Sone Downloader").start(); + } + } + + @Override + public short getPollingPriorityProgress() { + return RequestStarter.INTERACTIVE_PRIORITY_CLASS; + } + + @Override + public short getPollingPriorityNormal() { + return RequestStarter.INTERACTIVE_PRIORITY_CLASS; + } + } + /** * Insert token that can cancel a running insert and sends events. * -- 2.7.4