org.eclipse.ditto.connectivity.service.messaging.kafka.RestartableKafkaConsumerStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ditto-connectivity-service Show documentation
Show all versions of ditto-connectivity-service Show documentation
Eclipse Ditto is a framework for creating and managing digital twins in the IoT.
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.connectivity.service.messaging.kafka;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import org.eclipse.ditto.base.service.config.supervision.ExponentialBackOff;
import org.eclipse.ditto.base.service.config.supervision.ExponentialBackOffConfig;
import akka.Done;
/**
* Responsible to wrap a {@link KafkaConsumerStream} and restart it on demand.
*/
final class RestartableKafkaConsumerStream implements KafkaConsumerStream {
private final ExponentialBackOff backOff;
private final KafkaConsumerStream kafkaConsumerStream;
private final Supplier consumerStreamStarter;
RestartableKafkaConsumerStream(final Supplier consumerStreamStarter,
final ExponentialBackOffConfig backOffConfig) {
backOff = ExponentialBackOff.initial(backOffConfig);
this.consumerStreamStarter = consumerStreamStarter;
kafkaConsumerStream = consumerStreamStarter.get();
}
private RestartableKafkaConsumerStream(final Supplier consumerStreamStarter,
final ExponentialBackOff backOff) {
this.backOff = backOff;
this.consumerStreamStarter = consumerStreamStarter;
kafkaConsumerStream = consumerStreamStarter.get();
}
@Override
public CompletionStage