Class WsClient

java.lang.Object
io.karatelabs.http.WsClient
All Implemented Interfaces:
io.karatelabs.common.Stoppable, AutoCloseable

public class WsClient extends Object implements io.karatelabs.common.Stoppable
Protocol-agnostic WebSocket client built on Netty.
  • Method Details

    • closeAll

      public static void closeAll()
    • shutdownCallbackExecutor

      public static void shutdownCallbackExecutor()
      Shut down the callback pool shared by every client that did not supply its own. Deliberately not a KarateLifecycle registrant: the pool is process-wide and outlives any one client, so draining it from a generic shutdown would silently drop the callbacks of clients connected afterwards. Its threads are daemons, so leaving it running never holds up JVM exit — call this only when no further websocket use is expected.
    • connect

      public static WsClient connect(String uri)
    • connect

      public static WsClient connect(URI uri)
    • connect

      public static WsClient connect(WsClientOptions options)
    • isOpen

      public boolean isOpen()
    • getUri

      public URI getUri()
    • getNegotiatedSubprotocol

      public String getNegotiatedSubprotocol()
    • send

      public void send(String text)
    • send

      public void send(byte[] binary)
    • send

      public void send(WsFrame frame)
    • sendAsync

      public CompletableFuture<Void> sendAsync(WsFrame frame)
    • onMessage

      public void onMessage(Consumer<WsFrame> listener)
    • onClose

      public void onClose(Runnable listener)
    • onError

      public void onError(Consumer<Throwable> listener)
    • lifecycleName

      public String lifecycleName()
      Specified by:
      lifecycleName in interface io.karatelabs.common.Stoppable
    • lifecycleKind

      public String lifecycleKind()
      Specified by:
      lifecycleKind in interface io.karatelabs.common.Stoppable
    • stop

      public void stop()
      The graceful stop is close() — a close frame to the peer, then the event loop wound down. Idempotent: a client already closed (or closed by the peer) does nothing.
      Specified by:
      stop in interface io.karatelabs.common.Stoppable
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface io.karatelabs.common.Stoppable
    • closeNow

      public void closeNow()
    • waitSync

      public void waitSync()
    • ping

      public void ping()