Module swim.io
Package swim.io

Interface Socket

  • All Known Implementing Classes:
    AbstractSocket, SocketModem

    public interface Socket
    Network socket binding that handles asynchronous I/O operations for a non-blocking NIO network channel. A Socket interfaces with the underlying asynchronous networking system via a SocketContext. The socket context invokes I/O callbacks on the Socket when the underlying network socket is ready to perform I/O operations permitted by the socket context's FlowControl.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void didBecome​(Socket socket)
      Lifecycle callback invoked by the socket context after it has become a new socket implementation.
      void didConnect()
      Lifecycle callback invoked by the socket context after the underlying network socket has opened a connection.
      void didDisconnect()
      Lifecycle callback invoked by the socket context after the underlying network connection has disconnected.
      void didFail​(Throwable error)
      Lifecycle callback invoked by the socket context when the underlying network socket fails by throwing an error.
      void didSecure()
      Lifecycle callback invoked by the socket context after the underlying network socket has established a secure connection.
      void didTimeout()
      Lifecycle callback invoked by the socket context after the underlying network connection has timed out.
      void didWrite()
      I/O callback invoked by the socket context after the underlying network socket has completed writing all data in its outputBuffer.
      void doRead()
      I/O callback invoked by the socket context asking this Socket to read input data out of the socket context's inputBuffer.
      void doWrite()
      I/O callback invoked by the socket context asking this Socket to write output data into the socket context's outputBuffer.
      long idleTimeout()
      Returns the number of idle milliseconds after which this Socket should be closed due to inactivity.
      void setSocketContext​(SocketContext context)
      Sets the network socket context to which this Socket is bound.
      SocketContext socketContext()
      Returns the network socket context to which this Socket is bound; returns null if this Socket is unbound.
      void willBecome​(Socket socket)
      Lifecycle callback invoked by the socket context before it has become a new socket implementation.
      void willConnect()
      Lifecycle callback invoked by the socket context before the underlying network socket attempts to open a connection.
      void willSecure()
      Lifecycle callback invoked by the socket context before the underlying network socket establishes a secure connection.
    • Method Detail

      • socketContext

        SocketContext socketContext()
        Returns the network socket context to which this Socket is bound; returns null if this Socket is unbound.
      • setSocketContext

        void setSocketContext​(SocketContext context)
        Sets the network socket context to which this Socket is bound.
      • idleTimeout

        long idleTimeout()
        Returns the number of idle milliseconds after which this Socket should be closed due to inactivity. Returns -1 if a default idle timeout should be used. Returns 0 if the underlying network socket should not time out.
      • doRead

        void doRead()
        I/O callback invoked by the socket context asking this Socket to read input data out of the socket context's inputBuffer. 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 socket context asking this Socket to write output data into the socket context's outputBuffer. 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 socket context after the underlying network socket has completed writing all data in its outputBuffer. May be invoked concurrently to other I/O callbacks, but never concurrently with other doWrite or didWrite calls.
      • willConnect

        void willConnect()
        Lifecycle callback invoked by the socket context before the underlying network socket attempts to open a connection.
      • didConnect

        void didConnect()
        Lifecycle callback invoked by the socket context after the underlying network socket has opened a connection.
      • willSecure

        void willSecure()
        Lifecycle callback invoked by the socket context before the underlying network socket establishes a secure connection.
      • didSecure

        void didSecure()
        Lifecycle callback invoked by the socket context after the underlying network socket has established a secure connection.
      • willBecome

        void willBecome​(Socket socket)
        Lifecycle callback invoked by the socket context before it has become a new socket implementation.
      • didBecome

        void didBecome​(Socket socket)
        Lifecycle callback invoked by the socket context after it has become a new socket implementation.
      • didTimeout

        void didTimeout()
        Lifecycle callback invoked by the socket context after the underlying network connection has timed out. The socket will automatically be closed.
      • didDisconnect

        void didDisconnect()
        Lifecycle callback invoked by the socket context after the underlying network connection has disconnected.
      • didFail

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