(InetSocketAddress addr)
| 97 | } |
| 98 | |
| 99 | public Server queryByAddress(InetSocketAddress addr) throws Exception { |
| 100 | List<Server> all = this.queryAll(); |
| 101 | if (addr.getAddress() == null) { |
| 102 | |
| 103 | throw new Exception(String.format("cannot resolv hostname: %s", addr.getHostName())); |
| 104 | } |
| 105 | if (addr.getPort() == 0) { |
| 106 | |
| 107 | throw new Exception("cannot resolv portnumber: 0"); |
| 108 | } |
| 109 | String target = addr.getAddress().getHostAddress(); |
| 110 | for (Server server : all) { |
| 111 | |
| 112 | List<InetAddress> ips = server.getIps(); |
| 113 | for (InetAddress ip : ips) { |
| 114 | |
| 115 | if (ip.getHostAddress().equals(target) && server.getPort() == addr.getPort()) { |
| 116 | |
| 117 | return server; |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | return null; |
| 122 | } |
| 123 | |
| 124 | public Server queryByHostName(String hostname) throws Exception { |
| 125 | List<Server> ret = cache.query("queryByHostName", hostname); |
no test coverage detected