public boolean addStateListener(final K id, final StateListener listener) {
        List<StateListener> group = this.stateListeners.get(id);
        if (group == null) {
            final List<StateListener> newGroup = new CopyOnWriteArrayList<>();
            group = this.stateListeners.putIfAbsent(id, newGroup);
            if (group == null) {
                group = newGroup;
            }
        }
        return group.add(listener);
    }
The container of raft state listener, each key(id) corresponds to a listener group.

@author jiachun.fjc
jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/StateListenerContainer.java