Hi gRPC team,
Firstly, thanks for listen to me. I have a question that in my current 
project, I already have a daemon service to check Name server (DNS) and 
when have a changed, I want it call custom NameResolver to update gRPC 
client channel. I have a solution like it:

public class ExampleNameResolver extends NameResolver {
    private Listener2 listener;
    private final String serviceName;

    private final AtomicReference<List<InetSocketAddress>> currentAddresses 
= new AtomicReference<>(Collections.emptyList());

    public ExampleNameResolver(URI targetUri) {
        this.serviceName = targetUri.getPath().substring(1);
    }

    @Override
    public String getServiceAuthority() {
        return "example-authority";
    }

    @Override
    public void start(Listener2 listener) {
        this.listener = listener;
        if (!currentAddresses.get().isEmpty()) {
            updateResolution();
        }
    }

    @Override
    public void refresh() {

    }

    @Override
    public void shutdown() {

    }

    public void updateAddresses(List<InetSocketAddress> newAddresses) {
        currentAddresses.set(newAddresses);
        updateResolution();
    }

    private void updateResolution() {
        if (listener == null) {
            return;
        }
        List<EquivalentAddressGroup> groups = 
currentAddresses.get().stream()
            .map(EquivalentAddressGroup::new)
            .collect(Collectors.toList());

        ResolutionResult result = ResolutionResult.newBuilder()
            .setAddresses(groups)
            .build();

        listener.onResult(result);
    }
}

Do you think about this solution? Have any risk? Do you have any suggestion?
(I mean about the logical, NameResolver will be auto call to get newest 
Name server (proactive), but I want it only update when I want (passive)
Thank and best regards team.

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/grpc-io/44182b19-cea9-4dc4-aa68-0ced479d826fn%40googlegroups.com.

Reply via email to