Mercurial > lbo > hg > clusterrpc-java
view src/main/java/net/borgac/clusterrpc/client/PeerAddress.java @ 6:0e608c466a58
Implement ClientChannel/SocketWrapper and add logging and tests
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 24 Sep 2016 16:42:13 +0200 |
parents | 117cb812e28a |
children |
line wrap: on
line source
package net.borgac.clusterrpc.client; import java.net.InetSocketAddress; /** * PeerAddress identifies a remote server that a ClientChannel can connect to. * * @author lbo */ public class PeerAddress { private final String host; private final int port; /** * Construct a PeerAddress from a (host,port) tuple. * * @param host * @param port */ public PeerAddress(String host, int port) { this.host = host; this.port = port; } /** * Construct a PeerAddress from an InetSocketAddress. * * @param address Address to use (note: InetSocketAddress performs a host * lookup!) */ public PeerAddress(InetSocketAddress address) { this.host = address.getHostString(); this.port = address.getPort(); } /** * For hermetic testing. * * @param inmemoryAddr An arbitrary string. */ PeerAddress(String inmemoryAddr) { this.host = inmemoryAddr; this.port = 0; } String getConnectAddress() { if (port > 0) { return String.format("tcp://%s:%d", host, port); } else { return String.format("inproc://%s", host); } } }