Class MagicWebSocketClient
java.lang.Object
dev.ua.theroer.magicutils.http.MagicWebSocketClient
- All Implemented Interfaces:
AutoCloseable
MagicUtils WebSocket client with config defaults and logging.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic MagicWebSocketClient.BuilderCreates a builder without auto-loading configuration.static MagicWebSocketClient.Builderbuilder(Platform platform, ConfigManager configManager) Creates a builder that loads configuration from the provided manager.voidclose()connect(String path, WebSocket.Listener listener) Connects to a WebSocket endpoint (blocking).connectAsync(String path, WebSocket.Listener listener) Connects to a WebSocket endpoint asynchronously.connectSmart(String path, WebSocket.Listener listener) Connects to a WebSocket endpoint, switching to async on blocking-sensitive threads.
-
Method Details
-
builder
Creates a builder that loads configuration from the provided manager.- Parameters:
platform- platform used for loggingconfigManager- configuration manager used to registerHttpClientConfig- Returns:
- a new builder instance
-
builder
Creates a builder without auto-loading configuration.- Parameters:
platform- platform used for logging- Returns:
- a new builder instance
-
connectAsync
Connects to a WebSocket endpoint asynchronously.- Parameters:
path- absolute URL or a path resolved against base URLlistener- websocket listener- Returns:
- future with WebSocket
-
connect
public WebSocket connect(String path, WebSocket.Listener listener) throws IOException, InterruptedException Connects to a WebSocket endpoint (blocking).- Parameters:
path- absolute URL or a path resolved against base URLlistener- websocket listener- Returns:
- connected WebSocket
- Throws:
IOException- if connection failsInterruptedException- if thread interrupted
-
connectSmart
Connects to a WebSocket endpoint, switching to async on blocking-sensitive threads.- Parameters:
path- absolute URL or a path resolved against base URLlistener- websocket listener- Returns:
- future with WebSocket
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-