Skip to content

Commit 82a1f43

Browse files
KingMobRobWin
authored andcommitted
Added a Registry.find() (ReactiveX#478)
Add find() method that will only return an existing object in a Registry but will not create a new one.
1 parent fb143f3 commit 82a1f43

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

resilience4j-core/src/main/java/io/github/resilience4j/core/Registry.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ public interface Registry<E, C> {
3838
*/
3939
void addConfiguration(String configName, C configuration);
4040

41+
/**
42+
* Find a named entry in the Registry
43+
*
44+
* @param name the name
45+
*/
46+
Optional<E> find(String name);
47+
4148
/**
4249
* Remove an entry from the Registry
4350
*

resilience4j-core/src/main/java/io/github/resilience4j/core/registry/AbstractRegistry.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ protected E computeIfAbsent(String name, Supplier<E> supplier){
5858
});
5959
}
6060

61+
@Override
62+
public Optional<E> find(String name){
63+
return Optional.ofNullable(entryMap.get(name));
64+
}
65+
6166
@Override
6267
public Optional<E> remove(String name){
6368
Optional<E> removedEntry = Optional.ofNullable(entryMap.remove(name));

resilience4j-core/src/test/java/io/github/resilience4j/core/registry/AbstractRegistryTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ public void shouldConsumeRegistryEvents() {
7676

7777
}
7878

79+
@Test
80+
public void shouldOnlyFindRegisteredObjects() {
81+
TestRegistry testRegistry = new TestRegistry();
82+
83+
assertThat(testRegistry.find("test")).isEmpty();
84+
testRegistry.entryMap.put("test", "value");
85+
assertThat(testRegistry.find("test")).contains("value");
86+
}
87+
88+
7989
class TestRegistry extends AbstractRegistry<String, String> {
8090

8191
public TestRegistry() {
@@ -85,4 +95,4 @@ public TestRegistry() {
8595
}
8696
}
8797

88-
}
98+
}

0 commit comments

Comments
 (0)