Search in sources :

Example 1 with PerHostClientFactory

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() + '}';
        }
    };
}
Also used : ServiceConfiguration(com.palantir.conjure.java.api.config.service.ServiceConfiguration) PartialServiceConfiguration(com.palantir.conjure.java.api.config.service.PartialServiceConfiguration) DialogueChannel(com.palantir.dialogue.core.DialogueChannel) PerHostClientFactory(com.palantir.dialogue.clients.DialogueClients.PerHostClientFactory) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Endpoint(com.palantir.dialogue.Endpoint)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 PartialServiceConfiguration (com.palantir.conjure.java.api.config.service.PartialServiceConfiguration)1 ServiceConfiguration (com.palantir.conjure.java.api.config.service.ServiceConfiguration)1 Endpoint (com.palantir.dialogue.Endpoint)1 PerHostClientFactory (com.palantir.dialogue.clients.DialogueClients.PerHostClientFactory)1 DialogueChannel (com.palantir.dialogue.core.DialogueChannel)1 List (java.util.List)1