Module swim.io
Package swim.io

Interface Transport


  • public interface Transport
    I/O transport binding that handles asynchronous I/O operations for a non-blocking NIO channel. A Transport provides a selectable channel() on which to perform asynchronous I/O operations, along with an readBuffer() into which input data will be read, and an writeBuffer() from which data will be written.

    A Transport interfaces with the underlying asynchronous I/O system via a TransportContext. The transport context invokes I/O callbacks on the Transport when the underlying NIO channel is ready to perform I/O operations permitted by the transport context's FlowControl.

    • Method Summary

      Modifier and Type Method Description
      SelectableChannel channel()
      Returns the NIO channel that this Transport manages.
      void didClose()
      Lifecycle callback invoked by the transport context after the underlying transport has closed.
      void didFail​(Throwable error)
      Lifecycle callback invoked by the transport context when the underlying transport fails by throwing an error.
      void didTimeout()
      Lifecycle callback invoked by the transport context after the underlying transport has timed out.
      void didWrite()
      I/O callback invoked by the transport context after the underlying transport has completed writing all data in its writeBuffer, thereby completing the current write operation.
      void doAccept()
      I/O callback invoked by the transport context when the underlying transport is ready to complete an accept operation.
      void doConnect()
      I/O callback invoked by the transport context when the underlying transport is ready to complete a connect operation.
      void doRead()
      I/O callback invoked by the transport context asking this Transport to read input data out of the readBuffer, thereby completing a read operation from the underlying I/O transport.
      void doWrite()
      I/O callback invoked by the transport context asking this Transport to write output data into the writeBuffer, thereby initiating a write operation to the underlying I/O transport.
      long idleTimeout()
      Returns the number of idle milliseconds after which this Transport should be closed due to inactivity.
      ByteBuffer readBuffer()
      Returns the buffer into which input data should be read by the underlying I/O transport.
      void setTransportContext​(TransportContext context)
      Sets the I/O transport context to which this Transport is bound.
      TransportContext transportContext()
      Returns the I/O transport context to which this Transport is bound; returns null if this Transport is unbound.
      ByteBuffer writeBuffer()
      Returns the buffer from which output data should be written by the underlying I/O transport.
    • Method Detail

      • transportContext

        TransportContext transportContext()
        Returns the I/O transport context to which this Transport is bound; returns null if this Transport is unbound.
      • setTransportContext

        void setTransportContext​(TransportContext context)
        Sets the I/O transport context to which this Transport is bound.
      • channel

        SelectableChannel channel()
        Returns the NIO channel that this Transport manages.
      • readBuffer

        ByteBuffer readBuffer()
        Returns the buffer into which input data should be read by the underlying I/O transport.
      • writeBuffer

        ByteBuffer writeBuffer()
        Returns the buffer from which output data should be written by the underlying I/O transport.
      • idleTimeout

        long idleTimeout()
        Returns the number of idle milliseconds after which this Transport should be closed due to inactivity. Returns -1 if a default idle timeout should be used. Returns 0 if the underlying I/O transport should not time out.
      • doAccept

        void doAccept()
               throws IOException
        I/O callback invoked by the transport context when the underlying transport is ready to complete an accept operation.
        Throws:
        IOException
      • doConnect

        void doConnect()
                throws IOException
        I/O callback invoked by the transport context when the underlying transport is ready to complete a connect operation.
        Throws:
        IOException
      • doRead

        void doRead()
        I/O callback invoked by the transport context asking this Transport to read input data out of the readBuffer, thereby completing a read operation from the underlying I/O transport. May be invoked concurrently to other I/O callbacks, but never concurrently with other doRead calls.
      • doWrite

        void doWrite()
        I/O callback invoked by the transport context asking this Transport to write output data into the writeBuffer, thereby initiating a write operation to the underlying I/O transport. May be invoked concurrently to other I/O callbacks, but never concurrently with other doWrite or didWrite calls.
      • didWrite

        void didWrite()
        I/O callback invoked by the transport context after the underlying transport has completed writing all data in its writeBuffer, thereby completing the current write operation. May be invoked concurrently to other I/O callbacks, but never concurrently with other doWrite or didWrite calls.
      • didTimeout

        void didTimeout()
        Lifecycle callback invoked by the transport context after the underlying transport has timed out. The transport will automatically be closed.
      • didClose

        void didClose()
        Lifecycle callback invoked by the transport context after the underlying transport has closed.
      • didFail

        void didFail​(Throwable error)
        Lifecycle callback invoked by the transport context when the underlying transport fails by throwing an error. The transport will automatically be closed.