diff options
Diffstat (limited to 'mod/src/main/java/kr')
14 files changed, 78 insertions, 33 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java index e7eb4bd6..7a7ba7fb 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java @@ -82,7 +82,9 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.Method; import java.util.*; +import java.util.concurrent.ExecutorService; import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; public class DungeonsGuide implements DGInterface { @@ -151,12 +153,18 @@ public class DungeonsGuide implements DGInterface { MinecraftForge.EVENT_BUS.register(object); } private List<ICommand> registeredCommands = new ArrayList<>(); + private List<ExecutorService> executorServices = new ArrayList<>(); public void registerCommands(ICommand command) { registeredCommands.add(command); ClientCommandHandler.instance.registerCommand(command); } + public ExecutorService registerExecutorService(ExecutorService executorService) { + this.executorServices.add(executorService); + return executorService; + } + private PacketInjector packetInjector; public void init(File f) { @@ -293,6 +301,7 @@ public class DungeonsGuide implements DGInterface { @Override public void unload() { + StompManager.getInstance().cleanup(); // have FUN! for (Object registeredListener : registeredListeners) { @@ -399,9 +408,13 @@ public class DungeonsGuide implements DGInterface { e.printStackTrace(); } ShaderManager.unload(); - + GLCursors.cleanup(); DiscordIntegrationManager.INSTANCE.cleanup(); + for (ExecutorService executorService : executorServices) { + executorService.shutdownNow(); + } + THREAD_GROUP.interrupt(); THREAD_GROUP.stop(); try { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java index f25515ca..6012a24a 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/DiscordIntegrationManager.java @@ -61,7 +61,6 @@ public class DiscordIntegrationManager implements IPCListener { ipcClient = new IPCClient(816298079732498473L, DungeonsGuide.THREAD_FACTORY); t.start(); } - @Getter private final Map<Long, JDiscordRelation> relationMap = new HashMap<>(); @@ -278,7 +277,9 @@ public class DiscordIntegrationManager implements IPCListener { public void cleanup() { - ipcClient.close(); + try { + ipcClient.close(); + } catch (Exception e) {e.printStackTrace();} this.t.interrupt(); ipcClient = null; } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonRoomScaffoldParser.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonRoomScaffoldParser.java index 6cd046cd..1dad5b43 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonRoomScaffoldParser.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/map/DungeonRoomScaffoldParser.java @@ -48,12 +48,6 @@ public class DungeonRoomScaffoldParser { @Getter private MapData latestMapData; - - - ExecutorService es = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder() - .setThreadFactory(DungeonsGuide.THREAD_FACTORY) - .setNameFormat("Dg-MapPlayerProcessor-%d").build()); - @Getter private final Map<Point, DungeonRoom> roomMap = new HashMap<>(); @Getter diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoom.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoom.java index 166e6724..435d8bc6 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoom.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/dungeon/roomfinder/DungeonRoom.java @@ -19,6 +19,7 @@ package kr.syeyoung.dungeonsguide.mod.dungeon.roomfinder; import com.google.common.collect.Sets; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoomInfo; import kr.syeyoung.dungeonsguide.dungeon.mechanics.DungeonRoomDoor; import kr.syeyoung.dungeonsguide.dungeon.mechanics.dunegonmechanic.DungeonMechanic; @@ -47,6 +48,7 @@ import lombok.Getter; import lombok.Setter; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; import net.minecraft.util.*; import net.minecraft.world.ChunkCache; import net.minecraft.world.World; @@ -120,7 +122,10 @@ public class DungeonRoom { context.getExecutors().add(executor); return executor; } - private static final ExecutorService roomMatcherThread = Executors.newSingleThreadExecutor( DungeonsGuide.THREAD_FACTORY); + private static final ExecutorService roomMatcherThread = DungeonsGuide.getDungeonsGuide().registerExecutorService(Executors.newSingleThreadExecutor( + new ThreadFactoryBuilder() + .setThreadFactory(DungeonsGuide.THREAD_FACTORY) + .setNameFormat("DG-RoomMatcher-%d").build())); @Getter private final Map<String, Object> roomContext = new HashMap<>(); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureTestPeople.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureTestPeople.java index 771ef5d2..9f2b6a1a 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureTestPeople.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/advanced/FeatureTestPeople.java @@ -18,6 +18,7 @@ package kr.syeyoung.dungeonsguide.mod.features.impl.advanced; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; @@ -180,7 +181,9 @@ public class FeatureTestPeople extends RawRenderingGuiFeature { - ExecutorService executor = Executors.newFixedThreadPool(5, DungeonsGuide.THREAD_FACTORY); + ExecutorService executor = DungeonsGuide.getDungeonsGuide().registerExecutorService(Executors.newFixedThreadPool(5, new ThreadFactoryBuilder() + .setThreadFactory(DungeonsGuide.THREAD_FACTORY) + .setNameFormat("DG-FeatureTestPeople-%d").build())); public ItemStack getSkullByUserName(String username) { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java index de4b390b..5ea37c96 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/discord/inviteViewer/PartyInviteViewer.java @@ -65,8 +65,6 @@ public class PartyInviteViewer extends AbstractGuiFeature { } catch (Throwable e) {e.printStackTrace();} } - ExecutorService executorService = Executors.newFixedThreadPool(3, DungeonsGuide.THREAD_FACTORY); - @DGEventHandler(triggerOutOfSkyblock = true) public void onDiscordUserJoinRequest(DiscordUserJoinRequestEvent event) { partyInviteViewer.addJoinRequest(event); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/party/playerpreview/api/ApiFetcher.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/party/playerpreview/api/ApiFetcher.java index 397161ec..1c234f59 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/party/playerpreview/api/ApiFetcher.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/impl/party/playerpreview/api/ApiFetcher.java @@ -18,6 +18,7 @@ package kr.syeyoung.dungeonsguide.mod.features.impl.party.playerpreview.api; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -51,7 +52,9 @@ public class ApiFetcher { private static final Map<String, CachedData<String>> UIDtoNickname = new ConcurrentHashMap<>(); private static final Map<String, CachedData<GameProfile>> UIDtoGameProfile = new ConcurrentHashMap<>(); - public static final ExecutorService ex = Executors.newFixedThreadPool(4, DungeonsGuide.THREAD_FACTORY); + public static final ExecutorService ex = DungeonsGuide.getDungeonsGuide().registerExecutorService(Executors.newFixedThreadPool(4, new ThreadFactoryBuilder() + .setThreadFactory(DungeonsGuide.THREAD_FACTORY) + .setNameFormat("DG-APIFetcher-%d").build())); private static final Set<String> invalidKeys = new HashSet<>(); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/image/ImageTexture.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/image/ImageTexture.java index e78c143e..4db364d0 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/image/ImageTexture.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/elements/image/ImageTexture.java @@ -19,6 +19,7 @@ package kr.syeyoung.dungeonsguide.mod.guiv2.elements.image; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; import lombok.Data; import net.minecraft.client.Minecraft; @@ -148,7 +149,9 @@ public class ImageTexture { tessellator.draw(); } - public static final ExecutorService executorService = Executors.newFixedThreadPool(3, DungeonsGuide.THREAD_FACTORY); + public static final ExecutorService executorService = DungeonsGuide.getDungeonsGuide().registerExecutorService(Executors.newFixedThreadPool(3, new ThreadFactoryBuilder() + .setThreadFactory(DungeonsGuide.THREAD_FACTORY) + .setNameFormat("DG-ImageFetcher-%d").build())); public static final Map<String, ImageTexture> imageMap = new HashMap<>(); public static final Logger logger = LogManager.getLogger("DG-ImageLoader"); public static void loadImage(String url, Consumer<ImageTexture> callback) { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompClient.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompClient.java index 50e63f7f..4de6b258 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompClient.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompClient.java @@ -18,6 +18,7 @@ package kr.syeyoung.dungeonsguide.mod.stomp; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; import lombok.Getter; import net.minecraftforge.common.MinecraftForge; @@ -62,7 +63,10 @@ public class StompClient extends WebSocketClient { private ScheduledFuture heartbeat = null; - private static final ScheduledExecutorService ex = Executors.newScheduledThreadPool(1, DungeonsGuide.THREAD_FACTORY); + private static final ScheduledExecutorService ex = Executors.newScheduledThreadPool(1, + new ThreadFactoryBuilder() + .setThreadFactory(DungeonsGuide.THREAD_FACTORY) + .setNameFormat("DG-StompClient-%d").build()); @Override public void onOpen(ServerHandshake handshakeData) { send(new StompPayload().method(StompHeader.CONNECT) @@ -130,7 +134,7 @@ public class StompClient extends WebSocketClient { @Override public void onClose(int code, String reason, boolean remote) { if (heartbeat != null) heartbeat.cancel(true); - + ex.shutdownNow(); MinecraftForge.EVENT_BUS.post(new StompDiedEvent(code, reason, remote)); StompManager.getInstance().onStompDied(new StompDiedEvent(code, reason, remote)); } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompManager.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompManager.java index e1a0baad..6c2a7fcc 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompManager.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/stomp/StompManager.java @@ -19,6 +19,7 @@ package kr.syeyoung.dungeonsguide.mod.stomp; import com.google.common.base.Throwables; +import com.google.common.util.concurrent.ThreadFactoryBuilder; import kr.syeyoung.dungeonsguide.launcher.auth.AuthManager; import kr.syeyoung.dungeonsguide.mod.DungeonsGuide; import kr.syeyoung.dungeonsguide.mod.events.impl.StompConnectedEvent; @@ -63,9 +64,13 @@ public class StompManager { } } - ScheduledExecutorService ex = Executors.newSingleThreadScheduledExecutor(DungeonsGuide.THREAD_FACTORY); + ScheduledExecutorService ex = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder() + .setThreadFactory(DungeonsGuide.THREAD_FACTORY) + .setNameFormat("DG-StompManager-%d").build()); + private volatile boolean disconnecting = false; public void onStompDied(StompDiedEvent event) { + if (disconnecting) return; logger.info("Stomp Connection closed, trying to reconnect - {} - {}", event.reason, event.code); connectStomp(); } @@ -84,4 +89,13 @@ public class StompManager { } }, 5L, TimeUnit.SECONDS); } + + public void cleanup() { + if (stompConnection != null) { + disconnecting = true; + stompConnection.disconnect(); + } + + ex.shutdownNow(); + } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/Foundation.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/Foundation.java index 7474c85a..1184d446 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/Foundation.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/Foundation.java @@ -24,9 +24,6 @@ import com.sun.jna.Pointer; public interface Foundation extends Library { - Foundation INSTANCE = (Foundation) Native.loadLibrary("Foundation", - Foundation.class); - Pointer objc_getClass(String className); Pointer sel_registerName(String selectorName); Pointer objc_msgSend(Pointer receiver, Pointer selector, Object... args); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/GLCursors.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/GLCursors.java index fda036f2..c0baf538 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/GLCursors.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/GLCursors.java @@ -21,11 +21,13 @@ package kr.syeyoung.dungeonsguide.mod.utils.cursor; import com.google.common.base.Throwables; import com.sun.jna.Native; +import com.sun.jna.NativeLibrary; import com.sun.jna.Pointer; import kr.syeyoung.dungeonsguide.mod.utils.RenderUtils; import net.minecraft.client.Minecraft; import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.ReflectionHelper; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.BufferUtils; @@ -42,10 +44,7 @@ import java.lang.reflect.InvocationTargetException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.IntBuffer; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @@ -182,8 +181,21 @@ public class GLCursors { return enumCursorCursorMap.get(enumCursor); } + public static void cleanup() { + F_INSTANCE = null; U_INSTANCE = null; X_INSTANCE = null; + + Map<Class, ?> blah = ReflectionHelper.getPrivateValue(Native.class, null, "typeOptions"); + blah.remove(Foundation.class); + blah.remove(User32.class); + blah.remove(X11.class); + } + + private static Foundation F_INSTANCE; + private static User32 U_INSTANCE; + private static X11 X_INSTANCE; private static Cursor createCursorWindows(int cursor) throws LWJGLException, InstantiationException, InvocationTargetException, IllegalAccessException { - User32 user32 = User32.INSTANCE; + if (U_INSTANCE == null) U_INSTANCE= Native.loadLibrary("User32", User32.class); + User32 user32 = U_INSTANCE; Pointer hIcon = user32 .LoadCursorW(Pointer.NULL, cursor); long ptrVal = Pointer.nativeValue(hIcon); @@ -203,15 +215,17 @@ public class GLCursors { return createCursor(handle); } private static Cursor createCursorLinux(int cursor) throws LWJGLException, InstantiationException, InvocationTargetException, IllegalAccessException { - X11.Display display = X11.INSTANCE.XOpenDisplay(null); - Pointer fontCursor = X11.INSTANCE.XCreateFontCursor(display, cursor); + if (X_INSTANCE == null) X_INSTANCE= Native.loadLibrary("X11", X11.class); + X11.Display display = X_INSTANCE.XOpenDisplay(null); + Pointer fontCursor = X_INSTANCE.XCreateFontCursor(display, cursor); long iconPtr = Pointer.nativeValue(fontCursor); return createCursor(iconPtr); } private static Cursor createCursorMac(String cursor) throws LWJGLException, InstantiationException, InvocationTargetException, IllegalAccessException { // trust me, it's horrible. - Foundation foundation = Foundation.INSTANCE; + if (F_INSTANCE == null) F_INSTANCE = Native.loadLibrary("Foundation", Foundation.class); + Foundation foundation = F_INSTANCE; Pointer nsCursor = foundation.objc_getClass("NSCursor"); Pointer selector = foundation.sel_registerName(cursor); Pointer thePointer = foundation.objc_msgSend(nsCursor, selector); diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/User32.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/User32.java index dfbbc03d..e812319b 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/User32.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/User32.java @@ -24,9 +24,6 @@ import com.sun.jna.Pointer; public interface User32 extends Library { - public static User32 INSTANCE = (User32) Native - .loadLibrary("User32", User32.class); - /** @see #LoadCursorW(Pointer, int) */ public static final int IDC_ARROW = 32512; /** @see #LoadCursorW(Pointer, int) */ diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/X11.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/X11.java index dc5a8894..57da9ec0 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/X11.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/utils/cursor/X11.java @@ -24,7 +24,6 @@ import com.sun.jna.Pointer; import com.sun.jna.PointerType; public interface X11 extends Library { - X11 INSTANCE = (X11) Native.loadLibrary("X11", X11.class); public Pointer XCreateFontCursor(Display display, int shape); public Display XOpenDisplay(String var1); |