Class SslRxSocket
- java.lang.Object
-
- org.forgerock.opendj.io.rx.TransformedRxSocket<ByteBuffer,ByteBuffer>
-
- org.forgerock.opendj.io.rx.SslRxSocket
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,RxSocket<ByteBuffer>
public final class SslRxSocket extends TransformedRxSocket<ByteBuffer,ByteBuffer>
A reactive socket implementation which adds SSL to an underlying reactive socket.
-
-
Field Summary
-
Fields inherited from class org.forgerock.opendj.io.rx.TransformedRxSocket
socket
-
Fields inherited from interface org.forgerock.opendj.io.RxSocket
LOCAL_CLOSE, REMOTE_CLOSE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description io.reactivex.rxjava3.core.Completable
closeWithReason(Throwable reason)
Returns a "hot"Completable
which will close this socket when it is subscribed for the first time.SSLSession
getSslSession()
Returns the SSL session currently in use by the underlying connection.io.reactivex.rxjava3.core.Completable
handshake()
Returns aCompletable
representing the completion status of the initial SSL handshake, which completes once the handshake completes or fails with an error if the handshake fails for some reason.io.reactivex.rxjava3.core.Single<ByteBuffer>
read(Supplier<ByteBuffer> bufferSupplier)
Returns a "cold"Single
which will read the next message from the network each time it is subscribed.String
toString()
io.reactivex.rxjava3.core.Completable
write(ByteBuffer packet)
Returns a "cold"Completable
which will write the provided message to the network each time it is subscribed.-
Methods inherited from class org.forgerock.opendj.io.rx.TransformedRxSocket
getLocalAddress, getRemoteAddress
-
-
-
-
Method Detail
-
handshake
public io.reactivex.rxjava3.core.Completable handshake()
Returns aCompletable
representing the completion status of the initial SSL handshake, which completes once the handshake completes or fails with an error if the handshake fails for some reason. Handshaking starts as soon as the connection is created and only occurs once during the lifetime of the connection. Thus, the returned completable is a "hot" completable: subscribing to it multiple times always yields the same result.- Returns:
- A
Completable
representing the completion status of the initial SSL handshake.
-
read
public io.reactivex.rxjava3.core.Single<ByteBuffer> read(Supplier<ByteBuffer> 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 returnedSingle
will not allow multiple concurrent subscriptions as this will result in non-deterministic behavior. Attempts to have multiple concurrent subscriptions will result in anIllegalStateException
.Subscribers will be notified when the socket is closed through
SingleObserver.onError(Throwable)
with the correspondingIOException
providing the reason for the disconnection. In particular, if the socket is closed locally viaRxSocket.close()
then it will be notified withRxSocket.LOCAL_CLOSE
, if it is closed locally viaRxSocket.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 usingRxSocket.REMOTE_CLOSE
. Low-level network transports should return aSocketTimeoutException
for communicating any network timeouts. Application layers may return exceptions which are more closely aligned to their APIs.- Specified by:
read
in interfaceRxSocket<ByteBuffer>
- Specified by:
read
in classTransformedRxSocket<ByteBuffer,ByteBuffer>
- Parameters:
bufferSupplier
- An optional buffer supplier which may be used by the transport to reduce copying between transport layers. Usenull
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 io.reactivex.rxjava3.core.Completable write(ByteBuffer packet)
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 correspondingIOException
providing the reason for the disconnection. In particular, if the socket is closed locally viaRxSocket.close()
then it will be notified withRxSocket.LOCAL_CLOSE
, if it is closed locally viaRxSocket.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 usingRxSocket.REMOTE_CLOSE
. Low-level network transports should return aSocketTimeoutException
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 interfaceRxSocket<ByteBuffer>
- Specified by:
write
in classTransformedRxSocket<ByteBuffer,ByteBuffer>
- Parameters:
packet
- The message to be written to the network.- Returns:
- A "cold"
Completable
which will be signalled once the write operation completes or fails.
-
getSslSession
public SSLSession getSslSession()
Returns the SSL session currently in use by the underlying connection.- Returns:
- The SSL session currently in use by the underlying connection.
-
closeWithReason
public io.reactivex.rxjava3.core.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>)
orRxSocket.write(M)
operations to fail with the providedThrowable
. 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 interfaceRxSocket<ByteBuffer>
- Overrides:
closeWithReason
in classTransformedRxSocket<ByteBuffer,ByteBuffer>
- Parameters:
reason
- The reason which will be forwarded to any active or futureRxSocket.read(java.util.function.Supplier<M>)
orRxSocket.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 classTransformedRxSocket<ByteBuffer,ByteBuffer>
-
-