1 /* 2 * %CopyrightBegin% 3 * 4 * Copyright Ericsson AB 2000-2016. All Rights Reserved. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * %CopyrightEnd% 19 */ 20 package com.ericsson.otp.erlang; 21 22 import java.io.IOException; 23 import java.net.UnknownHostException; 24 25 /** 26 * Represents a remote OTP node. It acts only as a container for the nodename 27 * and other node-specific information that is needed by the 28 * {@link OtpConnection} class. 29 */ 30 public class OtpPeer extends AbstractNode { 31 int distChoose = 0; /* 32 * this is set by OtpConnection and is the highest 33 * common protocol version we both support 34 */ 35 OtpPeer(final OtpTransportFactory transportFactory)36 OtpPeer(final OtpTransportFactory transportFactory) { 37 super(transportFactory); 38 } 39 40 /** 41 * Create a peer node. 42 * 43 * @param node 44 * the name of the node. 45 */ OtpPeer(final String node)46 public OtpPeer(final String node) { 47 super(node); 48 } 49 50 /** 51 * Create a peer node with custom transport factory. 52 * 53 * @param node 54 * the name of the node. 55 * @param transportFactory 56 * custom transport factory 57 */ OtpPeer(final String node, final OtpTransportFactory transportFactory)58 public OtpPeer(final String node, final OtpTransportFactory 59 transportFactory) { 60 super(node, transportFactory); 61 } 62 63 /** 64 * Create a connection to a remote node. 65 * 66 * @param self 67 * the local node from which you wish to connect. 68 * 69 * @return a connection to the remote node. 70 * 71 * @exception java.net.UnknownHostException 72 * if the remote host could not be found. 73 * 74 * @exception java.io.IOException 75 * if it was not possible to connect to the remote node. 76 * 77 * @exception OtpAuthException 78 * if the connection was refused by the remote node. 79 * 80 * @deprecated Use the corresponding method in {@link OtpSelf} instead. 81 */ 82 @Deprecated connect(final OtpSelf self)83 public OtpConnection connect(final OtpSelf self) throws IOException, 84 UnknownHostException, OtpAuthException { 85 return new OtpConnection(self, this); 86 } 87 88 // package 89 /* 90 * Get the port number used by the remote node. 91 * 92 * @return the port number used by the remote node, or 0 if the node was not 93 * registered with the port mapper. 94 * 95 * @exception java.io.IOException if the port mapper could not be contacted. 96 */ port()97 int port() throws IOException { 98 return OtpEpmd.lookupPort(this); 99 } 100 } 101