AMashenkov commented on code in PR #5004:
URL: https://github.com/apache/ignite-3/pull/5004#discussion_r1905736856
##########
modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/impl/ConfigurationBasedChannelRegistry.java:
##########
@@ -35,73 +34,57 @@
import org.apache.ignite.internal.eventlog.config.schema.ChannelView;
import org.apache.ignite.internal.eventlog.config.schema.EventLogConfiguration;
-class ConfigurationBasedChannelRegistry implements ChannelRegistry {
- private final ReadWriteLock guard;
+public class ConfigurationBasedChannelRegistry implements ChannelRegistry {
+ private final AtomicReference<Map<String, EventChannel>> cache;
- private final Map<String, EventChannel> cache;
-
- private final Map<String, Set<EventChannel>> typeCache;
+ private final AtomicReference<Map<String, Set<EventChannel>>> typeCache;
private final SinkRegistry sinkRegistry;
- ConfigurationBasedChannelRegistry(EventLogConfiguration cfg, SinkRegistry
sinkRegistry) {
- this.guard = new ReentrantReadWriteLock();
- this.cache = new HashMap<>();
- this.typeCache = new HashMap<>();
+ public ConfigurationBasedChannelRegistry(EventLogConfiguration cfg,
SinkRegistry sinkRegistry) {
+ this.cache = new AtomicReference<>(new HashMap<>());
+ this.typeCache = new AtomicReference<>(new HashMap<>());
this.sinkRegistry = sinkRegistry;
cfg.channels().listen(new CacheUpdater());
}
@Override
public EventChannel getByName(String name) {
- guard.readLock().lock();
- try {
- return cache.get(name);
- } finally {
- guard.readLock().unlock();
- }
+ return cache.get().get(name);
}
@Override
public Set<EventChannel> findAllChannelsByEventType(String
igniteEventType) {
- guard.readLock().lock();
- try {
- Set<EventChannel> result = typeCache.get(igniteEventType);
- return result == null ? Set.of() : new HashSet<>(result);
- } finally {
- guard.readLock().unlock();
- }
+ Set<EventChannel> result = typeCache.get().get(igniteEventType);
+ return result == null ? Set.of() : new HashSet<>(result);
Review Comment:
No need to copy `result`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]