announcer

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package announcer encapsulates the idea of a server that dynamically advertises its presence to clients through various media.

Typical usage:

// On startup:
var a announcer.Announcer
impl, err := announcer.NewFoo(...)
// check err
a.Add(impl)

// When ready to serve:
err = a.Announce(ctx, &membership.Roxy{
	Ready:       true,
	IP:          ipAddr,
	ServerName:  "myserver.example.com", // name on your TLS certificate
	PrimaryPort: mainPort,
	AdditionalPorts: map[string]uint16{
		"foo": fooPort,
		"bar": barPort,
	},
})
// check err

// When about to stop serving:
err = a.Withdraw(ctx)
// check err

// On exit:
err = a.Close()
// check err

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Announcer

type Announcer struct {
	// contains filtered or unexported fields
}

Announcer is a multiplexer implementation of Interface that distributes method calls to multiple announcers.

func (*Announcer) Add

func (a *Announcer) Add(impl Interface)

Add adds a child announcer. Both Announcer and the child announcer must be in the ready state, or Add will panic.

func (*Announcer) Announce

func (a *Announcer) Announce(ctx context.Context, r *membership.Roxy) error

Announce broadcasts to all child announcers that the service is available at the given address.

Announcer must be in the ready state, or Announce will panic. A successful call to this method changes Announcer's state from the ready state to the running state.

func (*Announcer) Close

func (a *Announcer) Close() error

Close broadcasts to all child announcers that no further announcements are coming and that they should clean up any resources.

If Announcer is already in the closed state, nothing is done and fs.ErrClosed is returned. If Announcer is in neither the ready state nor the closed state, Close will panic. Any call to this method changes Announcer's state to the closed state.

func (*Announcer) State added in v0.4.3

func (a *Announcer) State() State

State returns the current state of the Announcer.

func (*Announcer) Withdraw

func (a *Announcer) Withdraw(ctx context.Context) error

Withdraw broadcasts to all child announcers that the service is no longer available.

Announcer must be in the running state, or Withdraw will panic. Any call to this method changes Announcer's state from the running state to the ready state.

type Format

type Format uint8
const (
	RoxyFormat Format = iota
	FinagleFormat
	GRPCFormat
)

func (Format) GoString added in v0.4.3

func (format Format) GoString() string

GoString fulfills fmt.GoStringer.

func (Format) MarshalJSON

func (format Format) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*Format) Parse

func (format *Format) Parse(str string) error

Parse parses from a string value.

func (Format) String

func (format Format) String() string

String fulfills fmt.Stringer.

func (*Format) UnmarshalJSON

func (format *Format) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type Interface added in v0.4.3

type Interface interface {
	Announce(ctx context.Context, r *membership.Roxy) error
	Withdraw(ctx context.Context) error
	Close() error
}

Interface is the interface provided by announcers for specific protocols.

func NewATC

func NewATC(client *atcclient.ATCClient, serviceName, location, unique, namedPort string, loadFn atcclient.LoadFunc) (Interface, error)

func NewEtcd

func NewEtcd(etcd *v3.Client, path, unique, namedPort string, format Format) (Interface, error)

func NewZK

func NewZK(zkconn *zk.Conn, path, unique, namedPort string, format Format) (Interface, error)

type State added in v0.4.3

type State uint8

State is used to keep track of which Announcer methods have been called.

const (
	StateReady State = iota
	StateRunning
	StateDead
	StateClosed
)

func (State) GoString added in v0.4.3

func (state State) GoString() string

GoString fulfills fmt.GoStringer.

func (State) IsReady added in v0.4.3

func (state State) IsReady() bool

IsReady returns true if it is safe to call Announce.

func (State) IsRunning added in v0.4.3

func (state State) IsRunning() bool

IsRunning returns true if Withdraw needs to be called.

func (State) String added in v0.4.3

func (state State) String() string

String fulfills fmt.Stringer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL