Class AbstractConnection

java.lang.Object
java.lang.Thread
com.ericsson.otp.erlang.AbstractConnection
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
OtpConnection, OtpCookedConnection

public abstract class AbstractConnection extends Thread
Maintains 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 Details Link icon

  • Constructor Details Link icon

  • Method Details Link icon

    • deliver Link icon

      public abstract void deliver(Exception e)
      Deliver communication exceptions to the recipient.
    • deliver Link icon

      public abstract void deliver(OtpMsg msg)
      Deliver messages to the recipient.
    • sendBuf Link icon

      protected void sendBuf(OtpErlangPid from, String dest, OtpOutputStream payload) throws 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:
      IOException - if the connection is not active or a communication error occurs.
    • sendBuf Link icon

      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 Link icon

      protected void sendLink(OtpErlangPid from, OtpErlangPid dest) throws IOException
      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 Link icon

      protected void sendUnlink(OtpErlangPid from, OtpErlangPid dest, long unlink_id) throws IOException
      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 Link icon

      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 Link icon

      protected void sendExit(OtpErlangPid from, OtpErlangPid dest, OtpErlangObject reason) throws IOException
      Throws:
      IOException
    • sendExit2 Link icon

      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 Link icon

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • setTraceLevel Link icon

      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 Link icon

      public int getTraceLevel()
      Get the trace level for this connection.
      Returns:
      the current trace level.
    • close Link icon

      public void close()
      Close the connection to the remote node.
    • finalize Link icon

      protected void finalize()
      Overrides:
      finalize in class Object
    • isConnected Link icon

      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 Link icon

      protected void do_send(OtpOutputStream header, OtpOutputStream payload) throws IOException
      Throws:
      IOException
    • do_send Link icon

      protected void do_send(OtpOutputStream header) throws IOException
      Throws:
      IOException
    • headerType Link icon

      protected String headerType(OtpErlangObject h)
    • readSock Link icon

      protected int readSock(OtpTransport s, byte[] b) throws IOException
      Throws:
      IOException
    • doAccept Link icon

      protected void doAccept() throws IOException, OtpAuthException
      Throws:
      IOException
      OtpAuthException
    • doConnect Link icon

      protected void doConnect(int port) throws IOException, OtpAuthException
      Throws:
      IOException
      OtpAuthException
    • genChallenge Link icon

      protected static int genChallenge()
    • genDigest Link icon

      protected byte[] genDigest(int challenge, String cookie)
    • sendName Link icon

      protected int sendName(int dist, long aflags, int creation) throws IOException
      Throws:
      IOException
    • sendComplement Link icon

      protected void sendComplement(int send_name_tag) throws IOException
      Throws:
      IOException
    • sendChallenge Link icon

      protected void sendChallenge(long her_flags, long our_flags, int challenge) throws IOException
      Throws:
      IOException
    • read2BytePackage Link icon

      protected byte[] read2BytePackage() throws IOException, OtpErlangDecodeException
      Throws:
      IOException
      OtpErlangDecodeException
    • recvName Link icon

      protected int recvName(OtpPeer apeer) throws IOException
      Throws:
      IOException
    • recvChallenge Link icon

      protected int recvChallenge() throws IOException
      Throws:
      IOException
    • recvComplement Link icon

      protected void recvComplement(int send_name_tag) throws IOException
      Throws:
      IOException
    • sendChallengeReply Link icon

      protected void sendChallengeReply(int challenge, byte[] digest) throws IOException
      Throws:
      IOException
    • recvChallengeReply Link icon

      protected int recvChallengeReply(int our_challenge) throws IOException, OtpAuthException
      Throws:
      IOException
      OtpAuthException
    • sendChallengeAck Link icon

      protected void sendChallengeAck(byte[] digest) throws IOException
      Throws:
      IOException
    • recvChallengeAck Link icon

      protected void recvChallengeAck(int our_challenge) throws IOException, OtpAuthException
      Throws:
      IOException
      OtpAuthException
    • sendStatus Link icon

      protected void sendStatus(String status) throws IOException
      Throws:
      IOException
    • recvStatus Link icon

      protected void recvStatus() throws IOException
      Throws:
      IOException
    • setFlags Link icon

      public void setFlags(int flags)
    • getFlags Link icon

      public int getFlags()