From 3c3506bf5574afcb3fcd222a4df46cb4fba22022 Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Thu, 11 Dec 2014 14:48:34 -0800 Subject: [PATCH] Added retry logic to UUID migration. Finally got a detailed log from hitting a rate limit - added retry logic for only the cases where it's definitely a rate limit problem. --- .../GriefPrevention/UUIDFetcher.java | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/me/ryanhamshire/GriefPrevention/UUIDFetcher.java b/src/me/ryanhamshire/GriefPrevention/UUIDFetcher.java index 413f1d9..ff2855a 100644 --- a/src/me/ryanhamshire/GriefPrevention/UUIDFetcher.java +++ b/src/me/ryanhamshire/GriefPrevention/UUIDFetcher.java @@ -96,10 +96,35 @@ class UUIDFetcher { int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { - HttpURLConnection connection = createConnection(); - String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); - writeBody(connection, body); - JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); + boolean retry = false; + JSONArray array = null; + do + { + HttpURLConnection connection = createConnection(); + String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); + writeBody(connection, body); + retry = false; + array = null; + try + { + array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); + } + catch(Exception e) + { + //in case of error 429 too many requests, pause and then retry later + if(e.getMessage().contains("429")) + { + retry = true; + GriefPrevention.AddLogEntry("Mojang says we're sending requests too fast. Will retry every 30 seconds until we succeed..."); + Thread.sleep(30000); + } + else + { + throw e; + } + } + }while(retry); + for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id");