-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added event listener for connection manager
- Loading branch information
Showing
25 changed files
with
403 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/io/tarantool/driver/cluster/DiscoveryServiceEventManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.tarantool.driver.cluster; | ||
|
||
import io.tarantool.driver.core.connection.EventListener; | ||
import io.tarantool.driver.core.connection.EventManager; | ||
import io.tarantool.driver.core.connection.EventType; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* Implementation of event manager which manage events for discovery service | ||
* | ||
* @author Oleg Kuznetsov | ||
*/ | ||
public class DiscoveryServiceEventManager implements EventManager { | ||
|
||
private final Map<EventType, Set<EventListener>> listeners; | ||
|
||
public DiscoveryServiceEventManager() { | ||
this.listeners = new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public void subscribe(EventType type, EventListener listener) { | ||
Set<EventListener> eventListeners = getEventListeners(type); | ||
eventListeners.add(listener); | ||
} | ||
|
||
@Override | ||
public void unsubscribe(EventType type, EventListener listener) { | ||
final Set<EventListener> eventListeners = listeners.get(type); | ||
if (eventListeners != null) { | ||
eventListeners.remove(listener); | ||
} | ||
} | ||
|
||
@Override | ||
public void unsubscribe(EventType type) { | ||
listeners.remove(type); | ||
} | ||
|
||
@Override | ||
public void notify(EventType type) { | ||
getEventListeners(type).forEach(EventListener::update); | ||
} | ||
|
||
private Set<EventListener> getEventListeners(EventType type) { | ||
return listeners.computeIfAbsent(type, k -> new HashSet<>()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.