Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit fd9b96e

Browse files
committed
Add Javadocs for store implementations
1 parent 3042627 commit fd9b96e

File tree

3 files changed

+122
-5
lines changed

3 files changed

+122
-5
lines changed

src/main/java/com/launchdarkly/client/FeatureStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public interface FeatureStore {
6666
void upsert(String key, FeatureRep<?> feature);
6767

6868
/**
69-
* Returns true if this store has been initialized (i.e. if {@link #init(java.util.Map)} has been called)
69+
* Returns true if this store has been initialized
7070
*
7171
* @return true if this store has been initialized
7272
*/

src/main/java/com/launchdarkly/client/InMemoryFeatureStore.java

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,29 @@
44
import java.util.Map;
55
import java.util.concurrent.locks.ReentrantReadWriteLock;
66

7+
/**
8+
* A thread-safe, versioned store for {@link com.launchdarkly.client.FeatureRep} objects based on a
9+
* {@link HashMap}
10+
*
11+
*/
712
public class InMemoryFeatureStore implements FeatureStore {
813

914
final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
1015
final Map<String, FeatureRep<?>> features = new HashMap<String, FeatureRep<?>>();
1116
volatile boolean initialized = false;
1217

18+
19+
/**
20+
*
21+
* Returns the {@link com.launchdarkly.client.FeatureRep} to which the specified key is mapped, or
22+
* null if the key is not associated or the associated {@link com.launchdarkly.client.FeatureRep} has
23+
* been deleted.
24+
*
25+
* @param key the key whose associated {@link com.launchdarkly.client.FeatureRep} is to be returned
26+
* @return the {@link com.launchdarkly.client.FeatureRep} to which the specified key is mapped, or
27+
* null if the key is not associated or the associated {@link com.launchdarkly.client.FeatureRep} has
28+
* been deleted.
29+
*/
1330
@Override
1431
public FeatureRep<?> get(String key) {
1532
try {
@@ -24,6 +41,12 @@ public FeatureRep<?> get(String key) {
2441
}
2542
}
2643

44+
/**
45+
* Returns a {@link java.util.Map} of all associated features.
46+
*
47+
*
48+
* @return a map of all associated features.
49+
*/
2750
@Override
2851
public Map<String, FeatureRep<?>> all() {
2952
try {
@@ -41,18 +64,33 @@ public Map<String, FeatureRep<?>> all() {
4164
}
4265
}
4366

67+
68+
/**
69+
* Initializes (or re-initializes) the store with the specified set of features. Any existing entries
70+
* will be removed.
71+
*
72+
* @param features the features to set the store
73+
*/
4474
@Override
45-
public void init(Map<String, FeatureRep<?>> fs) {
75+
public void init(Map<String, FeatureRep<?>> features) {
4676
try {
4777
lock.writeLock().lock();
4878
this.features.clear();
49-
this.features.putAll(fs);
79+
this.features.putAll(features);
5080
initialized = true;
5181
} finally {
5282
lock.writeLock().unlock();
5383
}
5484
}
5585

86+
/**
87+
*
88+
* Deletes the feature associated with the specified key, if it exists and its version
89+
* is less than or equal to the specified version.
90+
*
91+
* @param key the key of the feature to be deleted
92+
* @param version the version for the delete operation
93+
*/
5694
@Override
5795
public void delete(String key, int version) {
5896
try {
@@ -72,6 +110,13 @@ else if (f == null) {
72110
}
73111
}
74112

113+
/**
114+
* Update or insert the feature associated with the specified key, if its version
115+
* is less than or equal to the version specified in the argument feature.
116+
*
117+
* @param key
118+
* @param feature
119+
*/
75120
@Override
76121
public void upsert(String key, FeatureRep<?> feature) {
77122
try {
@@ -87,6 +132,11 @@ public void upsert(String key, FeatureRep<?> feature) {
87132
}
88133
}
89134

135+
/**
136+
* Returns true if this store has been initialized
137+
*
138+
* @return true if this store has been initialized
139+
*/
90140
@Override
91141
public boolean initialized() {
92142
return initialized;

src/main/java/com/launchdarkly/client/RedisFeatureStore.java

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,47 @@
1515
import java.util.Map;
1616
import java.util.concurrent.TimeUnit;
1717

18+
/**
19+
* A thread-safe, versioned store for {@link com.launchdarkly.client.FeatureRep} objects backed by Redis. Also
20+
* supports an optional in-memory cache configuration that can be used to improve performance.
21+
*
22+
*/
1823
public class RedisFeatureStore implements FeatureStore {
1924
private static final String DEFAULT_PREFIX = "launchdarkly";
2025
private final Jedis jedis;
2126
private LoadingCache<String, FeatureRep<?>> cache;
2227
private String prefix;
2328

29+
/**
30+
*
31+
* @param host the host for the Redis connection
32+
* @param port the port for the Redis connection
33+
* @param prefix a namespace prefix for all keys stored in Redis
34+
* @param cacheTimeSecs an optional timeout for the in-memory cache. If set to 0, no in-memory caching will be performed
35+
*/
2436
public RedisFeatureStore(String host, int port, String prefix, long cacheTimeSecs) {
2537
jedis = new Jedis(host, port);
2638
setPrefix(prefix);
2739
createCache(cacheTimeSecs);
2840
}
2941

42+
/**
43+
* Creates a new store instance that connects to Redis with the provided URI, prefix, and cache timeout.
44+
*
45+
* @param uri the URI for the Redis connection
46+
* @param prefix a namespace prefix for all keys stored in Redis
47+
* @param cacheTimeSecs an optional timeout for the in-memory cache. If set to 0, no in-memory caching will be performed
48+
*/
3049
public RedisFeatureStore(URI uri, String prefix, long cacheTimeSecs) {
3150
jedis = new Jedis(uri);
3251
setPrefix(prefix);
3352
createCache(cacheTimeSecs);
3453
}
3554

55+
/**
56+
* Creates a new store instance that connects to Redis with a default connection (localhost port 6379) and no in-memory cache.
57+
*
58+
*/
3659
public RedisFeatureStore() {
3760
jedis = new Jedis("localhost");
3861
this.prefix = DEFAULT_PREFIX;
@@ -59,7 +82,17 @@ public FeatureRep<?> load(String key) throws Exception {
5982
}
6083
}
6184

62-
85+
/**
86+
*
87+
* Returns the {@link com.launchdarkly.client.FeatureRep} to which the specified key is mapped, or
88+
* null if the key is not associated or the associated {@link com.launchdarkly.client.FeatureRep} has
89+
* been deleted.
90+
*
91+
* @param key the key whose associated {@link com.launchdarkly.client.FeatureRep} is to be returned
92+
* @return the {@link com.launchdarkly.client.FeatureRep} to which the specified key is mapped, or
93+
* null if the key is not associated or the associated {@link com.launchdarkly.client.FeatureRep} has
94+
* been deleted.
95+
*/
6396
@Override
6497
public FeatureRep<?> get(String key) {
6598
if (cache != null) {
@@ -69,6 +102,14 @@ public FeatureRep<?> get(String key) {
69102
}
70103
}
71104

105+
106+
/**
107+
* Returns a {@link java.util.Map} of all associated features. This implementation does not take advantage
108+
* of the in-memory cache, so fetching all features will involve a fetch from Redis.
109+
*
110+
*
111+
* @return a map of all associated features.
112+
*/
72113
@Override
73114
public Map<String, FeatureRep<?>> all() {
74115
Map<String,String> featuresJson = jedis.hgetAll(featuresKey());
@@ -84,7 +125,12 @@ public Map<String, FeatureRep<?>> all() {
84125

85126
return result;
86127
}
87-
128+
/**
129+
* Initializes (or re-initializes) the store with the specified set of features. Any existing entries
130+
* will be removed.
131+
*
132+
* @param features the features to set the store
133+
*/
88134
@Override
89135
public void init(Map<String, FeatureRep<?>> features) {
90136
Gson gson = new Gson();
@@ -99,6 +145,15 @@ public void init(Map<String, FeatureRep<?>> features) {
99145
t.exec();
100146
}
101147

148+
149+
/**
150+
*
151+
* Deletes the feature associated with the specified key, if it exists and its version
152+
* is less than or equal to the specified version.
153+
*
154+
* @param key the key of the feature to be deleted
155+
* @param version the version for the delete operation
156+
*/
102157
@Override
103158
public void delete(String key, int version) {
104159
try {
@@ -126,6 +181,13 @@ public void delete(String key, int version) {
126181

127182
}
128183

184+
/**
185+
* Update or insert the feature associated with the specified key, if its version
186+
* is less than or equal to the version specified in the argument feature.
187+
*
188+
* @param key
189+
* @param feature
190+
*/
129191
@Override
130192
public void upsert(String key, FeatureRep<?> feature) {
131193
try {
@@ -149,6 +211,11 @@ public void upsert(String key, FeatureRep<?> feature) {
149211
}
150212
}
151213

214+
/**
215+
* Returns true if this store has been initialized
216+
*
217+
* @return true if this store has been initialized
218+
*/
152219
@Override
153220
public boolean initialized() {
154221
return jedis.exists(featuresKey());

0 commit comments

Comments
 (0)