OtpServer
public class OtpSelf extends OtpLocalNode
When the Java node will be connecting to a remote Erlang, Java or C node, it must first identify itself as a node by creating an instance of this class, after which it may connect to the remote node.
When you create an instance of this class, it will bind a socket to a port so
that incoming connections can be accepted. However the port number will not
be made available to other nodes wishing to connect until you explicitely
register with the port mapper daemon by calling publishPort()
.
OtpSelf self = new OtpSelf("client", "authcookie"); // identify self OtpPeer other = new OtpPeer("server"); // identify peer OtpConnection conn = self.connect(other); // connect to peer
epmd, port
Constructor | Description |
---|---|
OtpSelf(java.lang.String node) |
Create a self node using the default cookie.
|
OtpSelf(java.lang.String node,
java.lang.String cookie) |
Create a self node.
|
OtpSelf(java.lang.String node,
java.lang.String cookie,
int port) |
Modifier and Type | Method | Description |
---|---|---|
OtpConnection |
accept() |
Accept an incoming connection from a remote node.
|
OtpConnection |
connect(OtpPeer other) |
Open a connection to a remote node.
|
OtpErlangPid |
pid() |
Get the Erlang PID that will be used as the sender id in all "anonymous"
messages sent by this node.
|
boolean |
publishPort() |
Make public the information needed by remote nodes that may wish to
connect to this one.
|
void |
unPublishPort() |
Unregister the server node's name and port number from the Erlang port
mapper, thus preventing any new connections from remote nodes.
|
alive, cookie, host, node, setCookie, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createPid, createPort, createRef, getEpmd, port, setEpmd
public OtpSelf(java.lang.String node) throws java.io.IOException
Create a self node using the default cookie. The default cookie is found by reading the first line of the .erlang.cookie file in the user's home directory. The home directory is obtained from the System property "user.home".
If the file does not exist, an empty string is used. This method makes no attempt to create the file.
node
- the name of this node.java.io.IOException
public OtpSelf(java.lang.String node, java.lang.String cookie) throws java.io.IOException
node
- the name of this node.cookie
- the authorization cookie that will be used by this node
when it communicates with other nodes.java.io.IOException
public OtpSelf(java.lang.String node, java.lang.String cookie, int port) throws java.io.IOException
java.io.IOException
public OtpErlangPid pid()
OtpConnection
that do not specify a
sender.public boolean publishPort() throws java.io.IOException
This method will fail if an Epmd process is not running on the localhost. See the Erlang documentation for information about starting Epmd.
Note that once this method has been called, the node is expected to be
available to accept incoming connections. For that reason you should make
sure that you call accept()
shortly after calling
publishPort()
. When you no longer intend to accept connections
you should call unPublishPort()
.
java.io.IOException
- if the port mapper could not be contacted.public void unPublishPort()
public OtpConnection accept() throws java.io.IOException, OtpAuthException
java.io.IOException
- if a remote node attempted to connect but no common
protocol was found.OtpAuthException
- if a remote node attempted to connect, but was not
authorized to connect.public OtpConnection connect(OtpPeer other) throws java.io.IOException, java.net.UnknownHostException, OtpAuthException
other
- the remote node to which you wish to connect.java.net.UnknownHostException
- if the remote host could not be found.java.io.IOException
- if it was not possible to connect to the remote node.OtpAuthException
- if the connection was refused by the remote node.