Search in sources :

Example 1 with GetSequenceResponse

use of com.alipay.sofa.jraft.rhea.cmd.store.GetSequenceResponse in project sofa-jraft by sofastack.

the class DefaultRegionKVService method handleGetSequence.

@Override
public void handleGetSequence(final GetSequenceRequest request, final RequestProcessClosure<BaseRequest, BaseResponse<?>> closure) {
    final GetSequenceResponse response = new GetSequenceResponse();
    response.setRegionId(getRegionId());
    response.setRegionEpoch(getRegionEpoch());
    try {
        KVParameterRequires.requireSameEpoch(request, getRegionEpoch());
        final byte[] seqKey = KVParameterRequires.requireNonNull(request.getSeqKey(), "sequence.seqKey");
        final int step = KVParameterRequires.requireNonNegative(request.getStep(), "sequence.step");
        this.rawKVStore.getSequence(seqKey, step, new BaseKVStoreClosure() {

            @Override
            public void run(final Status status) {
                if (status.isOk()) {
                    response.setValue((Sequence) getData());
                } else {
                    setFailure(request, response, status, getError());
                }
                closure.sendResponse(response);
            }
        });
    } catch (final Throwable t) {
        LOG.error("Failed to handle: {}, {}.", request, StackTraceUtil.stackTrace(t));
        response.setError(Errors.forException(t));
        closure.sendResponse(response);
    }
}
Also used : Status(com.alipay.sofa.jraft.Status) GetSequenceResponse(com.alipay.sofa.jraft.rhea.cmd.store.GetSequenceResponse) BaseKVStoreClosure(com.alipay.sofa.jraft.rhea.storage.BaseKVStoreClosure) Sequence(com.alipay.sofa.jraft.rhea.storage.Sequence)

Aggregations

Status (com.alipay.sofa.jraft.Status)1 GetSequenceResponse (com.alipay.sofa.jraft.rhea.cmd.store.GetSequenceResponse)1 BaseKVStoreClosure (com.alipay.sofa.jraft.rhea.storage.BaseKVStoreClosure)1 Sequence (com.alipay.sofa.jraft.rhea.storage.Sequence)1