hyperbahn

package
v1.34.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 12 Imported by: 66

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdRequest

type AdRequest struct {
	Services []service `json:"services"`
}

AdRequest is the Ad request sent to Hyperbahn.

type AdResponse

type AdResponse struct {
	ConnectionCount int `json:"connectionCount"`
}

AdResponse is the Ad response from Hyperbahn.

type Client

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

Client manages Hyperbahn connections and registrations.

func NewClient

func NewClient(ch *tchannel.Channel, config Configuration, opts *ClientOptions) (*Client, error)

NewClient creates a new Hyperbahn client using the given channel. config is the environment-specific configuration for Hyperbahn such as the list of initial nodes. opts are optional, and are used to customize the client.

func (*Client) Advertise

func (c *Client) Advertise(otherServices ...tchannel.Registrar) error

Advertise advertises the service with Hyperbahn, and returns any errors on initial advertisement. Advertise can register multiple services hosted on the same endpoint. If the advertisement succeeds, a goroutine is started to re-advertise periodically.

func (*Client) Close

func (c *Client) Close()

Close closes the Hyperbahn client, which stops any background re-advertisements.

func (*Client) Discover

func (c *Client) Discover(serviceName string) ([]string, error)

Discover queries Hyperbahn for a list of peers that are currently advertised with the specified service name.

func (*Client) IsClosed

func (c *Client) IsClosed() bool

IsClosed returns whether this Client is closed.

type ClientOptions

type ClientOptions struct {
	// Timeout defaults to 3 seconds if it is not set.
	Timeout time.Duration
	// TimeoutPerAttempt defaults to 1 second if it is not set.
	TimeoutPerAttempt time.Duration
	Handler           Handler
	FailStrategy      FailStrategy

	// The following are variables for stubbing in unit tests.
	// They are not part of the stable API and may change.
	TimeSleep func(d time.Duration)
}

ClientOptions are used to configure this Hyperbahn client.

type Configuration

type Configuration struct {
	// InitialNodes is the list of known Hyperbahn nodes to add initially.
	InitialNodes []string
	// InitialNodesFile is a JSON file that contains the list of known Hyperbahn nodes.
	// If this option is set, it overrides InitialNodes.
	InitialNodesFile string
}

Configuration is the initial configuration

type ErrAdvertiseFailed

type ErrAdvertiseFailed struct {
	// WillRetry is set to true if advertise will be retried.
	WillRetry bool
	// Cause is the underlying error returned from the advertise call.
	Cause error
}

ErrAdvertiseFailed is triggered when advertise fails.

func (ErrAdvertiseFailed) Error

func (e ErrAdvertiseFailed) Error() string

type Event

type Event int

Event describes different events that Client can trigger.

const (
	// UnknownEvent should never be used.
	UnknownEvent Event = iota
	// SendAdvertise is triggered when the Hyperbahn client tries to advertise.
	SendAdvertise
	// Advertised is triggered when the initial advertisement for a service is successful.
	Advertised
	// Readvertised is triggered on periodic advertisements.
	Readvertised
)

func (Event) String

func (i Event) String() string

type FailStrategy

type FailStrategy int

FailStrategy is the strategy to use when registration fails maxRegistrationFailures times consecutively in the background. This is not used if the initial registration fails.

const (
	// FailStrategyFatal will call Fatalf on the channel's logger after triggering handler.OnError.
	// This is the default strategy.
	FailStrategyFatal FailStrategy = iota
	// FailStrategyIgnore will only call handler.OnError, even after many
	// errors, and will continue to retry forever.
	FailStrategyIgnore
)

func (*FailStrategy) UnmarshalText added in v1.0.8

func (f *FailStrategy) UnmarshalText(text []byte) error

UnmarshalText implements encoding/text.Unmarshaler. This allows FailStrategy to be specified as a string in many file formats (e.g. JSON, YAML, TOML).

type Handler

type Handler interface {
	// On is called when events are triggered.
	On(event Event)
	// OnError is called when an error is detected.
	OnError(err error)
}

Handler is the interface for handling Hyperbahn events and errors.

Directories

Path Synopsis
gen-go
hyperbahn
Package hyperbahn is generated code used to make or handle TChannel calls using Thrift.
Package hyperbahn is generated code used to make or handle TChannel calls using Thrift.

Jump to

Keyboard shortcuts

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