org.apache.cassandra.distributed.api.IInvokableInstance Maven / Gradle / Ivy
/*
* 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.cassandra.distributed.api;
import java.io.Serializable;
import java.util.concurrent.Future;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
/**
* This version is only supported for a Cluster running the same code as the test environment, and permits
* ergonomic cross-node behaviours, without editing the cross-version API.
*
* A lambda can be written tto be invoked on any or all of the nodes.
*
* The reason this cannot (easily) be made cross-version is that the lambda is tied to the declaring class, which will
* not be the same in the alternate version. Even were it not, there would likely be a runtime linkage error given
* any code divergence.
*/
public interface IInvokableInstance extends IInstance
{
default CallableNoExcept> asyncCallsOnInstance(SerializableCallable call) { return async(transfer(call)); }
default CallableNoExcept callsOnInstance(SerializableCallable call) { return sync(transfer(call)); }
default O callOnInstance(SerializableCallable call) { return callsOnInstance(call).call(); }
default CallableNoExcept> asyncRunsOnInstance(SerializableRunnable run) { return async(transfer(run)); }
default Runnable runsOnInstance(SerializableRunnable run) { return sync(transfer(run)); }
default void runOnInstance(SerializableRunnable run) { runsOnInstance(run).run(); }
default Function> asyncAcceptsOnInstance(SerializableConsumer consumer) { return async(transfer(consumer)); }
default Consumer acceptsOnInstance(SerializableConsumer consumer) { return sync(transfer(consumer)); }
default void acceptOnInstance(SerializableConsumer consumer, I1 i1) { acceptsOnInstance(consumer).accept(i1); }
default BiFunction> asyncAcceptsOnInstance(SerializableBiConsumer consumer) { return async(transfer(consumer)); }
default BiConsumer acceptsOnInstance(SerializableBiConsumer consumer) { return sync(transfer(consumer)); }
default void acceptOnInstance(SerializableBiConsumer consumer, I1 i1, I2 i2) { acceptsOnInstance(consumer).accept(i1, i2); }
default TriFunction> asyncAcceptsOnInstance(SerializableTriConsumer consumer) { return async(transfer(consumer)); }
default TriConsumer acceptsOnInstance(SerializableTriConsumer consumer) { return sync(transfer(consumer)); }
default void acceptOnInstance(SerializableTriConsumer consumer, I1 i1, I2 i2, I3 i3) { acceptsOnInstance(consumer).accept(i1, i2, i3); }
default Function> asyncAppliesOnInstance(SerializableFunction f) { return async(transfer(f)); }
default Function appliesOnInstance(SerializableFunction f) { return sync(transfer(f)); }
default O applyOnInstance(SerializableFunction f, I1 i1) { return sync(transfer(f)).apply(i1); }
default BiFunction> asyncAppliesOnInstance(SerializableBiFunction f) { return async(transfer(f)); }
default BiFunction appliesOnInstance(SerializableBiFunction f) { return sync(transfer(f)); }
default O applyOnInstance(SerializableBiFunction f, I1 i1, I2 i2) { return sync(transfer(f)).apply(i1, i2); }
default TriFunction> asyncAppliesOnInstance(SerializableTriFunction f) { return async(transfer(f)); }
default TriFunction appliesOnInstance(SerializableTriFunction f) { return sync(transfer(f)); }
default O applyOnInstance(SerializableTriFunction f, I1 i1, I2 i2, I3 i3) { return sync(transfer(f)).apply(i1, i2, i3); }
default QuadFunction> asyncAppliesOnInstance(SerializableQuadFunction f) { return async(transfer(f)); }
default QuadFunction appliesOnInstance(SerializableQuadFunction f) { return sync(transfer(f)); }
default O applyOnInstance(SerializableQuadFunction f, I1 i1, I2 i2, I3 i3, I4 i4) { return sync(transfer(f)).apply(i1, i2, i3, i4); }
default QuintFunction> asyncAppliesOnInstance(SerializableQuintFunction f) { return async(transfer(f)); }
default QuintFunction appliesOnInstance(SerializableQuintFunction f) { return sync(transfer(f)); }
default O applyOnInstance(SerializableQuintFunction f, I1 i1, I2 i2, I3 i3, I4 i4, I5 i5) { return sync(transfer(f)).apply(i1, i2, i3, i4, i5); }
/**
* {@link #runOnInstance(SerializableRunnable)} on the invoking thread
*/
default void unsafeRunOnThisThread(IIsolatedExecutor.SerializableRunnable invoke)
{
transfer(invoke).run();
}
/**
* {@link #callOnInstance(SerializableCallable)} on the invoking thread
*/
default O unsafeCallOnThisThread(IIsolatedExecutor.SerializableCallable invoke)
{
return transfer(invoke).call();
}
/**
* {@link #acceptOnInstance(SerializableConsumer, Object)} on the invoking thread
*/
default void unsafeAcceptOnThisThread(IIsolatedExecutor.SerializableConsumer apply, I i1)
{
transfer(apply).accept(i1);
}
/**
* {@link #acceptOnInstance(SerializableBiConsumer, Object, Object)} on the invoking thread
*/
default void unsafeAcceptOnThisThread(IIsolatedExecutor.SerializableBiConsumer apply, I1 i1, I2 i2)
{
transfer(apply).accept(i1, i2);
}
/**
* {@link #acceptOnInstance(SerializableBiConsumer, Object, Object)} on the invoking thread
*/
default void unsafeAcceptOnThisThread(IIsolatedExecutor.SerializableTriConsumer apply, I1 i1, I2 i2, I3 i3)
{
transfer(apply).accept(i1, i2, i3);
}
/**
* {@link #applyOnInstance(SerializableFunction, Object)} on the invoking thread
*/
default O unsafeApplyOnThisThread(IIsolatedExecutor.SerializableFunction apply, I i1)
{
return transfer(apply).apply(i1);
}
/**
* {@link #applyOnInstance(SerializableBiFunction, Object, Object)} on the invoking thread
*/
default O unsafeApplyOnThisThread(IIsolatedExecutor.SerializableBiFunction apply, I1 i1, I2 i2)
{
return transfer(apply).apply(i1, i2);
}
/**
* {@link #applyOnInstance(SerializableTriFunction, Object, Object, Object)} on the invoking thread
*/
default O unsafeApplyOnThisThread(IIsolatedExecutor.SerializableTriFunction apply, I1 i1, I2 i2, I3 i3)
{
return transfer(apply).apply(i1, i2, i3);
}
/**
* {@link #applyOnInstance(SerializableTriFunction, Object, Object, Object)} on the invoking thread
*/
default O unsafeApplyOnThisThread(IIsolatedExecutor.SerializableQuadFunction apply, I1 i1, I2 i2, I3 i3, I4 i4)
{
return transfer(apply).apply(i1, i2, i3, i4);
}
/**
* {@link #applyOnInstance(SerializableTriFunction, Object, Object, Object)} on the invoking thread
*/
default O unsafeApplyOnThisThread(IIsolatedExecutor.SerializableQuintFunction apply, I1 i1, I2 i2, I3 i3, I4 i4, I5 i5)
{
return transfer(apply).apply(i1, i2, i3, i4, i5);
}
E transfer(E object);
}