All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.activej.rpc.client.sender.strategy.RpcStrategies Maven / Gradle / Ivy

Go to download

High-performance and fault-tolerant Remote Procedure Call module for building distributed applications. Provides a high-performance asynchronous binary RPC streaming protocol.

There is a newer version: 6.0-rc2
Show newest version
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 servers(InetSocketAddress... addresses) {
		return servers(List.of(addresses));
	}

	public static List 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 strategies) {
		return new FirstAvailable(strategies);
	}

	public static RpcStrategy firstValidResult(RpcStrategy... strategies) {
		return firstValidResult(List.of(strategies));
	}

	public static RpcStrategy firstValidResult(List strategies) {
		return FirstValidResult.create(strategies);
	}

	public static RpcStrategy roundRobin(RpcStrategy... strategies) {
		return roundRobin(List.of(strategies));
	}

	public static RpcStrategy roundRobin(List 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 strategies) {
		return Sharding.create(shardingFunction, strategies);
	}

	public static RpcStrategy forced(RpcStrategy strategy) {
		return new Forced(strategy);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy