public final class SessionImpl extends DirectoryThread implements Session
Thread.State, Thread.UncaughtExceptionHandler
DIRECTORY_THREAD_GROUP
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
SessionImpl(ReplicationContext replicationContext,
Socket socket,
SSLSocket secureSocket)
Creates a new Session.
|
Modifier and Type | Method and 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.
|
short |
getProtocolVersion()
Returns the version of the protocol that is currently used.
|
String |
getReadableRemoteAddress()
Retrieve the human readable address of the remote server.
|
HostPort |
getRemoteAddress()
Retrieve the IP address and port of the remote server.
|
boolean |
isEncrypted()
Determine whether the session is using a security layer.
|
ExtendedStartMsg |
performExtendedHandshake(ServerId<?> serverId,
GroupId groupId,
ServerState state)
Performs extended handshake to exchange additional informations.
|
void |
publish(ReplicationMsg msg)
Sends a replication message to the remote peer.
|
ReplicationMsg |
receive()
Attempt to receive a ReplicationMsg.
|
void |
run()
Run method for the Session.
|
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 |
stopEncryption()
Stop using the security layer, if there is any.
|
void |
waitForStartup()
This method can be called to wait until the session thread is properly started.
|
getAssociatedTask, getCreationStackTrace, getDebugProperties, getParentThread, initiateShutdown, isShutdownInitiated, isStarted, isStarting, setAssociatedTask, setStarted
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public SessionImpl(ReplicationContext replicationContext, Socket socket, SSLSocket secureSocket) throws IOException
replicationContext
- The replication context.socket
- The regular Socket on which the SocketSession will be based.secureSocket
- The secure Socket on which the SocketSession will be based.IOException
- When an IException happens on the socket.public void close()
Session
public boolean closeInitiated()
Session
closeInitiated
in interface Session
public ExtendedStartMsg performExtendedHandshake(ServerId<?> serverId, GroupId groupId, ServerState state) throws IOException, DataFormatException, NotSupportedOldVersionPDUException
Session
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.
performExtendedHandshake
in interface Session
serverId
- the serverId for this servergroupId
- the groupId for this serverstate
- the server state of this serverIOException
- if the remote server does not send its groupID in response to oursDataFormatException
- if a network error prevents getting the remote server groupIDNotSupportedOldVersionPDUException
- if the remote server is not using the correct protocol versionpublic long getLastPublishTime()
Session
getLastPublishTime
in interface Session
public long getLastReceiveTime()
Session
getLastReceiveTime
in interface Session
public String getReadableRemoteAddress()
Session
getReadableRemoteAddress
in interface Session
public HostPort getRemoteAddress()
Session
getRemoteAddress
in interface Session
public boolean isEncrypted()
Session
isEncrypted
in interface Session
public void publish(ReplicationMsg msg) throws IOException
Session
publish
in interface Session
msg
- The message to be sent.IOException
- If an IO error occurred.public ReplicationMsg receive() throws IOException, DataFormatException, NotSupportedOldVersionPDUException
Session
receive
in interface Session
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.public void setProtocolVersion(short version)
Session
setProtocolVersion
in interface Session
version
- The version of the protocol that is currently used.public short getProtocolVersion()
Session
getProtocolVersion
in interface Session
public void setSoTimeout(int timeout) throws SocketException
Session
setSoTimeout
in interface Session
timeout
- the specified timeout, in milliseconds.SocketException
- if there is an error in the underlying protocol, such as a TCP error.public void stopEncryption()
Session
stopEncryption
in interface Session
public void run()
Session
public void waitForStartup() throws InterruptedException
Session
waitForStartup
in interface Session
InterruptedException
- when interruptedCopyright 2010-2022 ForgeRock AS.