Search in sources :

Example 6 with TaskIdFormatException

use of org.apache.kafka.streams.errors.TaskIdFormatException in project kafka by apache.

the class TaskId method parse.

/**
 * @throws TaskIdFormatException if the taskIdStr is not a valid {@link TaskId}
 */
public static TaskId parse(final String taskIdStr) {
    try {
        final int namedTopologyDelimiterIndex = taskIdStr.indexOf(NAMED_TOPOLOGY_DELIMITER);
        // If there is no copy of the NamedTopology delimiter, this task has no named topology and only one `_` char
        if (namedTopologyDelimiterIndex < 0) {
            final int index = taskIdStr.indexOf('_');
            final int topicGroupId = Integer.parseInt(taskIdStr.substring(0, index));
            final int partition = Integer.parseInt(taskIdStr.substring(index + 1));
            return new TaskId(topicGroupId, partition);
        } else {
            final int topicGroupIdIndex = namedTopologyDelimiterIndex + 2;
            final int subtopologyPartitionDelimiterIndex = taskIdStr.indexOf('_', topicGroupIdIndex);
            final String namedTopology = taskIdStr.substring(0, namedTopologyDelimiterIndex);
            final int topicGroupId = Integer.parseInt(taskIdStr.substring(topicGroupIdIndex, subtopologyPartitionDelimiterIndex));
            final int partition = Integer.parseInt(taskIdStr.substring(subtopologyPartitionDelimiterIndex + 1));
            return new TaskId(topicGroupId, partition, namedTopology);
        }
    } catch (final Exception e) {
        throw new TaskIdFormatException(taskIdStr);
    }
}
Also used : TaskIdFormatException(org.apache.kafka.streams.errors.TaskIdFormatException) IOException(java.io.IOException) TaskIdFormatException(org.apache.kafka.streams.errors.TaskIdFormatException)

Aggregations

TaskIdFormatException (org.apache.kafka.streams.errors.TaskIdFormatException)6 TaskId (org.apache.kafka.streams.processor.TaskId)4 File (java.io.File)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)2 LockException (org.apache.kafka.streams.errors.LockException)1 ProcessorStateException (org.apache.kafka.streams.errors.ProcessorStateException)1 StreamsException (org.apache.kafka.streams.errors.StreamsException)1 TaskDirectory (org.apache.kafka.streams.processor.internals.StateDirectory.TaskDirectory)1