Class WebsocketEndpoint

java.lang.Object
io.fluxzero.testserver.websocket.WebsocketEndpoint
Direct Known Subclasses:
ConsumerEndpoint, EventSourcingEndpoint, KeyValueEndPoint, ProducerEndpoint, SchedulingEndpoint, SearchEndpoint

public abstract class WebsocketEndpoint extends Object
  • Field Details

    • ESTIMATED_RESULT_OVERHEAD_BYTES

      protected static final int ESTIMATED_RESULT_OVERHEAD_BYTES
      See Also:
    • webSocketSendTimeout

      protected static Duration webSocketSendTimeout
    • pingTimeout

      protected static Duration pingTimeout
    • pingDelay

      protected static Duration pingDelay
    • shuttingDown

      protected final AtomicBoolean shuttingDown
    • shutDown

      protected volatile boolean shutDown
  • Constructor Details

    • WebsocketEndpoint

      protected WebsocketEndpoint()
    • WebsocketEndpoint

      protected WebsocketEndpoint(CommandIdempotencyStore commandIdempotencyStore)
    • WebsocketEndpoint

      protected WebsocketEndpoint(Executor requestExecutor)
    • WebsocketEndpoint

      protected WebsocketEndpoint(Executor requestExecutor, CommandIdempotencyStore commandIdempotencyStore)
  • Method Details

    • onOpen

      public void onOpen(ServerWebsocketSession session)
      Registers an accepted session, its command-idempotency state and result backlog, emits connection metrics, and schedules a ping. Rejects new sessions during shutdown.
    • deserializeRequest

      protected io.fluxzero.common.api.JsonType deserializeRequest(ServerWebsocketSession session, byte[] bytes) throws IOException
      Throws:
      IOException
    • onMessage

      public void onMessage(byte[] bytes, ServerWebsocketSession session)
      Deserializes and dispatches an incoming binary request for the session, logging failures that escape dispatch.
    • dispatchRequest

      protected void dispatchRequest(ServerWebsocketSession session, io.fluxzero.common.api.JsonType request)
    • dispatchRequest

      protected void dispatchRequest(ServerWebsocketSession session, io.fluxzero.common.api.JsonType request, long requestReceivedTimestamp)
    • shouldHandleIdempotently

      protected boolean shouldHandleIdempotently(io.fluxzero.common.api.Command command)
    • submitRequestTask

      protected boolean submitRequestTask(ServerWebsocketSession session, io.fluxzero.common.api.JsonType request, Runnable task)
    • isSessionActive

      protected boolean isSessionActive(String sessionId)
      Returns whether this endpoint still owns the session's request lifecycle.
    • handleMessage

      protected void handleMessage(ServerWebsocketSession session, io.fluxzero.common.api.JsonType message)
    • handleMessage

      protected void handleMessage(ServerWebsocketSession session, io.fluxzero.common.api.JsonType message, long requestReceivedTimestamp)
    • doSendResult

      protected void doSendResult(ServerWebsocketSession session, io.fluxzero.common.api.RequestResult result)
    • createTasks

      protected Stream<Runnable> createTasks(io.fluxzero.common.api.RequestBatch<?> batch, ServerWebsocketSession session)
    • createTasks

      protected Stream<Runnable> createTasks(io.fluxzero.common.api.RequestBatch<?> batch, ServerWebsocketSession session, long requestReceivedTimestamp)
    • sendResultBatch

      protected void sendResultBatch(ServerWebsocketSession session, List<io.fluxzero.common.api.RequestResult> results)
    • sendResultBatchAsync

      protected CompletableFuture<Void> sendResultBatchAsync(ServerWebsocketSession session, List<io.fluxzero.common.api.RequestResult> results)
    • estimateRequestResultBytes

      protected int estimateRequestResultBytes(io.fluxzero.common.api.RequestResult result)
      Estimates one endpoint-specific request result for websocket batch sizing.
    • estimateStringBytes

      protected static int estimateStringBytes(String value)
    • findAlternativeBacklog

      protected Optional<WebsocketEndpoint.SessionBacklog> findAlternativeBacklog(ServerWebsocketSession closedSession)
    • schedulePing

    • sendPing

      protected void sendPing(ServerWebsocketSession session)
    • onPong

      public void onPong(ByteBuffer message, ServerWebsocketSession session)
      Acknowledges a pong by cancelling the pending ping deadline and scheduling the next ping for an active ping registration.
    • abort

      protected void abort(ServerWebsocketSession session, String reason)
    • onClose

      public void onClose(ServerWebsocketSession session, io.fluxzero.sdk.common.websocket.WebsocketCloseReason closeReason)
      Removes session, command-idempotency, backlog, and ping bookkeeping and reports disconnection when appropriate for the transport-close lifecycle.
    • onError

      public void onError(ServerWebsocketSession session, Throwable e)
      Classifies and logs a transport error, aborts the session, and always performs close cleanup.
    • shutDown

      protected void shutDown()
      Close all sessions on the websocket after an optional delay. During the delay we don't handle new requests but will be able to send back results.
    • newRequestStripeExecutors

      protected ExecutorService[] newRequestStripeExecutors(int stripes)
    • getCompressionAlgorithm

      protected io.fluxzero.common.serialization.compression.CompressionAlgorithm getCompressionAlgorithm(ServerWebsocketSession session)
    • getTransportFormat

      protected io.fluxzero.common.websocket.WebSocketTransportFormat getTransportFormat(ServerWebsocketSession session)
    • transportCodec

      protected io.fluxzero.common.websocket.WebSocketTransportCodec transportCodec(ServerWebsocketSession session)
    • payloadCodecs

      protected List<? extends io.fluxzero.common.websocket.WebSocketPayloadCodec> payloadCodecs()
      Returns compact payload codecs owned by this concrete endpoint protocol.
    • getRequestHeaders

      protected Map<String, List<String>> getRequestHeaders(ServerWebsocketSession session)
    • getNamespace

      protected String getNamespace(ServerWebsocketSession session)
    • getClientId

      protected String getClientId(ServerWebsocketSession session)
    • getClientName

      protected String getClientName(ServerWebsocketSession session)
    • getClientSdkVersion

      protected String getClientSdkVersion(ServerWebsocketSession session)
    • getRuntimeVersion

      protected String getRuntimeVersion()
    • getNegotiatedSessionId

      protected String getNegotiatedSessionId(ServerWebsocketSession session)
    • registerMetrics

      protected void registerMetrics(Object event, ServerWebsocketSession session)
    • sessionMetadata

      protected io.fluxzero.common.api.Metadata sessionMetadata(ServerWebsocketSession session)