Search in sources :

Example 1 with StateListener

use of com.alipay.sofa.jraft.rhea.StateListener in project sofa-jraft by sofastack.

the class KVStoreStateMachine method onLeaderStop.

@Override
public void onLeaderStop(final Status status) {
    super.onLeaderStop(status);
    final long oldTerm = this.leaderTerm.get();
    this.leaderTerm.set(-1L);
    // Because of the raft state machine must be a sequential commit, in order to prevent the user
    // doing something (needs to go through the raft state machine) in the listeners, we asynchronously
    // triggers the listeners.
    final List<StateListener> listeners = // 
    this.storeEngine.getStateListenerContainer().getStateListenerGroup(getRegionId());
    if (listeners.isEmpty()) {
        return;
    }
    this.storeEngine.getRaftStateTrigger().execute(() -> {
        for (final StateListener listener : listeners) {
            // iterator the snapshot
            listener.onLeaderStop(oldTerm);
        }
    });
}
Also used : StateListener(com.alipay.sofa.jraft.rhea.StateListener)

Example 2 with StateListener

use of com.alipay.sofa.jraft.rhea.StateListener in project sofa-jraft by sofastack.

the class KVStoreStateMachine method onLeaderStart.

@Override
public void onLeaderStart(final long term) {
    super.onLeaderStart(term);
    this.leaderTerm.set(term);
    // Because of the raft state machine must be a sequential commit, in order to prevent the user
    // doing something (needs to go through the raft state machine) in the listeners, we need
    // asynchronously triggers the listeners.
    final List<StateListener> listeners = // 
    this.storeEngine.getStateListenerContainer().getStateListenerGroup(getRegionId());
    if (listeners.isEmpty()) {
        return;
    }
    this.storeEngine.getRaftStateTrigger().execute(() -> {
        for (final StateListener listener : listeners) {
            // iterator the snapshot
            listener.onLeaderStart(term);
        }
    });
}
Also used : StateListener(com.alipay.sofa.jraft.rhea.StateListener)

Example 3 with StateListener

use of com.alipay.sofa.jraft.rhea.StateListener in project sofa-jraft by sofastack.

the class KVStoreStateMachine method onStopFollowing.

@Override
public void onStopFollowing(final LeaderChangeContext ctx) {
    super.onStopFollowing(ctx);
    // Because of the raft state machine must be a sequential commit, in order to prevent the user
    // doing something (needs to go through the raft state machine) in the listeners, we need
    // asynchronously triggers the listeners.
    final List<StateListener> listeners = // 
    this.storeEngine.getStateListenerContainer().getStateListenerGroup(getRegionId());
    if (listeners.isEmpty()) {
        return;
    }
    this.storeEngine.getRaftStateTrigger().execute(() -> {
        for (final StateListener listener : listeners) {
            // iterator the snapshot
            listener.onStopFollowing(ctx.getLeaderId(), ctx.getTerm());
        }
    });
}
Also used : StateListener(com.alipay.sofa.jraft.rhea.StateListener)

Example 4 with StateListener

use of com.alipay.sofa.jraft.rhea.StateListener in project sofa-jraft by sofastack.

the class KVStoreStateMachine method onStartFollowing.

@Override
public void onStartFollowing(final LeaderChangeContext ctx) {
    super.onStartFollowing(ctx);
    // Because of the raft state machine must be a sequential commit, in order to prevent the user
    // doing something (needs to go through the raft state machine) in the listeners, we need
    // asynchronously triggers the listeners.
    final List<StateListener> listeners = // 
    this.storeEngine.getStateListenerContainer().getStateListenerGroup(getRegionId());
    if (listeners.isEmpty()) {
        return;
    }
    this.storeEngine.getRaftStateTrigger().execute(() -> {
        for (final StateListener listener : listeners) {
            // iterator the snapshot
            listener.onStartFollowing(ctx.getLeaderId(), ctx.getTerm());
        }
    });
}
Also used : StateListener(com.alipay.sofa.jraft.rhea.StateListener)

Aggregations

StateListener (com.alipay.sofa.jraft.rhea.StateListener)4