Interface Session
-
- All Superinterfaces:
AutoCloseable
,Closeable
public interface Session extends Closeable
Defines a replication session using TLS.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
This method is called when the session with the remote must be closed.boolean
closeInitiated()
This methods allows to determine if the session close was initiated on this Session.long
getLastPublishTime()
Gets the time the last replication message was published on this session.long
getLastReceiveTime()
Gets the time the last replication message was received on this session.Certificate
getPeerCertificate()
Returns the certificate presented by the peer during TLS handshake.short
getProtocolVersion()
Returns the version of the protocol that is currently used.String
getReadableRemoteAddress()
Retrieve the human readable address of the remote server.com.forgerock.opendj.util.HostPort
getRemoteAddress()
Retrieve the IP address and port of the remote server.boolean
isEncrypted()
Determine whether the session is using a security layer.static org.opends.server.replication.protocol.DsSession
newDsSession(ServerContext serverContext, Socket socket, com.forgerock.opendj.util.Host host, int soTimeout, ReplSessionSecurity securityConfiguration, BooleanSupplier shuttingDown)
Creates a new DS Session.static org.opends.server.replication.protocol.RsSession
newRsClientSession(ServerContext serverContext, Socket socket, com.forgerock.opendj.util.Host host, int soTimeout, ReplSessionSecurity securityConfiguration)
Creates a new RS Session in the client role.static org.opends.server.replication.protocol.RsSession
newRsServerSession(ServerContext serverContext, Socket socket, int soTimeout, ReplSessionSecurity securityConfiguration)
Creates a new RS Session in the server role.ExtendedStartMsg
performExtendedHandshake(ServerId<?> serverId, com.forgerock.opendj.discovery.GroupId groupId, ServerState state, long heartbeatInterval)
Performs extended handshake to exchange additional information.void
publish(ReplicationMsg msg)
Sends a replication message to the remote peer.ReplicationMsg
receive()
Attempt to receive a ReplicationMsg.void
resetReceiveTime()
Reset the time the last message was received to restart accounting from scratch.void
setHandshakeComplete()
Signals that handshake is complete (i.e.void
setName(String sourceServer, String peerServer)
Sets name of the source server and peer server, in order to identify the session in thread name and logging statements.void
setProtocolVersion(short version)
This method is called at the establishment of the session and can be used to record the version of the protocol that is currently used.void
setSoTimeout(int timeout)
Set a timeout value.void
start()
Starts the publisher thread of this session.void
stopEncryption()
Stops using the security layer, if there is any, possibly waiting during the process to ensure encryption is not removed during reception or sending of a message.org.reactivestreams.Publisher<UpdateMsg>
writer(Flowable<UpdateMsg> upstream)
Returns aPublisher
that: writes update messages to the remote server with back-pressure support and publishes in return each written message.
-
-
-
Method Detail
-
newDsSession
static org.opends.server.replication.protocol.DsSession newDsSession(ServerContext serverContext, Socket socket, com.forgerock.opendj.util.Host host, int soTimeout, ReplSessionSecurity securityConfiguration, BooleanSupplier shuttingDown) throws ConfigException, IOException
Creates a new DS Session.- Parameters:
serverContext
- The directory server contextsocket
- The regular Socket on which the SocketSession will be based.host
- The host the socket is connected to.soTimeout
- The socket timeout option to use for the protocol session.securityConfiguration
- Provides the security configuration for replication protocol sessions.shuttingDown
- The Supplier returning if domain shutdown is in progress- Returns:
- a new DS Session
- Throws:
ConfigException
- If the session could not be established due to a configuration problem.IOException
- If the session could not be established for some other reason.
-
newRsClientSession
static org.opends.server.replication.protocol.RsSession newRsClientSession(ServerContext serverContext, Socket socket, com.forgerock.opendj.util.Host host, int soTimeout, ReplSessionSecurity securityConfiguration) throws ConfigException, IOException
Creates a new RS Session in the client role.- Parameters:
serverContext
- The directory server contextsocket
- The regular Socket on which the SocketSession will be based.host
- The host the socket is connected to.soTimeout
- The socket timeout option to use for the protocol session.securityConfiguration
- Provides the security configuration for replication protocol sessions.- Returns:
- a new RS Session in the client role
- Throws:
ConfigException
- If the session could not be established due to a configuration problem.IOException
- If the session could not be established for some other reason.
-
newRsServerSession
static org.opends.server.replication.protocol.RsSession newRsServerSession(ServerContext serverContext, Socket socket, int soTimeout, ReplSessionSecurity securityConfiguration) throws ConfigException, IOException
Creates a new RS Session in the server role.- Parameters:
serverContext
- The directory server contextsocket
- The regular Socket on which the SocketSession will be based.soTimeout
- The socket timeout option to use for the protocol session.securityConfiguration
- Provides the security configuration for replication protocol sessions.- Returns:
- a new RS Session in the server role or
null
if the underlying SSL socket cannot be created - Throws:
ConfigException
- If the session could not be established due to a configuration problem.IOException
- If the session could not be established for some other reason.
-
close
void close()
This method is called when the session with the remote must be closed. This object won't be used anymore after this method is called.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
closeInitiated
boolean closeInitiated()
This methods allows to determine if the session close was initiated on this Session.- Returns:
- A boolean allowing to determine if the session close was initiated on this Session.
-
performExtendedHandshake
ExtendedStartMsg performExtendedHandshake(ServerId<?> serverId, com.forgerock.opendj.discovery.GroupId groupId, ServerState state, long heartbeatInterval) throws IOException, DataFormatException, NotSupportedOldVersionPDUException
Performs extended handshake to exchange additional information.It expects to get the remote server groupId and processId in response; since the exchange is done during handshaking it does not matter who sends it first as the global loop for reading messages is not running yet, so we'll be receiving the remote server message here.
- Parameters:
serverId
- the serverId for this servergroupId
- the groupId for this serverstate
- the server state of this serverheartbeatInterval
- the heartbeat interval to use- Returns:
- the remote server GroupIdMsg
- Throws:
NotSupportedOldVersionPDUException
- if the remote server is not using the correct protocol versionIOException
- if the remote server does not send its groupID in response to oursDataFormatException
- if a network error prevents getting the remote server groupID
-
getLastPublishTime
long getLastPublishTime()
Gets the time the last replication message was published on this session.- Returns:
- The timestamp in milliseconds of the last message published.
-
getLastReceiveTime
long getLastReceiveTime()
Gets the time the last replication message was received on this session.- Returns:
- The timestamp in milliseconds of the last message received.
-
resetReceiveTime
void resetReceiveTime()
Reset the time the last message was received to restart accounting from scratch.
-
getReadableRemoteAddress
String getReadableRemoteAddress()
Retrieve the human readable address of the remote server.- Returns:
- The human readable address of the remote server.
-
getRemoteAddress
com.forgerock.opendj.util.HostPort getRemoteAddress()
Retrieve the IP address and port of the remote server.- Returns:
- The IP address and port of the remote server.
-
isEncrypted
boolean isEncrypted()
Determine whether the session is using a security layer.- Returns:
- true if the connection is encrypted, false otherwise.
-
publish
void publish(ReplicationMsg msg) throws IOException
Sends a replication message to the remote peer.- Parameters:
msg
- The message to be sent.- Throws:
IOException
- If an IO error occurred.
-
receive
ReplicationMsg receive() throws IOException, DataFormatException, NotSupportedOldVersionPDUException
Attempt to receive a ReplicationMsg. This method should block the calling thread until a ReplicationMsg is available or until an error condition. This method can only be called by a single thread and therefore does not need to implement any replication.- Returns:
- The ReplicationMsg that was received.
- Throws:
IOException
- When error happened during IO process.DataFormatException
- When the data received is not formatted as a ReplicationMsg.NotSupportedOldVersionPDUException
- If the received PDU is part of an old protocol version and we do not support it.
-
setProtocolVersion
void setProtocolVersion(short version)
This method is called at the establishment of the session and can be used to record the version of the protocol that is currently used.- Parameters:
version
- The version of the protocol that is currently used.
-
getProtocolVersion
short getProtocolVersion()
Returns the version of the protocol that is currently used.- Returns:
- The version of the protocol that is currently used.
-
setSoTimeout
void setSoTimeout(int timeout) throws SocketException
Set a timeout value. With this option set to a non-zero value, calls to the receive() method block for only this amount of time after which a java.net.SocketTimeoutException is raised. The Broker is valid and usable even after such an Exception is raised.- Parameters:
timeout
- the specified timeout, in milliseconds.- Throws:
SocketException
- if there is an error in the underlying protocol, such as a TCP error.
-
setHandshakeComplete
void setHandshakeComplete()
Signals that handshake is complete (i.e. it was not ended prematurely).Closing of the session is handled differently when handshake ends prematurely.
-
stopEncryption
void stopEncryption() throws IOException, InterruptedException
Stops using the security layer, if there is any, possibly waiting during the process to ensure encryption is not removed during reception or sending of a message.- Throws:
IOException
- if the StopEncryptionMsg could not be publishedInterruptedException
- if thread is interrupted during the waiting process
-
setName
void setName(String sourceServer, String peerServer)
Sets name of the source server and peer server, in order to identify the session in thread name and logging statements.- Parameters:
sourceServer
- identifies the source server.peerServer
- identifies the peer server.
-
start
void start()
Starts the publisher thread of this session.
-
writer
org.reactivestreams.Publisher<UpdateMsg> writer(Flowable<UpdateMsg> upstream)
Returns aPublisher
that:- writes update messages to the remote server with back-pressure support and
- publishes in return each written message.
- Parameters:
upstream
- the upstream (or source) of update messages.- Returns:
- a
Publisher
that 1) writes received messages to the remote server with back-pressure support and 2) publishes in return each written message. - Throws:
UnsupportedOperationException
- if the subclass does not support reactive implementation.
-
getPeerCertificate
Certificate getPeerCertificate() throws SSLPeerUnverifiedException
Returns the certificate presented by the peer during TLS handshake.- Returns:
- the certificate presented by the peer during TLS handshake
- Throws:
SSLPeerUnverifiedException
- if the peer did not present a certificate or an authentication error occurred
-
-