Skip to content

Commit f051b31

Browse files
committed
wip
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 27955de commit f051b31

3 files changed

Lines changed: 65 additions & 0 deletions

File tree

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ResourceCache.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,22 @@
2424
@SuppressWarnings("unchecked")
2525
public interface ResourceCache<T extends HasMetadata> extends Cache<T> {
2626

27+
/**
28+
* Lists all resources in the given namespace.
29+
*
30+
* @param namespace the namespace to list resources from
31+
* @return a stream of all cached resources in the namespace
32+
*/
2733
default Stream<T> list(String namespace) {
2834
return list(namespace, TRUE);
2935
}
3036

37+
/**
38+
* Lists resources in the given namespace that match the provided predicate.
39+
*
40+
* @param namespace the namespace to list resources from
41+
* @param predicate filter to apply on the resources
42+
* @return a stream of cached resources matching the predicate
43+
*/
3144
Stream<T> list(String namespace, Predicate<T> predicate);
3245
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/Cache.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,45 @@
2525
public interface Cache<T> {
2626
Predicate TRUE = (a) -> true;
2727

28+
/**
29+
* Retrieves a resource from the cache by its {@link ResourceID}.
30+
*
31+
* @param resourceID the identifier of the resource
32+
* @return an optional containing the resource if present in the cache
33+
*/
2834
Optional<T> get(ResourceID resourceID);
2935

36+
/**
37+
* Checks whether a resource with the given {@link ResourceID} exists in the cache.
38+
*
39+
* @param resourceID the identifier of the resource
40+
* @return {@code true} if the resource is present in the cache
41+
*/
3042
default boolean contains(ResourceID resourceID) {
3143
return get(resourceID).isPresent();
3244
}
3345

46+
/**
47+
* Returns a stream of all {@link ResourceID}s currently in the cache.
48+
*
49+
* @return a stream of resource identifiers
50+
*/
3451
Stream<ResourceID> keys();
3552

53+
/**
54+
* Lists all resources in the cache.
55+
*
56+
* @return a stream of all cached resources
57+
*/
3658
default Stream<T> list() {
3759
return list(TRUE);
3860
}
3961

62+
/**
63+
* Lists resources in the cache that match the provided predicate.
64+
*
65+
* @param predicate filter to apply on the resources
66+
* @return a stream of cached resources matching the predicate
67+
*/
4068
Stream<T> list(Predicate<T> predicate);
4169
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,47 @@ public void addIndexers(Map<String, Function<R, List<String>>> indexers) {
234234
this.indexers.putAll(indexers);
235235
}
236236

237+
/**
238+
* {@inheritDoc}
239+
*
240+
* <p>This implementation is read-cache-after-write consistent. Results are merged with the
241+
* temporary resource cache to ensure recently written resources are reflected in the output.
242+
*/
237243
@Override
238244
public Stream<R> list(String namespace, Predicate<R> predicate) {
239245
return mergeWithWithTempCacheResources(
240246
manager().list(namespace, predicate), namespace, predicate);
241247
}
242248

249+
/**
250+
* {@inheritDoc}
251+
*
252+
* <p>This implementation is read-cache-after-write consistent. Results are merged with the
253+
* temporary resource cache to ensure recently written resources are reflected in the output.
254+
*/
243255
@Override
244256
public Stream<R> list(Predicate<R> predicate) {
245257
return mergeWithWithTempCacheResources(cache.list(predicate), null, predicate);
246258
}
247259

260+
/**
261+
* {@inheritDoc}
262+
*
263+
* <p>This implementation is read-cache-after-write consistent. Results are merged with the
264+
* temporary resource cache to ensure recently written resources are reflected in the output.
265+
*/
248266
@Override
249267
public Stream<R> byIndexStream(String indexName, String indexKey) {
250268
return mergeWithWithTempCacheResources(
251269
manager().byIndexStream(indexName, indexKey), indexName, indexKey);
252270
}
253271

272+
/**
273+
* {@inheritDoc}
274+
*
275+
* <p>This implementation is read-cache-after-write consistent. Results are merged with the
276+
* temporary resource cache to ensure recently written resources are reflected in the output.
277+
*/
254278
@Override
255279
public List<R> byIndex(String indexName, String indexKey) {
256280
return mergeWithWithTempCacheResources(

0 commit comments

Comments
 (0)