Class TransformedRxSocket<U,D>

java.lang.Object
org.forgerock.opendj.io.rx.TransformedRxSocket<U,D>
Type Parameters:
U - The upstream transport message type.
D - The downstream transport message type.
All Implemented Interfaces:
Closeable, AutoCloseable, RxSocket<U>
Direct Known Subclasses:
SaslRxSocket, SslRxSocket, SwitchableRxSocket

public abstract class TransformedRxSocket<U,D> extends Object implements RxSocket<U>
A reactive socket which wraps an underlying downstream reactive socket, providing opportunities to transform transferred data or provide additional functionality. This class overrides all methods of RxSocket, except read(java.util.function.Supplier<U>) and write(U), with implementations which delegate to the underlying reactive socket. Subclasses may override some of these methods as needed and may also provide additional methods and fields.
  • Field Details

    • socket

      protected volatile RxSocket<D> socket
      The downstream socket, which may be altered if needed.
  • Constructor Details

    • TransformedRxSocket

      protected TransformedRxSocket(RxSocket<D> socket)
      Returns a new transformed socket delegating to the provided downstream socket.
      Parameters:
      socket - The downstream socket.
  • Method Details

    • read

      public abstract Single<U> read(Supplier<U> bufferSupplier)
      Description copied from interface: RxSocket
      Returns a "cold" Single which will read the next message from the network each time it is subscribed. Read operations cannot be cancelled: cancelling/disposing a subscription has no effect, and will not close the underlying socket.

      Socket implementations must buffer incoming messages until they are read. Note that invoking this method multiple times returns the same Single instance. The returned Single will not allow multiple concurrent subscriptions as this will result in non-deterministic behavior. Attempts to have multiple concurrent subscriptions will result in an IllegalStateException.

      Subscribers will be notified when the socket is closed through SingleObserver.onError(Throwable) with the corresponding IOException providing the reason for the disconnection. In particular, if the socket is closed locally via RxSocket.close() then it will be notified with RxSocket.LOCAL_CLOSE, if it is closed locally via RxSocket.closeWithReason(java.lang.Throwable) then it will be notified using the provided exception and finally, if it is closed remotely by the peer, then it will be notified using RxSocket.REMOTE_CLOSE. Low-level network transports should return a SocketTimeoutException for communicating any network timeouts. Application layers may return exceptions which are more closely aligned to their APIs.

      Specified by:
      read in interface RxSocket<U>
      Parameters:
      bufferSupplier - An optional buffer supplier which may be used by the transport to reduce copying between transport layers. Use null when the transport does not support buffer suppliers or if the transport should allocate its own buffer. Note that the buffer supplier may be called multiple times in order to complete a single read.
      Returns:
      A "cold" Single which will be signalled once the read operation completes or fails.
    • write

      public abstract Completable write(U message)
      Description copied from interface: RxSocket
      Returns a "cold" Completable which will write the provided message to the network each time it is subscribed. Write operations cannot be cancelled reliably, as a consequence cancelling/disposing a subscription has no effect.

      Subscribers will be notified when the socket is closed through CompletableObserver.onError(Throwable) with the corresponding IOException providing the reason for the disconnection. In particular, if the socket is closed locally via RxSocket.close() then it will be notified with RxSocket.LOCAL_CLOSE, if it is closed locally via RxSocket.closeWithReason(java.lang.Throwable) then it will be notified using the provided exception and finally, if it is closed remotely by the peer, then it will be notified using RxSocket.REMOTE_CLOSE. Low-level network transports should return a SocketTimeoutException for communicating any network timeouts. Application layers may return exceptions which are more closely aligned to their APIs.

      This method is thread-safe, atomic and ordered with respect to other write attempts. In particular, consecutive writes will be performed in the order in which they are subscribed.

      Specified by:
      write in interface RxSocket<U>
      Parameters:
      message - The message to be written to the network.
      Returns:
      A "cold" Completable which will be signalled once the write operation completes or fails.
    • getLocalAddress

      public InetSocketAddress getLocalAddress()
      Description copied from interface: RxSocket
      Returns the InetSocketAddress associated with the local system. For logging purposes the local address can still be retrieved after the socket has been closed.
      Specified by:
      getLocalAddress in interface RxSocket<U>
      Returns:
      The InetSocketAddress associated with the local system.
    • getRemoteAddress

      public InetSocketAddress getRemoteAddress()
      Description copied from interface: RxSocket
      Returns the InetSocketAddress associated with the remote system. For logging purposes the remote address can still be retrieved after the socket has been closed.
      Specified by:
      getRemoteAddress in interface RxSocket<U>
      Returns:
      The InetSocketAddress associated with the remote system.
    • closeWithReason

      public Completable closeWithReason(Throwable reason)
      Description copied from interface: RxSocket
      Returns a "hot" Completable which will close this socket when it is subscribed for the first time.

      Disconnecting the socket may cause any active or future RxSocket.read(java.util.function.Supplier<M>) or RxSocket.write(M) operations to fail with the provided Throwable. Messages which have not yet been sent may be dropped, although implementations should generally attempt to flush any pending unwritten messages first.

      NOTE: this method is idempotent. The close reason cannot be changed once it has been set.

      Specified by:
      closeWithReason in interface RxSocket<U>
      Parameters:
      reason - The reason which will be forwarded to any active or future RxSocket.read(java.util.function.Supplier<M>) or RxSocket.write(M) operations.
      Returns:
      A "hot" Completable which will be signalled once the socket is closed. It will never fail.
    • toString

      public String toString()
      Overrides:
      toString in class Object