mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
feat(gateway): support assign hostname on websocket gateway
This commit is contained in:
@@ -34,11 +34,13 @@ public class WebSocketGateway extends WebSocketServer implements AgentGateway<In
|
||||
// 记录最后一次收到Pong的时间
|
||||
private final ConcurrentHashMap<WebSocket, Long> lastPongTimes = new ConcurrentHashMap<>();
|
||||
|
||||
public WebSocketGateway(int port, long heartbeatInterval) {
|
||||
super(new InetSocketAddress(port));
|
||||
public WebSocketGateway(int port, @NotNull String hostname, long heartbeatInterval) {
|
||||
super(new InetSocketAddress(hostname, port));
|
||||
this.heartbeatInterval = heartbeatInterval;
|
||||
this.setReuseAddr(true);
|
||||
this.executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
log.info("WebSocketGateway started on {}: {}", hostname, port);
|
||||
}
|
||||
|
||||
public void launch() {
|
||||
|
||||
@@ -10,9 +10,10 @@ object WebSocketGatewayRegistration : AgentGatewayRegistration {
|
||||
override fun create(params: Map<String, String>): AgentGateway<*, *> {
|
||||
val port = params["port"]?.toIntOrNull() ?: 29600
|
||||
val heartbeatInterval = params["heartbeat_interval"]?.toLongOrNull() ?: 10_000L
|
||||
val hostname = params["hostname"] ?: "127.0.0.1"
|
||||
require(port > 0) { "port must be greater than 0" }
|
||||
require(heartbeatInterval > 0) { "heartbeat_interval must be greater than 0" }
|
||||
return WebSocketGateway(port, heartbeatInterval)
|
||||
return WebSocketGateway(port, hostname, heartbeatInterval)
|
||||
}
|
||||
|
||||
override fun shutdown(instance: AgentGateway<*, *>) {
|
||||
|
||||
Reference in New Issue
Block a user