| 105 | } |
| 106 | |
| 107 | public Host get(final String key) throws IOException { |
| 108 | Callable<CacheHost> valueLoader = new Callable<CacheHost>() { |
| 109 | @Override |
| 110 | public CacheHost call() throws Exception { |
| 111 | Host host = hostStore.get(key); |
| 112 | if (host == null) |
| 113 | return NULL_HOST; |
| 114 | return new CacheHost(host, System.currentTimeMillis()); |
| 115 | } |
| 116 | }; |
| 117 | CacheHost cachedHost; |
| 118 | try { |
| 119 | cachedHost = cache.get(key, valueLoader); |
| 120 | } catch (ExecutionException e) { |
| 121 | throw new RuntimeException(e); |
| 122 | } |
| 123 | if (cachedHost != NULL_HOST) { |
| 124 | return cachedHost.host; |
| 125 | } else { |
| 126 | return null; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | public Host getByHostName(String hostName) throws IOException { |
| 131 | return get(TableUtil.reverseHost(hostName)); |