mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
reorganize and do proper resource cleanup
This commit is contained in:
parent
3fa9b31ad5
commit
88e0aa64a0
@ -35,7 +35,6 @@ import java.util.logging.Level;
|
||||
*/
|
||||
public class DataManager implements Listener {
|
||||
private final RedisBungee plugin;
|
||||
// TODO: Add cleanup for this.
|
||||
private final Cache<UUID, String> serverCache = createCache();
|
||||
private final Cache<UUID, String> proxyCache = createCache();
|
||||
private final Cache<UUID, InetAddress> ipCache = createCache();
|
||||
@ -46,6 +45,7 @@ public class DataManager implements Listener {
|
||||
}
|
||||
|
||||
private static <K, V> Cache<K, V> createCache() {
|
||||
// TODO: Allow customization via cache specification, ala ServerListPlus
|
||||
return CacheBuilder.newBuilder()
|
||||
.maximumSize(1000)
|
||||
.expireAfterWrite(1, TimeUnit.HOURS)
|
||||
|
@ -7,6 +7,9 @@ import com.google.common.io.ByteStreams;
|
||||
import com.google.gson.Gson;
|
||||
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
|
||||
import com.imaginarycode.minecraft.redisbungee.util.*;
|
||||
import com.imaginarycode.minecraft.redisbungee.util.uuid.NameFetcher;
|
||||
import com.imaginarycode.minecraft.redisbungee.util.uuid.UUIDFetcher;
|
||||
import com.imaginarycode.minecraft.redisbungee.util.uuid.UUIDTranslator;
|
||||
import com.squareup.okhttp.Dispatcher;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import lombok.AccessLevel;
|
||||
|
@ -1,9 +1,10 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.util;
|
||||
package com.imaginarycode.minecraft.redisbungee.util.uuid;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.ResponseBody;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@ -22,7 +23,9 @@ public class NameFetcher {
|
||||
public static List<String> nameHistoryFromUuid(UUID uuid) throws IOException {
|
||||
String url = "https://api.mojang.com/user/profiles/" + uuid.toString().replace("-", "") + "/names";
|
||||
Request request = new Request.Builder().url(url).get().build();
|
||||
String response = httpClient.newCall(request).execute().body().string();
|
||||
ResponseBody body = httpClient.newCall(request).execute().body();
|
||||
String response = body.string();
|
||||
body.close();
|
||||
|
||||
Type listType = new TypeToken<List<Name>>() {
|
||||
}.getType();
|
@ -1,11 +1,8 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.util;
|
||||
package com.imaginarycode.minecraft.redisbungee.util.uuid;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.imaginarycode.minecraft.redisbungee.RedisBungee;
|
||||
import com.squareup.okhttp.MediaType;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import com.squareup.okhttp.*;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -44,7 +41,9 @@ public class UUIDFetcher implements Callable<Map<String, UUID>> {
|
||||
for (int i = 0; i < requests; i++) {
|
||||
String body = RedisBungee.getGson().toJson(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
|
||||
Request request = new Request.Builder().url(PROFILE_URL).post(RequestBody.create(JSON, body)).build();
|
||||
String response = httpClient.newCall(request).execute().body().string();
|
||||
ResponseBody responseBody = httpClient.newCall(request).execute().body();
|
||||
String response = responseBody.string();
|
||||
responseBody.close();
|
||||
Profile[] array = RedisBungee.getGson().fromJson(response, Profile[].class);
|
||||
for (Profile profile : array) {
|
||||
UUID uuid = UUIDFetcher.getUUID(profile.id);
|
@ -1,4 +1,4 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.util;
|
||||
package com.imaginarycode.minecraft.redisbungee.util.uuid;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.ImmutableMap;
|
@ -1,7 +1,7 @@
|
||||
package com.imaginarycode.minecraft.redisbungee.test;
|
||||
|
||||
import com.imaginarycode.minecraft.redisbungee.util.NameFetcher;
|
||||
import com.imaginarycode.minecraft.redisbungee.util.UUIDFetcher;
|
||||
import com.imaginarycode.minecraft.redisbungee.util.uuid.NameFetcher;
|
||||
import com.imaginarycode.minecraft.redisbungee.util.uuid.UUIDFetcher;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import org.junit.Test;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user