Class AbstractConnection
- java.lang.Object
- 
- java.lang.Thread
- 
- com.ericsson.otp.erlang.AbstractConnection
 
 
- 
- All Implemented Interfaces:
- java.lang.Runnable
 - Direct Known Subclasses:
- OtpConnection,- OtpCookedConnection
 
 public abstract class AbstractConnection extends java.lang.ThreadMaintains a connection between a Java process and a remote Erlang, Java or C node. The object maintains connection state and allows data to be sent to and received from the peer.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.
- 
- 
Field SummaryFields Modifier and Type Field Description protected static intChallengeAckprotected static intChallengeReplyprotected static intChallengeStatusprotected booleanconnectedprotected booleancookieOkprotected static intctrlThresholdprotected static intdefaultLevelprotected static intexit2Tagprotected static intexit2TTTagprotected static intexitTagprotected static intexitTTTagprotected static intgroupLeaderTagprotected static inthandshakeThresholdprotected static intheaderLenprotected static intlinkTagprotected OtpLocalNodelocalNodeprotected static bytepassThroughprotected OtpPeerpeerprotected static java.util.Randomrandomprotected static intregSendTagprotected static intregSendTTTagprotected booleansendCookieprotected static intsendTagprotected static intsendThresholdprotected static intsendTTTagprotected OtpTransportsocketprotected inttraceLevelprotected static intunlinkIdAckTagprotected static intunlinkIdTagprotected static intunlinkTagprotected static byteversion
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedAbstractConnection(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 SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Close the connection to the remote node.abstract voiddeliver(OtpMsg msg)Deliver messages to the recipient.abstract voiddeliver(java.lang.Exception e)Deliver communication exceptions to the recipient.protected voiddo_send(OtpOutputStream header)protected voiddo_send(OtpOutputStream header, OtpOutputStream payload)protected voiddoAccept()protected voiddoConnect()protected voiddoGenericConnect()protected voiddoPortConnect(int port)protected voidfinalize()protected static intgenChallenge()protected byte[]genDigest(int challenge, java.lang.String cookie)intgetFlags()intgetTraceLevel()Get the trace level for this connection.protected java.lang.StringheaderType(OtpErlangObject h)booleanisConnected()Determine if the connection is still alive.protected byte[]read2BytePackage()protected intreadSock(OtpTransport s, byte[] b)protected intrecvChallenge()protected voidrecvChallengeAck(int our_challenge)protected intrecvChallengeReply(int our_challenge)protected voidrecvComplement(int send_name_tag)protected intrecvName(OtpPeer apeer)protected voidrecvStatus()voidrun()protected voidsendBuf(OtpErlangPid from, OtpErlangPid dest, OtpOutputStream payload)Send a pre-encoded message to a process on a remote node.protected voidsendBuf(OtpErlangPid from, java.lang.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 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(java.lang.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.ThreadactiveCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
 
- 
 
- 
- 
- 
Field Detail- 
headerLenprotected static final int headerLen - See Also:
- Constant Field Values
 
 - 
passThroughprotected static final byte passThrough - See Also:
- Constant Field Values
 
 - 
versionprotected static final byte version - See Also:
- Constant Field Values
 
 - 
linkTagprotected static final int linkTag - See Also:
- Constant Field Values
 
 - 
sendTagprotected static final int sendTag - See Also:
- Constant Field Values
 
 - 
exitTagprotected static final int exitTag - See Also:
- Constant Field Values
 
 - 
unlinkTagprotected static final int unlinkTag - See Also:
- Constant Field Values
 
 - 
regSendTagprotected static final int regSendTag - See Also:
- Constant Field Values
 
 - 
groupLeaderTagprotected static final int groupLeaderTag - See Also:
- Constant Field Values
 
 - 
exit2Tagprotected static final int exit2Tag - See Also:
- Constant Field Values
 
 - 
sendTTTagprotected static final int sendTTTag - See Also:
- Constant Field Values
 
 - 
exitTTTagprotected static final int exitTTTag - See Also:
- Constant Field Values
 
 - 
regSendTTTagprotected static final int regSendTTTag - See Also:
- Constant Field Values
 
 - 
exit2TTTagprotected static final int exit2TTTag - See Also:
- Constant Field Values
 
 - 
unlinkIdTagprotected static final int unlinkIdTag - See Also:
- Constant Field Values
 
 - 
unlinkIdAckTagprotected static final int unlinkIdAckTag - See Also:
- Constant Field Values
 
 - 
ChallengeReplyprotected static final int ChallengeReply - See Also:
- Constant Field Values
 
 - 
ChallengeAckprotected static final int ChallengeAck - See Also:
- Constant Field Values
 
 - 
ChallengeStatusprotected static final int ChallengeStatus - See Also:
- Constant Field Values
 
 - 
connectedprotected boolean connected 
 - 
socketprotected OtpTransport socket 
 - 
peerprotected OtpPeer peer 
 - 
localNodeprotected OtpLocalNode localNode 
 - 
cookieOkprotected boolean cookieOk 
 - 
sendCookieprotected boolean sendCookie 
 - 
traceLevelprotected int traceLevel 
 - 
defaultLevelprotected static int defaultLevel 
 - 
sendThresholdprotected static int sendThreshold 
 - 
ctrlThresholdprotected static int ctrlThreshold 
 - 
handshakeThresholdprotected static int handshakeThreshold 
 - 
randomprotected static java.util.Random random 
 
- 
 - 
Constructor Detail- 
AbstractConnectionprotected AbstractConnection(OtpLocalNode self, OtpTransport s) throws java.io.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:
- java.io.IOException- if it was not possible to connect to the peer.
- OtpAuthException- if handshake resulted in an authentication error
 
 - 
AbstractConnectionprotected AbstractConnection(OtpLocalNode self, OtpPeer other) throws java.io.IOException, OtpAuthException Intiate and open a connection to a remote node.- Throws:
- java.io.IOException- if it was not possible to connect to the peer.
- OtpAuthException- if handshake resulted in an authentication error.
 
 
- 
 - 
Method Detail- 
deliverpublic abstract void deliver(java.lang.Exception e) Deliver communication exceptions to the recipient.
 - 
deliverpublic abstract void deliver(OtpMsg msg) Deliver messages to the recipient.
 - 
sendBufprotected void sendBuf(OtpErlangPid from, java.lang.String dest, OtpOutputStream payload) throws java.io.IOException 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:
- java.io.IOException- if the connection is not active or a communication error occurs.
 
 - 
sendBufprotected void sendBuf(OtpErlangPid from, OtpErlangPid dest, OtpOutputStream payload) throws java.io.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:
- java.io.IOException- if the connection is not active or a communication error occurs.
 
 - 
sendLinkprotected void sendLink(OtpErlangPid from, OtpErlangPid dest) throws java.io.IOException Send link signal to remote process.- Parameters:
- dest- the Erlang PID of the remote process.
- Throws:
- java.io.IOException- if the connection is not active or a communication error occurs.
 
 - 
sendUnlinkprotected void sendUnlink(OtpErlangPid from, OtpErlangPid dest, long unlink_id) throws java.io.IOException Send unlink signal to remote process.- Parameters:
- dest- the Erlang PID of the remote process.
- Throws:
- java.io.IOException- if the connection is not active or a communication error occurs.
 
 - 
sendUnlinkAckprotected void sendUnlinkAck(OtpErlangPid from, OtpErlangPid dest, long unlink_id) throws java.io.IOException Send unlink acknowledgment signal to remote process.- Parameters:
- dest- the Erlang PID of the remote process.
- Throws:
- java.io.IOException- if the connection is not active or a communication error occurs.
 
 - 
sendExitprotected void sendExit(OtpErlangPid from, OtpErlangPid dest, OtpErlangObject reason) throws java.io.IOException - Throws:
- java.io.IOException
 
 - 
sendExit2protected void sendExit2(OtpErlangPid from, OtpErlangPid dest, OtpErlangObject reason) throws java.io.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:
- java.io.IOException- if the connection is not active or a communication error occurs.
 
 - 
runpublic void run() - Specified by:
- runin interface- java.lang.Runnable
- Overrides:
- runin class- java.lang.Thread
 
 - 
setTraceLevelpublic 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.
 
 - 
getTraceLevelpublic int getTraceLevel() Get the trace level for this connection.- Returns:
- the current trace level.
 
 - 
closepublic void close() Close the connection to the remote node.
 - 
finalizeprotected void finalize() - Overrides:
- finalizein class- java.lang.Object
 
 - 
isConnectedpublic 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_sendprotected void do_send(OtpOutputStream header, OtpOutputStream payload) throws java.io.IOException - Throws:
- java.io.IOException
 
 - 
do_sendprotected void do_send(OtpOutputStream header) throws java.io.IOException - Throws:
- java.io.IOException
 
 - 
headerTypeprotected java.lang.String headerType(OtpErlangObject h) 
 - 
readSockprotected int readSock(OtpTransport s, byte[] b) throws java.io.IOException - Throws:
- java.io.IOException
 
 - 
doAcceptprotected void doAccept() throws java.io.IOException, OtpAuthException- Throws:
- java.io.IOException
- OtpAuthException
 
 - 
doPortConnectprotected void doPortConnect(int port) throws java.io.IOException, OtpAuthException- Throws:
- java.io.IOException
- OtpAuthException
 
 - 
doConnectprotected void doConnect() throws java.io.IOException, OtpAuthException- Throws:
- java.io.IOException
- OtpAuthException
 
 - 
doGenericConnectprotected void doGenericConnect() throws java.io.IOException, OtpAuthException- Throws:
- java.io.IOException
- OtpAuthException
 
 - 
genChallengeprotected static int genChallenge() 
 - 
genDigestprotected byte[] genDigest(int challenge, java.lang.String cookie)
 - 
sendNameprotected int sendName(int dist, long aflags, int creation) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
sendChallengeprotected void sendChallenge(long her_flags, long our_flags, int challenge) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
read2BytePackageprotected byte[] read2BytePackage() throws java.io.IOException, OtpErlangDecodeException- Throws:
- java.io.IOException
- OtpErlangDecodeException
 
 - 
recvNameprotected int recvName(OtpPeer apeer) throws java.io.IOException - Throws:
- java.io.IOException
 
 - 
recvChallengeprotected int recvChallenge() throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
recvComplementprotected void recvComplement(int send_name_tag) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
sendChallengeReplyprotected void sendChallengeReply(int challenge, byte[] digest) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
recvChallengeReplyprotected int recvChallengeReply(int our_challenge) throws java.io.IOException, OtpAuthException- Throws:
- java.io.IOException
- OtpAuthException
 
 - 
sendChallengeAckprotected void sendChallengeAck(byte[] digest) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
recvChallengeAckprotected void recvChallengeAck(int our_challenge) throws java.io.IOException, OtpAuthException- Throws:
- java.io.IOException
- OtpAuthException
 
 - 
sendStatusprotected void sendStatus(java.lang.String status) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
recvStatusprotected void recvStatus() throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
setFlagspublic void setFlags(int flags) 
 - 
getFlagspublic int getFlags() 
 
- 
 
-