blob: 4ae6122becd1a35205ec481182ad19f267b65c3e (
plain) (
blame)
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.subscription;
import com.yahoo.config.ConfigInstance;
import com.yahoo.config.subscription.impl.ConfigSubscription;
/**
* A config handle represents one config in the context of one active subscription on a {@link ConfigSubscriber}.
* It will contain metadata of the subscription of that particular config, as well as access to the {@link com.yahoo.config.ConfigInstance} itself.
*
* @param <T> the type of the config
* @author vegardh
*/
public class ConfigHandle<T extends ConfigInstance> {
private final ConfigSubscription<T> sub;
private boolean changed = false;
protected ConfigHandle(ConfigSubscription<T> sub) {
this.sub = sub;
}
/**
* Returns true if:
* The config generation for the {@link ConfigSubscriber} that produced this is the first one in its life cycle. (Typically first time config.)
* or
* All configs for the subscriber have a new generation since the last time nextConfig() was called
* AND it's the same generation AND there is a change in <strong>this</strong> handle's config.
* (Typically calls for a reconfig.)
*
* @return there is a new config
*/
public boolean isChanged() {
return changed;
}
void setChanged(boolean changed) {
this.changed = changed;
}
ConfigSubscription<T> subscription() {
return sub;
}
/**
* The config of this handle
*
* @return the config that this handle holds
*/
public T getConfig() {
// TODO throw if subscriber not frozen?
return sub.getConfigState().getConfig();
}
@Override
public String toString() {
return "Handle changed: " + changed + "\nSub:\n" + sub.toString();
}
}
|