Module bus.http

Class CoverCall

java.lang.Object
org.miaixz.bus.http.plugin.httpv.CoverCall
All Implemented Interfaces:
Cancelable

public class CoverCall extends Object implements Cancelable
Represents an active or pending WebSocket call. This class provides methods to send messages, cancel the connection, and close it gracefully. It also queues messages sent before the WebSocket is fully open.
Since:
Java 17+
Author:
Kimi Liu
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A client for creating and configuring WebSocket connections.
    static class 
    Encapsulates information about a WebSocket closure.
    static class 
    A WebSocket listener that bridges Httpd's WebSocket events to the CoverCall's event system.
    static class 
    Represents an incoming WebSocket message, which can be either text or binary.
    static interface 
    A functional interface for handling WebSocket events.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CoverCall(CoverTasks.Executor executor, String msgType)
    Constructs a new CoverCall.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Cancels the WebSocket connection immediately.
    boolean
    close(int code, String reason)
    Attempts to close the WebSocket connection gracefully.
    void
    Sets the default message type for object serialization.
    long
    Returns the number of messages queued to be sent.
    boolean
    send(Object msg)
    Enqueues a message to be sent over the WebSocket.
    void
    Sets the character set to be used for message serialization.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CoverCall

      public CoverCall(CoverTasks.Executor executor, String msgType)
      Constructs a new CoverCall.
      Parameters:
      executor - The task executor.
      msgType - The default message type for serialization.
  • Method Details

    • setCharset

      public void setCharset(Charset charset)
      Sets the character set to be used for message serialization.
      Parameters:
      charset - The character set.
    • cancel

      public boolean cancel()
      Cancels the WebSocket connection immediately. Any queued messages that have not been transmitted will be discarded.
      Specified by:
      cancel in interface Cancelable
      Returns:
      true if the cancellation was initiated.
    • close

      public boolean close(int code, String reason)
      Attempts to close the WebSocket connection gracefully.
      Parameters:
      code - The closing status code (e.g., 1000 for normal closure).
      reason - A descriptive reason for closing.
      Returns:
      true if the closure was initiated.
    • msgType

      public void msgType(String type)
      Sets the default message type for object serialization.
      Parameters:
      type - The message type (e.g., "json"). Cannot be "form".
      Throws:
      IllegalArgumentException - if the type is null or "form".
    • queueSize

      public long queueSize()
      Returns the number of messages queued to be sent.
      Returns:
      The queue size.
    • send

      public boolean send(Object msg)
      Enqueues a message to be sent over the WebSocket. If the connection is not yet open, the message is queued internally.
      Parameters:
      msg - The message to send (can be String, ByteString, byte[], or a serializable object).
      Returns:
      true if the message was accepted for sending.