/**
 * Copyright 2015 StreamSets Inc.
 *
 * Licensed under the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.streamsets.pipeline.kafka.impl;


import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

public class RoundRobinPartitioner implements Partitioner {

  private final AtomicInteger counter = new AtomicInteger((new Random()).nextInt());

  @Override
  public int partition(
      String topic,
      Object key,
      byte[] keyBytes,
      Object value,
      byte[] valueBytes,
      Cluster cluster
  ) {
    int availablePartitions = cluster.partitionCountForTopic(topic);
    int partition = counter.getAndIncrement();
    return partition % availablePartitions;
  }

  @Override
  public void close() {

  }

  @Override
  public void configure(Map<String, ?> map) {

  }
}
@@ -1221,16 +1221,33 @@
 nextInt(
+Integer.MAX_VALUE
 ));%0A%0A  @
@@ -1531,51 +1531,126 @@
 nt()
-;%0A    return partition %25 availableP
+ %25 availablePartitions;%0A    if (counter.get() == Integer.MAX_VALUE) %7B%0A      counter.set(0);%0A    %7D%0A    return p
 artition
 s;%0A 
@@ -1641,25 +1641,24 @@
 rn partition
-s
 ;%0A  %7D%0A%0A  @Ov

SDC-2529. RoundRobin partitioner for Kafka 09 and can return negative partition id