use of com.palantir.dialogue.clients.DialogueClients.PerHostClientFactory in project dialogue by palantir.
the class ReloadingClientFactory method perHost.
@Override
public PerHostClientFactory perHost(String serviceName) {
Preconditions.checkNotNull(serviceName, "serviceName");
String channelName = ChannelNames.reloading(serviceName, params);
Refreshable<List<DialogueChannel>> perHostDialogueChannels = params.scb().map(block -> {
if (!block.services().containsKey(serviceName)) {
return ImmutableList.of();
}
ServiceConfiguration serviceConfiguration = ServiceConfigurationFactory.of(block).get(serviceName);
ImmutableList.Builder<DialogueChannel> list = ImmutableList.builder();
for (int i = 0; i < serviceConfiguration.uris().size(); i++) {
ServiceConfiguration singleUriServiceConf = ServiceConfiguration.builder().from(serviceConfiguration).uris(ImmutableList.of(serviceConfiguration.uris().get(i))).build();
// subtle gotcha here is that every single one of these has the same channelName,
// which means metrics like the QueuedChannel counter will end up being the sum of all of them.
list.add(cache.getNonReloadingChannel(params, singleUriServiceConf, channelName, OptionalInt.of(i)));
}
return list.build();
});
return new PerHostClientFactory() {
@Override
public Refreshable<List<Channel>> getPerHostChannels() {
return perHostDialogueChannels.map(ImmutableList::copyOf);
}
@Override
public <T> Refreshable<List<T>> getPerHost(Class<T> clientInterface) {
return getPerHostChannels().map(channels -> channels.stream().map(chan -> Reflection.callStaticFactoryMethod(clientInterface, chan, params.runtime())).collect(ImmutableList.toImmutableList()));
}
@Override
public String toString() {
return "PerHostClientFactory{serviceName=" + serviceName + ", channels=" + perHostDialogueChannels.get() + '}';
}
};
}
Aggregations