Interface Transport
- All Superinterfaces:
AutoCloseable
A single-use, ordered byte connection. It has no knowledge of MQTT packets.
All methods and listener callbacks must return promptly without waiting for I/O or capacity. Callbacks may occur inline. Received arrays transfer ownership to the listener; they must never be reused. Successful send admission transfers ownership of the array to the transport until onSent or onClosed; a rejected array remains the caller's. Neither side may mutate an admitted array. At most one send may be outstanding. Queuing, capacity limits, and admission policy belong to the caller, not the transport.
Callbacks are serialized. onConnected precedes bytes and send
completions. Bytes arrive in wire order with arbitrary chunk boundaries. Each successfully
written send must be reported exactly once through onSent, before onClosed, even if EOF,
failure, or a close request races with write completion. Shutdown must not discard a
successful write's pending notification.
Completion means successful local writing, not admission or confirmation of peer receipt.
The next send is allowed once onSent is invoked, including from that callback, unless closing.
A single final onClosed releases any send whose write did not complete successfully instead
of onSent. No callbacks follow it. Closing releases pending I/O and delayed work, including
a connection that finishes after close was requested.
Runtime exceptions from the factory, start, or send fail the current connection attempt or
connection without closing the client permanently. The client closes any created transport.
Close failures are logged and cleanup continues. Errors from the factory, start, or send
remain fatal to the client.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceCreates a client's transports, one for each connection; seeMqttClientBuilder.transportFactory(Transport.Factory).static interfaceReceives the serialized callbacks of one transport, asTransportdescribes.static enumThe immediate admission result; onlyTransport.SendResult.ACCEPTEDtransfers buffer ownership. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Requests shutdown.send(long ticket, byte[] bytes) Starts one write without waiting.voidstart(URI endpoint, Duration timeout, Transport.Listener listener) Starts this transport's only connection.static TransportCreates a plain TCP transport accepting onlymqttURIs (default port 1883).
-
Method Details
-
start
Starts this transport's only connection. The timeout bounds its establishment, including any TLS handshake, not subsequent reads. Implementations must reject unsupported URI schemes here withIllegalArgumentException, rather than silently use a different transport.- Parameters:
endpoint- the URI to connect totimeout- the bound on establishing the connectionlistener- the listener for this connection's callbacks
-
send
Starts one write without waiting. Call afterTransport.Listener.onConnected()has been invoked and after any previous send has completed. Completion may be notified before this returns.Transport.SendResult.CLOSEDincludes shutdown in progress. Once started, the transport reports its cause through exactly oneTransport.Listener.onClosed(Throwable)callback, which may already have arrived.- Parameters:
ticket- the caller's identifier for this send, whichTransport.Listener.onSent(long)reportsbytes- the bytes to write- Returns:
the immediate admission result- Throws:
IllegalStateException-if not yet connected or a send is outstanding, unless closing or closed
-
close
void close()Requests shutdown. Safe before start, concurrent with other methods, and idempotent.- Specified by:
closein interfaceAutoCloseable
-
tcp
Creates a plain TCP transport accepting onlymqttURIs (default port 1883). The client identifier is used for diagnostics. Its deadlines use real time, not the scheduler passed toMqttClientBuilder.timerScheduler(TimerScheduler).- Parameters:
clientId- the client identifier- Returns:
a new transport, not yet started
-