Class WsSession
java.lang.Object
com.alibaba.dashscope.transport.ws.WsSession
- All Implemented Interfaces:
TaskChannel,AutoCloseable
A single task over a dedicated WebSocket (audio design §3). No SDK-spawned threads: OkHttp's
socket reader hands events into a queue and
recv(java.time.Duration) blocks the caller's thread on it.
Events whose task_id differs from this session's task are protocol errors.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationHandshake (ws upgrade) timeout; audio design §5. -
Constructor Summary
ConstructorsConstructorDescriptionWsSession(HttpTransport transport, String url, String taskId, String module, RequestOptions options) WsSession(HttpTransport transport, String url, String taskId, String module, RequestOptions options, int maxQueueCapacity, Duration connectTimeout) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Idempotent: graceful 1000 close.static RuntimeExceptionmapFailure(Throwable t, okhttp3.Response response) Maps a websocket failure to the exception family; reused by the realtime session.Next inbound item for this task, blocking up totimeout;nullon timeout.voidsendBinary(ByteBuffer data) Send a raw binary frame (no header; ownership rules apply on shared connections).voidSend a text frame (already-serialized JSON).taskId()
-
Field Details
-
DEFAULT_CONNECT_TIMEOUT
Handshake (ws upgrade) timeout; audio design §5.
-
-
Constructor Details
-
WsSession
public WsSession(HttpTransport transport, String url, String taskId, String module, RequestOptions options) -
WsSession
public WsSession(HttpTransport transport, String url, String taskId, String module, RequestOptions options, int maxQueueCapacity, Duration connectTimeout) - Parameters:
maxQueueCapacity- 0 = unbounded downlink queue; overflow raises QueueCapacityExceeded.
-
-
Method Details
-
taskId
- Specified by:
taskIdin interfaceTaskChannel
-
sendText
Description copied from interface:TaskChannelSend a text frame (already-serialized JSON). Full upstream queue → SdkException.- Specified by:
sendTextin interfaceTaskChannel
-
sendBinary
Description copied from interface:TaskChannelSend a raw binary frame (no header; ownership rules apply on shared connections).- Specified by:
sendBinaryin interfaceTaskChannel
-
recv
Description copied from interface:TaskChannelNext inbound item for this task, blocking up totimeout;nullon timeout. FAILURE events throw their carried exception.- Specified by:
recvin interfaceTaskChannel
-
close
public void close()Idempotent: graceful 1000 close. Safe to call from any thread, any number of times.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTaskChannel
-
mapFailure
Maps a websocket failure to the exception family; reused by the realtime session.
-