Class OtpConnection
- All Implemented Interfaces:
Runnable
Once a connection is established between the local node and a remote node, the connection object can be used to send and receive messages between the nodes and make rpc calls (assuming that the remote node is a real Erlang node).
The various receive methods are all blocking and will return only when a valid message has been received or an exception is raised.
If an exception occurs in any of the methods in this class, the connection will be closed and must be explicitly reopened in order to resume communication with the peer.
It is not possible to create an instance of this class directly.
OtpConnection objects are returned by OtpSelf.connect()
and OtpSelf.accept()
.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Modifier and TypeFieldDescriptionprotected com.ericsson.otp.erlang.Links
protected GenericQueue
protected OtpSelf
Fields inherited from class com.ericsson.otp.erlang.AbstractConnection
ChallengeAck, ChallengeReply, ChallengeStatus, connected, cookieOk, ctrlThreshold, defaultLevel, exit2Tag, exit2TTTag, exitTag, exitTTTag, groupLeaderTag, handshakeThreshold, headerLen, linkTag, localNode, passThrough, peer, random, regSendTag, regSendTTTag, sendCookie, sendTag, sendThreshold, sendTTTag, socket, traceLevel, unlinkIdAckTag, unlinkIdTag, unlinkTag, version
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Deliver messages to the recipient.void
Deliver communication exceptions to the recipient.void
exit
(OtpErlangPid dest, OtpErlangObject reason) Send an exit signal to a remote process.void
link
(OtpErlangPid dest) Create a link between the local node and the specified process on the remote node.int
msgCount()
Return the number of messages currently waiting in the receive queue for this connection.peer()
Get information about the node at the peer end of this connection.receive()
Receive a message from a remote process.receive
(long timeout) Receive a message from a remote process.Receive a raw (still encoded) message from a remote process.receiveBuf
(long timeout) Receive a raw (still encoded) message from a remote process.Receive a message complete with sender and recipient information.receiveMsg
(long timeout) Receive a message complete with sender and recipient information.Receive an RPC reply from the remote Erlang node.self()
Get information about the node at the local end of this connection.void
send
(OtpErlangPid dest, OtpErlangObject msg) Send a message to a process on a remote node.void
send
(String dest, OtpErlangObject msg) Send a message to a named process on a remote node.void
sendBuf
(OtpErlangPid dest, OtpOutputStream payload) Send a pre-encoded message to a process on a remote node.void
sendBuf
(String dest, OtpOutputStream payload) Send a pre-encoded message to a named process on a remote node.void
sendRPC
(String mod, String fun, OtpErlangList args) Send an RPC request to the remote Erlang node.void
sendRPC
(String mod, String fun, OtpErlangObject[] args) Send an RPC request to the remote Erlang node.void
unlink
(OtpErlangPid dest) Remove a link between the local node and the specified process on the remote node.Methods inherited from class com.ericsson.otp.erlang.AbstractConnection
close, do_send, do_send, doAccept, doConnect, doGenericConnect, doPortConnect, finalize, genChallenge, genDigest, getFlags, getTraceLevel, headerType, isConnected, read2BytePackage, readSock, recvChallenge, recvChallengeAck, recvChallengeReply, recvComplement, recvName, recvStatus, run, sendBuf, sendBuf, sendChallenge, sendChallengeAck, sendChallengeReply, sendExit, sendExit2, sendLink, sendName, sendStatus, sendUnlink, sendUnlinkAck, setFlags, setTraceLevel
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
-
self
-
queue
-
links
protected com.ericsson.otp.erlang.Links links
-
-
Method Details
-
deliver
Description copied from class:AbstractConnection
Deliver communication exceptions to the recipient.- Specified by:
deliver
in classAbstractConnection
-
deliver
Description copied from class:AbstractConnection
Deliver messages to the recipient.- Specified by:
deliver
in classAbstractConnection
-
peer
Get information about the node at the peer end of this connection.- Returns:
- the
Node
representing the peer node.
-
self
Get information about the node at the local end of this connection.- Returns:
- the
Node
representing the local node.
-
msgCount
public int msgCount()Return the number of messages currently waiting in the receive queue for this connection. -
receive
Receive a message from a remote process. This method blocks until a valid message is received or an exception is raised.If the remote node sends a message that cannot be decoded properly, the connection is closed and the method throws an exception.
- Returns:
- an object containing a single Erlang term.
- Throws:
IOException
- if the connection is not active or a communication error occurs.OtpErlangExit
- if an exit signal is received from a process on the peer node.OtpAuthException
- if the remote node sends a message containing an invalid cookie.
-
receive
public OtpErlangObject receive(long timeout) throws InterruptedException, IOException, OtpErlangExit, OtpAuthException Receive a message from a remote process. This method blocks at most for the specified time, until a valid message is received or an exception is raised.If the remote node sends a message that cannot be decoded properly, the connection is closed and the method throws an exception.
- Parameters:
timeout
- the time in milliseconds that this operation will block. Specify 0 to poll the queue.- Returns:
- an object containing a single Erlang term.
- Throws:
IOException
- if the connection is not active or a communication error occurs.OtpErlangExit
- if an exit signal is received from a process on the peer node.OtpAuthException
- if the remote node sends a message containing an invalid cookie.InterruptedException
- if no message if the method times out before a message becomes available.
-
receiveBuf
Receive a raw (still encoded) message from a remote process. This message blocks until a valid message is received or an exception is raised.If the remote node sends a message that cannot be decoded properly, the connection is closed and the method throws an exception.
- Returns:
- an object containing a raw (still encoded) Erlang term.
- Throws:
IOException
- if the connection is not active or a communication error occurs.OtpErlangExit
- if an exit signal is received from a process on the peer node, or if the connection is lost for any reason.OtpAuthException
- if the remote node sends a message containing an invalid cookie.
-
receiveBuf
public OtpInputStream receiveBuf(long timeout) throws InterruptedException, IOException, OtpErlangExit, OtpAuthException Receive a raw (still encoded) message from a remote process. This message blocks at most for the specified time until a valid message is received or an exception is raised.If the remote node sends a message that cannot be decoded properly, the connection is closed and the method throws an exception.
- Parameters:
timeout
- the time in milliseconds that this operation will block. Specify 0 to poll the queue.- Returns:
- an object containing a raw (still encoded) Erlang term.
- Throws:
IOException
- if the connection is not active or a communication error occurs.OtpErlangExit
- if an exit signal is received from a process on the peer node, or if the connection is lost for any reason.OtpAuthException
- if the remote node sends a message containing an invalid cookie.InterruptedException
- if no message if the method times out before a message becomes available.
-
receiveMsg
Receive a message complete with sender and recipient information.- Returns:
- an
OtpMsg
containing the header information about the sender and recipient, as well as the actual message contents. - Throws:
IOException
- if the connection is not active or a communication error occurs.OtpErlangExit
- if an exit signal is received from a process on the peer node, or if the connection is lost for any reason.OtpAuthException
- if the remote node sends a message containing an invalid cookie.
-
receiveMsg
public OtpMsg receiveMsg(long timeout) throws InterruptedException, IOException, OtpErlangExit, OtpAuthException Receive a message complete with sender and recipient information. This method blocks at most for the specified time.- Parameters:
timeout
- the time in milliseconds that this operation will block. Specify 0 to poll the queue.- Returns:
- an
OtpMsg
containing the header information about the sender and recipient, as well as the actual message contents. - Throws:
IOException
- if the connection is not active or a communication error occurs.OtpErlangExit
- if an exit signal is received from a process on the peer node, or if the connection is lost for any reason.OtpAuthException
- if the remote node sends a message containing an invalid cookie.InterruptedException
- if no message if the method times out before a message becomes available.
-
send
Send a message to a process on a remote node.- Parameters:
dest
- the Erlang PID of the remote process.msg
- the message to send.- Throws:
IOException
- if the connection is not active or a communication error occurs.
-
send
Send a message to a named process on a remote node.- Parameters:
dest
- the name of the remote process.msg
- the message to send.- Throws:
IOException
- if the connection is not active or a communication error occurs.
-
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
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.
-
sendRPC
Send an RPC request to the remote Erlang node. This convenience function creates the following message and sends it to 'rex' on the remote node:{ self, { call, Mod, Fun, Args, user } }
Note that this method has unpredicatble results if the remote node is not an Erlang node.
- Parameters:
mod
- the name of the Erlang module containing the function to be called.fun
- the name of the function to call.args
- an array of Erlang terms, to be used as arguments to the function.- Throws:
IOException
- if the connection is not active or a communication error occurs.
-
sendRPC
Send an RPC request to the remote Erlang node. This convenience function creates the following message and sends it to 'rex' on the remote node:{ self, { call, Mod, Fun, Args, user } }
Note that this method has unpredicatble results if the remote node is not an Erlang node.
- Parameters:
mod
- the name of the Erlang module containing the function to be called.fun
- the name of the function to call.args
- a list of Erlang terms, to be used as arguments to the function.- Throws:
IOException
- if the connection is not active or a communication error occurs.
-
receiveRPC
Receive an RPC reply from the remote Erlang node. This convenience function receives a message from the remote node, and expects it to have the following format:{ rex, Term }
- Returns:
- the second element of the tuple if the received message is a two-tuple, otherwise null. No further error checking is performed.
- Throws:
IOException
- if the connection is not active or a communication error occurs.OtpErlangExit
- if an exit signal is received from a process on the peer node.OtpAuthException
- if the remote node sends a message containing an invalid cookie.
-
link
Create a link between the local node and the specified process on the remote node. If the link is still active when the remote process terminates, an exit signal will be sent to this connection. Useunlink()
to remove the link.- Parameters:
dest
- the Erlang PID of the remote process.- Throws:
IOException
- if the connection is not active or a communication error occurs.
-
unlink
Remove a link between the local node and the specified process on the remote node. This method deactivates links created withlink()
.- Parameters:
dest
- the Erlang PID of the remote process.- Throws:
IOException
- if the connection is not active or a communication error occurs.
-
exit
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.
-