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-2023 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.view;
import com.google.common.annotations.VisibleForTesting;
import cz.o2.proxima.direct.commitlog.CommitLogObserver;
import cz.o2.proxima.direct.commitlog.CommitLogReader;
import cz.o2.proxima.direct.commitlog.ObserveHandle;
import cz.o2.proxima.direct.commitlog.Offset;
import cz.o2.proxima.direct.core.CommitCallback;
import cz.o2.proxima.direct.core.OnlineAttributeWriter;
import cz.o2.proxima.direct.randomaccess.KeyValue;
import cz.o2.proxima.direct.randomaccess.RandomOffset;
import cz.o2.proxima.direct.randomaccess.RawOffset;
import cz.o2.proxima.direct.view.TimeBoundedVersionedCache.Payload;
import cz.o2.proxima.functional.BiConsumer;
import cz.o2.proxima.functional.Consumer;
import cz.o2.proxima.repository.AttributeDescriptor;
import cz.o2.proxima.repository.EntityDescriptor;
import cz.o2.proxima.storage.Partition;
import cz.o2.proxima.storage.StreamElement;
import cz.o2.proxima.storage.commitlog.Position;
import cz.o2.proxima.util.ExceptionUtils;
import cz.o2.proxima.util.Pair;
import java.net.URI;
import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
/** A transformation view from {@link CommitLogReader} to {@link CachedView}. */
@Slf4j
public class LocalCachedPartitionedView implements CachedView {
@Value
@VisibleForTesting
static class IntOffset implements RandomOffset {
int offset;
}
private final CommitLogReader reader;
private final EntityDescriptor entity;
/** Writer to persist data to. */
private final OnlineAttributeWriter writer;
/** Cache for data in memory. */
private final TimeBoundedVersionedCache cache;
/** Handle of the observation thread (if any running). */
private final AtomicReference handle = new AtomicReference<>();
private BiConsumer> updateCallback = (e, old) -> {};
public LocalCachedPartitionedView(
EntityDescriptor entity, CommitLogReader reader, OnlineAttributeWriter writer) {
this(entity, reader, writer, 60_000L);
}
public LocalCachedPartitionedView(
EntityDescriptor entity,
CommitLogReader reader,
OnlineAttributeWriter writer,
long keepCachedDuration) {
this.cache = new TimeBoundedVersionedCache(entity, keepCachedDuration);
this.reader = Objects.requireNonNull(reader);
this.entity = Objects.requireNonNull(entity);
this.writer = Objects.requireNonNull(writer);
}
protected void onCache(StreamElement ingest, boolean overwrite) {
final Optional