class SequenceService {

    public void checkRequest(final WilmaHttpRequest request, final SequenceDescriptor sequenceDescriptor) {
        if (sequenceEvaluator.evaluate(request, sequenceDescriptor)) {
            SequenceHandler handler = sequenceDescriptor.getHandler();
            String sequenceKey = handler.getExistingSequence(request, sequenceDescriptor.getSequences(), sequenceDescriptor.getParameters());
            if (sequenceKey == null) {
                sequenceKey = handler.generateNewSequenceKey(request, sequenceDescriptor.getParameters());
                handlerKeyValidator.validateGeneratedKey(sequenceKey, handler.getClass().getName());
                WilmaSequence sequence = sequenceFactory.createNewSequence(sequenceKey, request, sequenceDescriptor.getDefaultTimeout());
                sequenceDescriptor.putIntoSequences(sequence);
            } else {
                appendSequence(sequenceKey, request, sequenceDescriptor);
            }
            String sequenceId = sequenceIdUtil.createSequenceId(sequenceKey, sequenceDescriptor);
            appendSequenceKeyToHeader(sequenceId, request);
        }
    }

}