java.lang.Object
org.miaixz.bus.http.plugin.httpv.CoverCall
- All Implemented Interfaces:
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 ClassesModifier and TypeClassDescriptionstatic classA client for creating and configuring WebSocket connections.static classEncapsulates information about a WebSocket closure.static classA WebSocket listener that bridges Httpd's WebSocket events to the CoverCall's event system.static classRepresents an incoming WebSocket message, which can be either text or binary.static interfaceA functional interface for handling WebSocket events. -
Constructor Summary
ConstructorsConstructorDescriptionCoverCall(CoverTasks.Executor executor, String msgType) Constructs a new CoverCall. -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel()Cancels the WebSocket connection immediately.booleanAttempts to close the WebSocket connection gracefully.voidSets the default message type for object serialization.longReturns the number of messages queued to be sent.booleanEnqueues a message to be sent over the WebSocket.voidsetCharset(Charset charset) Sets the character set to be used for message serialization.
-
Constructor Details
-
CoverCall
Constructs a new CoverCall.- Parameters:
executor- The task executor.msgType- The default message type for serialization.
-
-
Method Details
-
setCharset
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:
cancelin interfaceCancelable- Returns:
trueif the cancellation was initiated.
-
close
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:
trueif the closure was initiated.
-
msgType
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
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:
trueif the message was accepted for sending.
-