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