vldpyatkov commented on a change in pull request #631: URL: https://github.com/apache/ignite-3/pull/631#discussion_r801558237
########## File path: modules/core/src/main/java/org/apache/ignite/internal/causality/VersionedValue.java ########## @@ -0,0 +1,220 @@ +/* + * Licensed to 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 org.apache.ignite.internal.causality; + +import java.util.Map.Entry; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentNavigableMap; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import org.apache.ignite.lang.IgniteStringFormatter; +import org.jetbrains.annotations.Nullable; + +/** + * Parametrized type to store several versions of the value. + * A value can be available through the causality token, which is represented by long. + * + * @param <T> Type of real value. + */ +public class VersionedValue<T> { + /** Last applied casualty token. */ + private volatile long actualToken; + + /** Size of stored history. */ + private final int historySize; + + /** Closure applied on storage revision update. */ + private final BiConsumer<VersionedValue<T>, Long> onStorageRevisionUpdate; + + /** Bersoned value storage. */ + private final ConcurrentNavigableMap<Long, CompletableFuture<T>> history = new ConcurrentSkipListMap<>(); + + /** + * Constructor. + * + * @param onStorageRevisionUpdate Closure applied on storage revision update (see {@link #onStorageRevisionUpdate(long)}. + * @param observableRevisionUpdater A closure intended to connect this VersionedValue with a revision updater, that this VersionedValue + * should be able to listen to, for receiving storage revision updates. This closure is called once on + * a construction of this VersionedValue and accepts a {@link Consumer<Long>} that should be called on + * every update of storage revision as a listener. + * @param historySize Size of the history of changes to store, including last applied token. + */ + public VersionedValue( + @Nullable BiConsumer<VersionedValue<T>, Long> onStorageRevisionUpdate, + Consumer<Consumer<Long>> observableRevisionUpdater, + int historySize + ) { + this.onStorageRevisionUpdate = onStorageRevisionUpdate == null ? (versionedValue, token) -> { Review comment: Ok, logic of future complete moved to dedicate method and is invoked into onStorageRevisionUpdate -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
