dubbo.apache.org/dubbo-go/v3@v3.1.1/registry/service_discovery.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   * contributor license agreements.  See the NOTICE file distributed with
     4   * this work for additional information regarding copyright ownership.
     5   * The ASF licenses this file to You under the Apache License, Version 2.0
     6   * (the "License"); you may not use this file except in compliance with
     7   * the License.  You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package registry
    19  
    20  import (
    21  	"fmt"
    22  )
    23  
    24  import (
    25  	gxset "github.com/dubbogo/gost/container/set"
    26  	gxpage "github.com/dubbogo/gost/hash/page"
    27  )
    28  
    29  const DefaultPageSize = 100
    30  
    31  // ServiceDiscovery is the interface that wraps common operations of Service Discovery
    32  type ServiceDiscovery interface {
    33  	fmt.Stringer
    34  
    35  	// Destroy will destroy the service discovery.
    36  	// If the discovery cannot be destroy, it will return an error.
    37  	Destroy() error
    38  
    39  	// Register will register an instance of ServiceInstance to registry
    40  	Register(instance ServiceInstance) error
    41  
    42  	// Update will update the data of the instance in registry
    43  	Update(instance ServiceInstance) error
    44  
    45  	// Unregister will unregister this instance from registry
    46  	Unregister(instance ServiceInstance) error
    47  
    48  	// GetDefaultPageSize will return the default page size
    49  	GetDefaultPageSize() int
    50  
    51  	// GetServices will return the all service names.
    52  	GetServices() *gxset.HashSet
    53  
    54  	// GetInstances will return all service instances with serviceName
    55  	GetInstances(serviceName string) []ServiceInstance
    56  
    57  	// GetInstancesByPage will return a page containing instances of ServiceInstance
    58  	// with the serviceName the page will start at offset
    59  	GetInstancesByPage(serviceName string, offset int, pageSize int) gxpage.Pager
    60  
    61  	// GetHealthyInstancesByPage will return a page containing instances of ServiceInstance.
    62  	// The param healthy indices that the instance should be healthy or not.
    63  	// The page will start at offset
    64  	GetHealthyInstancesByPage(serviceName string, offset int, pageSize int, healthy bool) gxpage.Pager
    65  
    66  	// GetRequestInstances gets all instances by the specified service names
    67  	GetRequestInstances(serviceNames []string, offset int, requestedSize int) map[string]gxpage.Pager
    68  
    69  	// AddListener adds a new ServiceInstancesChangedListenerImpl
    70  	// see addServiceInstancesChangedListener in Java
    71  	AddListener(listener ServiceInstancesChangedListener) error
    72  }