class CloudDiscoveryServicePolarisImp implements CloudDiscoveryService , Closeable {
    private ProviderAPI providerAPI;
    private ConsumerAPI consumerAPI;

    public CloudDiscoveryServicePolarisImp(CloudProps cloudProps) {
        String server = cloudProps.getDiscoveryServer();
        String namespace = Solon.cfg().appNamespace();

        ConfigurationImpl cfgImpl = PolarisProps.getCfgImpl();

        //发现集群设置
        ClusterConfigImpl clusterConfig = cfgImpl.getGlobal().getSystem().getDiscoverCluster();
        clusterConfig.setNamespace(namespace);

        //发现连接设置(8091)
        ServerConnectorConfigImpl connectorConfig = cfgImpl.getGlobal().getServerConnector();
        List<String> address = connectorConfig.getAddresses();
        address.add(server);
        connectorConfig.setAddresses(address);

        providerAPI = DiscoveryAPIFactory.createProviderAPIByConfig(cfgImpl);
        consumerAPI = DiscoveryAPIFactory.createConsumerAPIByConfig(cfgImpl);
    }

    /**
     * 注册服务实例
     *
     * @param group    分组
     * @param instance 服务实例
     */
    @Override
    public void register(String group, Instance instance) {
        registerState(group, instance, true);
    }

    /**
     * 注册服务实例健康状态
     *
     * @param group    分组
     * @param instance 服务实例
     */
    @Override
    public void registerState(String group, Instance instance, boolean health) {
        String[] ss = instance.address().split(":");

        if (ss.length != 2) {
            throw new IllegalArgumentException("Instance.address error");
        }

        InstanceRegisterRequest request = new InstanceRegisterRequest();
        request.setNamespace(Solon.cfg().appNamespace());
        request.setWeight((int) instance.weight());
        request.setMetadata(instance.meta());
        request.setService(instance.service());
        request.setHost(ss[0]);
        request.setPort(Integer.parseInt(ss[1]));
        request.setProtocol(instance.protocol());

        providerAPI.registerInstance(request);
    }

    /**
     * 注销服务实例
     *
     * @param group    分组
     * @param instance 服务实例
     */
    @Override
    public void deregister(String group, Instance instance) {
        String[] ss = instance.address().split(":");

        if (ss.length != 2) {
            throw new IllegalArgumentException("Instance.address error");
        }
        InstanceDeregisterRequest deregisterRequest = new InstanceDeregisterRequest();

        deregisterRequest.setNamespace(Solon.cfg().appNamespace());
        deregisterRequest.setService(instance.service());
        deregisterRequest.setHost(ss[0]);
        deregisterRequest.setPort(Integer.parseInt(ss[1]));

        providerAPI.deRegister(deregisterRequest);
    }

    /**
     * @param group   分组
     * @param service 服各名
     * @return
     */
    @Override
    public Discovery find(String group, String service) {<FILL_FUNCTION_BODY>}

    /**
     * 关注服务实例列表
     *
     * @param group    分组
     * @param service  服各名
     * @param observer 观察者
     */
    @Override
    public void attention(String group, String service, CloudDiscoveryHandler observer) {
        if (Utils.isEmpty(group)) {
            group = Solon.cfg().appGroup();
        }

        CloudDiscoveryObserverEntity entity = new CloudDiscoveryObserverEntity(group, service, observer);

        WatchServiceRequest request = WatchServiceRequest.builder()
                .namespace(Solon.cfg().appNamespace())
                .service(service)
                .listeners(Collections.singletonList(event -> {
                    Discovery discovery = new Discovery(service);

                    for (com.tencent.polaris.api.pojo.Instance instance : event.getAllInstances()) {
                        if (instance.isHealthy()) {
                            discovery.instanceAdd(new Instance(service,
                                    instance.getHost() + ":" + instance.getPort())
                                    .weight(instance.getWeight())
                                    .protocol(instance.getProtocol())
                                    .metaPutAll(instance.getMetadata()));
                        }
                    }

                    entity.handle(discovery);
                }))
                .build();

        consumerAPI.watchService(request);
    }

    @Override
    public void close() throws IOException {
        if (consumerAPI != null) {
            consumerAPI.close();
        }

        if (providerAPI != null) {
            providerAPI.close();
        }
    }
}

        Discovery discovery = new Discovery(service);

        GetHealthyInstancesRequest request = new GetHealthyInstancesRequest();

        request.setNamespace(Solon.cfg().appNamespace());
        request.setService(service);

        InstancesResponse instancesResponse = consumerAPI.getHealthyInstances(request);

        if (Objects.isNull(instancesResponse) || instancesResponse.getInstances().length > 0) {
            return discovery;
        }

        for (com.tencent.polaris.api.pojo.Instance instance : instancesResponse.getInstances()) {
            //只关注健康的
            if (instance.isHealthy()) {
                discovery.instanceAdd(new Instance(service,
                        instance.getHost() + ":" + instance.getPort())
                        .weight(instance.getWeight())
                        .protocol(instance.getProtocol())
                        .metaPutAll(instance.getMetadata()));
            }
        }

        return discovery;
    
<no_super_class>