Search in sources :

Example 21 with InvalidCursorException

use of org.zalando.nakadi.exceptions.InvalidCursorException in project nakadi by zalando.

the class VersionOneConverter method convert.

public NakadiCursor convert(final String eventTypeStr, final Cursor cursor) throws InternalNakadiException, NoSuchEventTypeException, InvalidCursorException {
    final String[] parts = cursor.getOffset().split("-", 3);
    if (parts.length != 3) {
        throw new InvalidCursorException(CursorError.INVALID_OFFSET);
    }
    final String versionStr = parts[0];
    if (versionStr.length() != CursorConverter.VERSION_LENGTH) {
        throw new InvalidCursorException(CursorError.INVALID_OFFSET);
    }
    final String orderStr = parts[1];
    if (orderStr.length() != TIMELINE_ORDER_LENGTH) {
        throw new InvalidCursorException(CursorError.INVALID_OFFSET);
    }
    final String offsetStr = parts[2];
    if (offsetStr.isEmpty() || !NUMBERS_ONLY_PATTERN.matcher(offsetStr).matches()) {
        throw new InvalidCursorException(CursorError.INVALID_OFFSET);
    }
    final int order;
    try {
        order = Integer.parseInt(orderStr, TIMELINE_ORDER_BASE);
    } catch (final NumberFormatException ex) {
        throw new InvalidCursorException(CursorError.INVALID_OFFSET);
    }
    return findCorrectTimelinedCursor(eventTypeStr, order, cursor.getPartition(), offsetStr);
}
Also used : InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException)

Aggregations

InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)21 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)15 Timeline (org.zalando.nakadi.domain.Timeline)9 Map (java.util.Map)8 NakadiException (org.zalando.nakadi.exceptions.NakadiException)8 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)8 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)7 Optional (java.util.Optional)6 EventTypePartition (org.zalando.nakadi.domain.EventTypePartition)6 PartitionStatistics (org.zalando.nakadi.domain.PartitionStatistics)6 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 LoggerFactory (org.slf4j.LoggerFactory)5 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)5 IOException (java.io.IOException)4 CursorError (org.zalando.nakadi.domain.CursorError)4