Class AbstractConnection
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
OtpConnection,OtpCookedConnection
This abstract class provides the necessary methods to maintain the actual connection and encode the messages and headers in the proper format according to the Erlang distribution protocol. Subclasses can use these methods to provide a more or less transparent communication channel as desired.
Note that no receive methods are provided. Subclasses must provide methods for message delivery, and may implement their own receive methods.
If an exception occurs in any of the methods in this class, the connection will be closed and must be reopened in order to resume communication with the peer. This will be indicated to the subclass by passing the exception to its delivery() method.
The System property OtpConnection.trace can be used to change the initial
trace level setting for all connections. Normally the initial trace level is
0 and connections are not traced unless setTraceLevel() is used to change the setting for a particular connection.
OtpConnection.trace can be used to turn on tracing by default for all
connections.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected static final intprotected static final intprotected booleanprotected booleanprotected static intprotected static intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static intprotected static final intprotected static final intprotected OtpLocalNodeprotected static final byteprotected OtpPeerprotected static Randomprotected static final intprotected static final intprotected booleanprotected static final intprotected static intprotected static final intprotected OtpTransportprotected intprotected static final intprotected static final intprotected static final intprotected static final byteFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractConnection(OtpLocalNode self, OtpPeer other) Intiate and open a connection to a remote node.protectedAbstractConnection(OtpLocalNode self, OtpTransport s) Accept an incoming connection from a remote node. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the connection to the remote node.abstract voidDeliver messages to the recipient.abstract voidDeliver communication exceptions to the recipient.protected voiddo_send(OtpOutputStream header) protected voiddo_send(OtpOutputStream header, OtpOutputStream payload) protected voiddoAccept()protected voiddoConnect(int port) protected voidfinalize()protected static intprotected byte[]intgetFlags()intGet the trace level for this connection.protected StringbooleanDetermine if the connection is still alive.protected byte[]protected intreadSock(OtpTransport s, byte[] b) protected intprotected voidrecvChallengeAck(int our_challenge) protected intrecvChallengeReply(int our_challenge) protected voidrecvComplement(int send_name_tag) protected intprotected voidvoidrun()protected voidsendBuf(OtpErlangPid from, OtpErlangPid dest, OtpOutputStream payload) Send a pre-encoded message to a process on a remote node.protected voidsendBuf(OtpErlangPid from, String dest, OtpOutputStream payload) Send a pre-encoded message to a named process on a remote node.protected voidsendChallenge(long her_flags, long our_flags, int challenge) protected voidsendChallengeAck(byte[] digest) protected voidsendChallengeReply(int challenge, byte[] digest) protected voidsendComplement(int send_name_tag) protected voidsendExit(OtpErlangPid from, OtpErlangPid dest, OtpErlangObject reason) protected voidsendExit2(OtpErlangPid from, OtpErlangPid dest, OtpErlangObject reason) Send an exit signal to a remote process.protected voidsendLink(OtpErlangPid from, OtpErlangPid dest) Send link signal to remote process.protected intsendName(int dist, long aflags, int creation) protected voidsendStatus(String status) protected voidsendUnlink(OtpErlangPid from, OtpErlangPid dest, long unlink_id) Send unlink signal to remote process.protected voidsendUnlinkAck(OtpErlangPid from, OtpErlangPid dest, long unlink_id) Send unlink acknowledgment signal to remote process.voidsetFlags(int flags) intsetTraceLevel(int level) Set the trace level for this connection.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
headerLen
protected static final int headerLen- See Also:
-
passThrough
protected static final byte passThrough- See Also:
-
version
protected static final byte version- See Also:
-
linkTag
protected static final int linkTag- See Also:
-
sendTag
protected static final int sendTag- See Also:
-
exitTag
protected static final int exitTag- See Also:
-
unlinkTag
protected static final int unlinkTag- See Also:
-
regSendTag
protected static final int regSendTag- See Also:
-
groupLeaderTag
protected static final int groupLeaderTag- See Also:
-
exit2Tag
protected static final int exit2Tag- See Also:
-
sendTTTag
protected static final int sendTTTag- See Also:
-
exitTTTag
protected static final int exitTTTag- See Also:
-
regSendTTTag
protected static final int regSendTTTag- See Also:
-
exit2TTTag
protected static final int exit2TTTag- See Also:
-
unlinkIdTag
protected static final int unlinkIdTag- See Also:
-
unlinkIdAckTag
protected static final int unlinkIdAckTag- See Also:
-
ChallengeReply
protected static final int ChallengeReply- See Also:
-
ChallengeAck
protected static final int ChallengeAck- See Also:
-
ChallengeStatus
protected static final int ChallengeStatus- See Also:
-
connected
protected boolean connected -
socket
-
peer
-
localNode
-
cookieOk
protected boolean cookieOk -
sendCookie
protected boolean sendCookie -
traceLevel
protected int traceLevel -
defaultLevel
protected static int defaultLevel -
sendThreshold
protected static int sendThreshold -
ctrlThreshold
protected static int ctrlThreshold -
handshakeThreshold
protected static int handshakeThreshold -
random
-
-
Constructor Details
-
AbstractConnection
protected AbstractConnection(OtpLocalNode self, OtpTransport s) throws IOException, OtpAuthException Accept an incoming connection from a remote node. Used byOtpSelf.accept()to create a connection based on data received when handshaking with the peer node, when the remote node is the connection initiator.- Throws:
IOException- if it was not possible to connect to the peer.OtpAuthException- if handshake resulted in an authentication error
-
AbstractConnection
Intiate and open a connection to a remote node.- Throws:
IOException- if it was not possible to connect to the peer.OtpAuthException- if handshake resulted in an authentication error.
-
-
Method Details
-
deliver
Deliver communication exceptions to the recipient. -
deliver
Deliver messages to the recipient. -
sendBuf
Send a pre-encoded message to a named process on a remote node.- Parameters:
dest- the name of the remote process.payload- the encoded message to send.- Throws:
IOException- if the connection is not active or a communication error occurs.
-
sendBuf
protected void sendBuf(OtpErlangPid from, OtpErlangPid dest, OtpOutputStream payload) throws IOException Send a pre-encoded message to a process on a remote node.- Parameters:
dest- the Erlang PID of the remote process.payload- the encoded message to send.- Throws:
IOException- if the connection is not active or a communication error occurs.
-
sendLink
Send link signal to remote process.- Parameters:
dest- the Erlang PID of the remote process.- Throws:
IOException- if the connection is not active or a communication error occurs.
-
sendUnlink
Send unlink signal to remote process.- Parameters:
dest- the Erlang PID of the remote process.- Throws:
IOException- if the connection is not active or a communication error occurs.
-
sendUnlinkAck
protected void sendUnlinkAck(OtpErlangPid from, OtpErlangPid dest, long unlink_id) throws IOException Send unlink acknowledgment signal to remote process.- Parameters:
dest- the Erlang PID of the remote process.- Throws:
IOException- if the connection is not active or a communication error occurs.
-
sendExit
protected void sendExit(OtpErlangPid from, OtpErlangPid dest, OtpErlangObject reason) throws IOException - Throws:
IOException
-
sendExit2
protected void sendExit2(OtpErlangPid from, OtpErlangPid dest, OtpErlangObject reason) throws IOException Send an exit signal to a remote process.- Parameters:
dest- the Erlang PID of the remote process.reason- an Erlang term describing the exit reason.- Throws:
IOException- if the connection is not active or a communication error occurs.
-
run
public void run() -
setTraceLevel
public int setTraceLevel(int level) Set the trace level for this connection. Normally tracing is off by default unless System property OtpConnection.trace was set.
The following levels are valid: 0 turns off tracing completely, 1 shows ordinary send and receive messages, 2 shows control messages such as link and unlink, 3 shows handshaking at connection setup, and 4 shows communication with Epmd. Each level includes the information shown by the lower ones.
- Parameters:
level- the level to set.- Returns:
- the previous trace level.
-
getTraceLevel
public int getTraceLevel()Get the trace level for this connection.- Returns:
- the current trace level.
-
close
public void close()Close the connection to the remote node. -
finalize
protected void finalize() -
isConnected
public boolean isConnected()Determine if the connection is still alive. Note that this method only reports the status of the connection, and that it is possible that there are unread messages waiting in the receive queue.- Returns:
- true if the connection is alive.
-
do_send
- Throws:
IOException
-
do_send
- Throws:
IOException
-
headerType
-
readSock
- Throws:
IOException
-
doAccept
- Throws:
IOExceptionOtpAuthException
-
doConnect
- Throws:
IOExceptionOtpAuthException
-
genChallenge
protected static int genChallenge() -
genDigest
-
sendName
- Throws:
IOException
-
sendComplement
- Throws:
IOException
-
sendChallenge
- Throws:
IOException
-
read2BytePackage
- Throws:
IOExceptionOtpErlangDecodeException
-
recvName
- Throws:
IOException
-
recvChallenge
- Throws:
IOException
-
recvComplement
- Throws:
IOException
-
sendChallengeReply
- Throws:
IOException
-
recvChallengeReply
- Throws:
IOExceptionOtpAuthException
-
sendChallengeAck
- Throws:
IOException
-
recvChallengeAck
- Throws:
IOExceptionOtpAuthException
-
sendStatus
- Throws:
IOException
-
recvStatus
- Throws:
IOException
-
setFlags
public void setFlags(int flags) -
getFlags
public int getFlags()
-