tdlib-session-container/src/main/java/it/tdlight/reactiveapi/ClusterSettings.java

40 lines
1.3 KiB
Java
Raw Normal View History

2021-12-05 15:15:28 +01:00
package it.tdlight.reactiveapi;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
2022-10-05 02:26:30 +02:00
import org.jetbrains.annotations.Nullable;
2021-12-05 15:15:28 +01:00
/**
* Define the cluster structure
*/
public class ClusterSettings {
public String id;
2022-01-13 01:59:26 +01:00
public List<String> kafkaBootstrapServers;
2022-10-05 02:26:30 +02:00
public String rsocketHost;
2022-09-22 15:46:31 +02:00
public List<String> lanes;
2021-12-05 15:15:28 +01:00
@JsonCreator
public ClusterSettings(@JsonProperty(required = true, value = "id") String id,
2022-10-05 02:26:30 +02:00
@JsonProperty(value = "kafkaBootstrapServers") List<String> kafkaBootstrapServers,
@JsonProperty(value = "rsocketHost") String rsocketHost,
2022-09-22 15:46:31 +02:00
@JsonProperty(required = true, value = "lanes") List<String> lanes) {
2021-12-05 15:15:28 +01:00
this.id = id;
2022-01-13 01:59:26 +01:00
this.kafkaBootstrapServers = kafkaBootstrapServers;
2022-10-05 02:26:30 +02:00
this.rsocketHost = rsocketHost;
2022-09-22 15:46:31 +02:00
this.lanes = lanes;
2022-10-05 02:26:30 +02:00
if ((rsocketHost == null) == (kafkaBootstrapServers == null || kafkaBootstrapServers.isEmpty())) {
throw new IllegalArgumentException("Please configure either RSocket or Kafka");
}
}
public ChannelsParameters toParameters(String clientId, InstanceType instanceType) {
if (rsocketHost != null) {
return new RSocketParameters(instanceType, rsocketHost, lanes);
} else {
return new KafkaParameters(clientId, clientId, kafkaBootstrapServers, List.copyOf(lanes));
}
2021-12-05 15:15:28 +01:00
}
}