belliottsmith commented on code in PR #175: URL: https://github.com/apache/cassandra-accord/pull/175#discussion_r1978165070
########## accord-core/src/main/java/accord/coordinate/SynchronousAwait.java: ########## @@ -0,0 +1,97 @@ +/* + * 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 accord.coordinate; + +import java.util.function.BiConsumer; + +import javax.annotation.Nullable; + +import accord.api.ProgressLog.BlockedUntil; +import accord.coordinate.tracking.QuorumTracker; +import accord.coordinate.tracking.RequestStatus; +import accord.coordinate.tracking.SimpleTracker; +import accord.local.Node; +import accord.local.Node.Id; +import accord.messages.Await; +import accord.messages.Callback; +import accord.primitives.Participants; +import accord.primitives.TxnId; +import accord.topology.Topologies; +import accord.utils.Invariants; +import accord.utils.async.AsyncChain; +import accord.utils.async.AsyncChains; +import accord.utils.async.Cancellable; + +/** + * Synchronously await some set of replicas reaching a given wait condition. + * This may or may not be a condition we expect to reach promptly, but we will wait only until the timeout passes + * at which point we will report failure. + */ +public class SynchronousAwait implements Callback<Await.AwaitOk> +{ + final SimpleTracker<?> tracker; + BiConsumer<? super Boolean, Throwable> callback; + Throwable failure; + + public SynchronousAwait(SimpleTracker<?> tracker, BiConsumer<? super Boolean, Throwable> callback) + { + this.callback = callback; + this.tracker = tracker; + } + + public static AsyncChain<Boolean> awaitQuorum(Node node, Topologies topologies, TxnId txnId, BlockedUntil blockedUntil, boolean notifyProgressLog, Participants<?> participants) + { + // TODO (expected): copy this pattern elsewhere; should also make it easier to share exception handling logic etc + return new AsyncChains.Head<>() + { + protected @Nullable @Override Cancellable start(BiConsumer<? super Boolean, Throwable> callback) + { + SynchronousAwait await = new SynchronousAwait(new QuorumTracker(topologies), callback); + node.send(topologies.nodes(), to -> new Await(to, topologies, txnId, participants, blockedUntil, notifyProgressLog), await); + return null; Review Comment: Oh right yes, we aren't Cancellable. So yes, this is all correct. We pass through the callback and leave Await to invoke it. -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org