1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.ipc;
19
20 import org.apache.hadoop.conf.Configuration;
21 import org.apache.hadoop.hbase.classification.InterfaceAudience;
22 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
23 import org.apache.hadoop.hbase.util.Pair;
24
25 import java.net.InetSocketAddress;
26 import java.util.Iterator;
27 import java.util.LinkedList;
28
29
30
31
32 @InterfaceAudience.Private
33 public class FailedServers {
34 private final LinkedList<Pair<Long, String>> failedServers = new
35 LinkedList<Pair<Long, String>>();
36 private final int recheckServersTimeout;
37
38 public FailedServers(Configuration conf) {
39 this.recheckServersTimeout = conf.getInt(
40 RpcClient.FAILED_SERVER_EXPIRY_KEY, RpcClient.FAILED_SERVER_EXPIRY_DEFAULT);
41 }
42
43
44
45
46 public synchronized void addToFailedServers(InetSocketAddress address) {
47 final long expiry = EnvironmentEdgeManager.currentTime() + recheckServersTimeout;
48 failedServers.addFirst(new Pair<Long, String>(expiry, address.toString()));
49 }
50
51
52
53
54
55
56 public synchronized boolean isFailedServer(final InetSocketAddress address) {
57 if (failedServers.isEmpty()) {
58 return false;
59 }
60
61 final String lookup = address.toString();
62 final long now = EnvironmentEdgeManager.currentTime();
63
64
65 Iterator<Pair<Long, String>> it = failedServers.iterator();
66 while (it.hasNext()) {
67 Pair<Long, String> cur = it.next();
68 if (cur.getFirst() < now) {
69 it.remove();
70 } else {
71 if (lookup.equals(cur.getSecond())) {
72 return true;
73 }
74 }
75 }
76
77 return false;
78 }
79 }