Interface FrameSink


public interface FrameSink
A transport's outbound side, handed to ServerBus.connect(BusSession, FrameSink) for one connection.

offer(String) must not block: it queues the frame and returns at once, or returns false when the connection's queue (bounded by BusPolicy.maxQueuedFrames()) is full. On false the bus detaches the sink and calls close(int, String) with 4429 / bus:slow-consumer.

close(int, String) must not block either: the bus calls it while holding its lock. A transport that needs a network handshake to close must hand the close off to another thread.

Close codes the bus uses: 1001 bus:closed (ServerBus.close()), 4401 bus:unknown-session (expired), 4409 bus:replaced (a second connection took over the session) and 4429 bus:slow-consumer. A transport without close codes (SSE) ends its response instead.

Example:

// A test double that records what the bus sends: List<String> frames = new ArrayList<>(); FrameSink sink = new FrameSink() { @Override public boolean offer(String frame) { return frames.add(frame); } @Override public void close(int code, String reason) { } }; bus.connect(session, sink); // resync-begin, retained pubs, resync-end

Since:
10.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    close(int code, String reason)
    Closes the connection.
    boolean
    offer(String frame)
    Queues one encoded frame for sending.
  • Method Details

    • offer

      boolean offer(String frame)
      Queues one encoded frame for sending. Must not block.
      Parameters:
      frame - The encoded frame (see BusFrames).
      Returns:
      false when the connection's queue is full or the sink is closed.
    • close

      void close(int code, String reason)
      Closes the connection. Called at most once by the bus for a given sink; must be safe to call again.
      Parameters:
      code - The close code (1001, 4401, 4409 or 4429).
      reason - The bus:* reason.