mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 03:05:34 +00:00
Use every thread available to the JVM, in a work stealing pool for packet handling
This commit is contained in:
parent
3c3adea406
commit
23aff95a2e
@ -1,7 +1,5 @@
|
||||
package emu.grasscutter.server.game;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.GAME_INFO;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.Grasscutter.ServerDebugMode;
|
||||
import emu.grasscutter.net.packet.*;
|
||||
@ -9,6 +7,8 @@ import emu.grasscutter.server.event.game.ReceivePacketEvent;
|
||||
import emu.grasscutter.server.game.GameSession.SessionState;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
|
||||
import static emu.grasscutter.config.Configuration.GAME_INFO;
|
||||
|
||||
public final class GameServerPacketHandler {
|
||||
private final Int2ObjectMap<PacketHandler> handlers;
|
||||
|
||||
@ -76,13 +76,11 @@ public final class GameServerPacketHandler {
|
||||
}
|
||||
|
||||
// Invoke event.
|
||||
ReceivePacketEvent event = new ReceivePacketEvent(session, opcode, payload);
|
||||
event.call();
|
||||
if (!event.isCanceled()) // If event is not canceled, continue.
|
||||
handler.handle(session, header, event.getPacketData());
|
||||
var event = new ReceivePacketEvent(session, opcode, payload);
|
||||
if (!event.call()) // If event is not canceled, continue.
|
||||
handler.handle(session, header, event.getPacketData());
|
||||
} catch (Exception ex) {
|
||||
// TODO Remove this when no more needed
|
||||
ex.printStackTrace();
|
||||
Grasscutter.getLogger().warn("Unable to handle packet.", ex);
|
||||
}
|
||||
return; // Packet successfully handled
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public final class GameSessionManager implements KcpListener {
|
||||
@Getter private static final GameSessionManager instance
|
||||
= new GameSessionManager();
|
||||
@Getter private static final ExecutorService executor
|
||||
= Executors.newFixedThreadPool(4);
|
||||
= Executors.newWorkStealingPool();
|
||||
@Getter private static final Map<Ukcp, GameSession> sessions
|
||||
= new ConcurrentHashMap<>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user