- this.executorService = executorService;
- this.consumer = consumer;
- this.producer = producer;
- this.topic = topic;
- this.zoneId = zoneId;
- // this.offsets = new long[numShards];
- // for (int i=0; i< numShards; i++)
- // {
- // this.offsets[i] = 0l;
- // }
- this.isShardOwned = new boolean[numShards];
- this.chatRoomMaps = new Map[numShards];
- }
-
-
- @Override
- public void onPartitionsAssigned(Collection<TopicPartition> partitions)
- {
- try
- {
- lock.writeLock().lock();
-
- consumer.endOffsets(partitions).forEach((topicPartition, currentOffset) ->
- {
- if (!topicPartition.topic().equals(topic))
- {
- log.warn("Ignoring partition from unwanted topic: {}", topicPartition);
- return;
- }
-
- int partition = topicPartition.partition();
- long unseenOffset = 0; // offsets[partition];
-
- log.info(
- "Loading messages from partition {}: start-offset={} -> current-offset={}",
- partition,
- unseenOffset,
- currentOffset);
-
- // TODO: reuse! Nicht immer alles neu laden, sondern erst ab offsets[partition]!
- consumer.seek(topicPartition, unseenOffset);
- });
-
- consumer.resume(partitions);
- }
- finally
- {
- lock.writeLock().unlock();
- }
- }
-
- @Override
- public void onPartitionsRevoked(Collection<TopicPartition> partitions)
- {
- partitions.forEach(topicPartition ->
- {
- if (!topicPartition.topic().equals(topic))
- {
- log.warn("Ignoring partition from unwanted topic: {}", topicPartition);
- return;
- }
-
- int partition = topicPartition.partition();
- // long unseenOffset = offsets[partition]; TODO: Offset merken...?
- });
- log.info("Revoked partitions: {}", partitions);