-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
InternalEurekaStatusModule.java
77 lines (69 loc) · 2.25 KB
/
InternalEurekaStatusModule.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.netflix.discovery;
import javax.inject.Inject;
import javax.inject.Singleton;
import com.google.common.base.Supplier;
import com.google.inject.AbstractModule;
import com.google.inject.Provider;
import com.google.inject.TypeLiteral;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.governator.annotations.binding.DownStatus;
import com.netflix.governator.annotations.binding.UpStatus;
/**
* Specific bindings for eureka status checker.
*
* Note that this is an internal modules and ASSUMES that a binding for
* DiscoveryClient was already set.
*
* Exposed bindings,
*
* @UpStatus Supplier<Boolean>
* @DownStatus Supplier<Boolean>
* @UpStatus Observable<Boolean>
*
* @author elandau
*
*/
@Singleton
public class InternalEurekaStatusModule extends AbstractModule {
@Singleton
public static class UpStatusProvider implements Provider<Supplier<Boolean>> {
@Inject
private Provider<EurekaUpStatusResolver> upStatus;
@Override
public Supplier<Boolean> get() {
final EurekaUpStatusResolver resolver = upStatus.get();
return new Supplier<Boolean>() {
@Override
public Boolean get() {
return resolver.getStatus().equals(InstanceInfo.InstanceStatus.UP);
}
};
}
}
@Singleton
public static class DownStatusProvider implements Provider<Supplier<Boolean>> {
@Inject
private Provider<EurekaUpStatusResolver> upStatus;
@Override
public Supplier<Boolean> get() {
final EurekaUpStatusResolver resolver = upStatus.get();
return new Supplier<Boolean>() {
@Override
public Boolean get() {
return !resolver.getStatus().equals(InstanceInfo.InstanceStatus.UP);
}
};
}
}
@Override
protected void configure() {
bind(new TypeLiteral<Supplier<Boolean>>() {
})
.annotatedWith(UpStatus.class)
.toProvider(UpStatusProvider.class);
bind(new TypeLiteral<Supplier<Boolean>>() {
})
.annotatedWith(DownStatus.class)
.toProvider(DownStatusProvider.class);
}
}