io.activej.rpc.client.sender.strategy.RpcStrategies Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of activej-rpc Show documentation
Show all versions of activej-rpc Show documentation
High-performance and fault-tolerant Remote Procedure Call module for building distributed applications.
Provides a high-performance asynchronous binary RPC streaming protocol.
package io.activej.rpc.client.sender.strategy;
import io.activej.common.annotation.StaticFactories;
import io.activej.rpc.client.sender.strategy.impl.*;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.function.ToIntFunction;
import static io.activej.common.Checks.checkArgument;
@StaticFactories(RpcStrategy.class)
public class RpcStrategies {
public static RpcStrategy server(InetSocketAddress address) {
return new Server(address);
}
public static List extends RpcStrategy> servers(InetSocketAddress... addresses) {
return servers(List.of(addresses));
}
public static List extends RpcStrategy> servers(List addresses) {
checkArgument(!addresses.isEmpty(), "At least one address must be present");
return addresses.stream()
.map(Server::new)
.toList();
}
public static RpcStrategy firstAvailable(RpcStrategy... strategies) {
return firstAvailable(List.of(strategies));
}
public static RpcStrategy firstAvailable(List extends RpcStrategy> strategies) {
return new FirstAvailable(strategies);
}
public static RpcStrategy firstValidResult(RpcStrategy... strategies) {
return firstValidResult(List.of(strategies));
}
public static RpcStrategy firstValidResult(List extends RpcStrategy> strategies) {
return FirstValidResult.create(strategies);
}
public static RpcStrategy roundRobin(RpcStrategy... strategies) {
return roundRobin(List.of(strategies));
}
public static RpcStrategy roundRobin(List extends RpcStrategy> strategies) {
return RoundRobin.create(strategies);
}
public static RpcStrategy sharding(ToIntFunction shardingFunction, RpcStrategy... strategies) {
return sharding(shardingFunction, List.of(strategies));
}
public static RpcStrategy sharding(ToIntFunction shardingFunction, List extends RpcStrategy> strategies) {
return Sharding.create(shardingFunction, strategies);
}
public static RpcStrategy forced(RpcStrategy strategy) {
return new Forced(strategy);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy