Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright 2017-2020 O2 Czech Republic, a.s.
*
* Licensed 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 cz.o2.proxima.direct.kafka;
import static cz.o2.proxima.direct.commitlog.ObserverUtils.asOnIdleContext;
import static cz.o2.proxima.direct.commitlog.ObserverUtils.asOnNextContext;
import static cz.o2.proxima.direct.commitlog.ObserverUtils.asRepartitionContext;
import com.google.common.base.MoreObjects;
import cz.o2.proxima.direct.commitlog.LogObserver;
import cz.o2.proxima.direct.commitlog.LogObserver.OnNextContext;
import cz.o2.proxima.functional.BiConsumer;
import cz.o2.proxima.functional.Factory;
import cz.o2.proxima.storage.StreamElement;
import cz.o2.proxima.time.WatermarkSupplier;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
import org.apache.kafka.common.TopicPartition;
/** Placeholder class for consumers. */
@Slf4j
class Consumers {
private abstract static class ConsumerBase implements ElementConsumer {
final Map committed = Collections.synchronizedMap(new HashMap<>());
final Map processing = Collections.synchronizedMap(new HashMap<>());
long watermark;
@Override
public void onCompleted() {
observer().onCompleted();
}
@Override
public void onCancelled() {
observer().onCancelled();
}
@Override
public boolean onError(Throwable err) {
return observer().onError(err);
}
@Override
public void onAssign(KafkaConsumer consumer, Collection offsets) {
committed.clear();
committed.putAll(
offsets
.stream()
.collect(Collectors.toMap(o -> o.getPartition().getId(), TopicOffset::getOffset)));
}
abstract LogObserver observer();
}
static final class OnlineConsumer extends ConsumerBase {
private final LogObserver observer;
private final OffsetCommitter committer;
private final Factory