naming.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. *
  3. * Copyright 2014 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * 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 naming defines the naming API and related data structures for gRPC.
  19. // The interface is EXPERIMENTAL and may be suject to change.
  20. package naming
  21. // Operation defines the corresponding operations for a name resolution change.
  22. type Operation uint8
  23. const (
  24. // Add indicates a new address is added.
  25. Add Operation = iota
  26. // Delete indicates an exisiting address is deleted.
  27. Delete
  28. )
  29. // Update defines a name resolution update. Notice that it is not valid having both
  30. // empty string Addr and nil Metadata in an Update.
  31. type Update struct {
  32. // Op indicates the operation of the update.
  33. Op Operation
  34. // Addr is the updated address. It is empty string if there is no address update.
  35. Addr string
  36. // Metadata is the updated metadata. It is nil if there is no metadata update.
  37. // Metadata is not required for a custom naming implementation.
  38. Metadata interface{}
  39. }
  40. // Resolver creates a Watcher for a target to track its resolution changes.
  41. type Resolver interface {
  42. // Resolve creates a Watcher for target.
  43. Resolve(target string) (Watcher, error)
  44. }
  45. // Watcher watches for the updates on the specified target.
  46. type Watcher interface {
  47. // Next blocks until an update or error happens. It may return one or more
  48. // updates. The first call should get the full set of the results. It should
  49. // return an error if and only if Watcher cannot recover.
  50. Next() ([]*Update, error)
  51. // Close closes the Watcher.
  52. Close()
  53. }