1
2
3
4
5 package cz.cuni.amis.pogamut.base.communication.connection.impl.socket;
6
7 import java.net.URI;
8 import java.net.URL;
9
10 import com.google.inject.name.Named;
11
12 import cz.cuni.amis.utils.NullCheck;
13
14
15
16
17
18 public class SocketConnectionAddress implements ISocketConnectionAddress {
19
20 public static final String ADDRESS_DEPENDENCY = "HOST_DEPENDENCY";
21
22 private String host;
23 private int port;
24
25 public SocketConnectionAddress(@Named(ADDRESS_DEPENDENCY) SocketConnectionAddress address) {
26 this(address.host, address.port);
27 }
28
29 public SocketConnectionAddress(String host, int port) {
30 this.host = host;
31 NullCheck.check(host, "host");
32 this.port = port;
33 if (port < 0 || port > 65535) throw new IllegalArgumentException("port=" + port + " is out of range.");
34 }
35
36 public SocketConnectionAddress(URL url) {
37 this(url.getHost(), url.getPort());
38 }
39
40 public SocketConnectionAddress(URI uri) {
41 this(uri.getHost(), uri.getPort());
42 }
43
44 @Override
45 public String getHost() {
46 return host;
47 }
48
49 @Override
50 public int getPort() {
51 return port;
52 }
53
54 public String toString() {
55 return "SocketConnectionAddress[" + host + ":" + port + "]";
56 }
57 }