itopo

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package itopo stores topology state and manages topology updates for an application.

The package must be initialized with Init. In subsequent updates through Update, the new topology is checked whether it is compatible with the previous version. The rules differ between services.

Updates

The update of the topology is only valid if a set of constraints is met. The constraints differ between the initialized service types.

In a topology update, when the diff is empty, the topology is only updated if it expires later than the current topology. Otherwise, Update succeeds and indicates that the in-memory copy has not been updated.

The client package can register callbacks to be notified about certain events.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get added in v0.4.0

func Get() topology.Topology

Get atomically gets the pointer to the current topology.

func Init added in v0.4.0

func Init(cfg *Config)

Init initializes the itopo package. A topology must be initialized by calling Update.

func Provider added in v0.4.0

func Provider() topology.Provider

Provider returns a topology provider that calls Get internally.

func TopologyHandler added in v0.5.0

func TopologyHandler(w http.ResponseWriter, r *http.Request)

func Update added in v0.5.0

func Update(static topology.Topology) error

Update atomically sets the topology.

Types

type Callbacks added in v0.4.0

type Callbacks struct {
	// OnUpdate is called whenever the pointer to static topology is updated.
	OnUpdate func()
}

Callbacks are callbacks to respond to specific topology update events.

type Config added in v0.5.0

type Config struct {
	// ID is the application identifier.
	ID string
	// Svc is the service type of the application. Updated are treated differently depending
	// on it.
	Svc topology.ServiceType
	// Callbacks can be used to run custom code on specific events.
	Callbacks Callbacks
	// TopologyFactory is used to build Topology facades for the underlying topology object.
	// If nil, topology.FromRWTopology is used.
	TopologyFactory func(*topology.RWTopology) topology.Topology
}

Config is used to initialize the package.

type Transaction added in v0.4.0

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

Transaction allows to get a view on which topology will be active without committing to the topology update yet.

func BeginUpdate added in v0.5.0

func BeginUpdate(static *topology.RWTopology) (Transaction, error)

BeginUpdate checks whether setting the static topology is permissible. The returned transaction provides a view on which topology would be active, if committed.

func (*Transaction) Commit added in v0.4.0

func (tx *Transaction) Commit() error

Commit commits the change. An error is returned, if the static topology changed in the meantime.

func (*Transaction) Get added in v0.4.0

func (tx *Transaction) Get() topology.Topology

Get returns the topology that will be active if the transaction is committed.

func (*Transaction) IsUpdate added in v0.4.0

func (tx *Transaction) IsUpdate() bool

IsUpdate indicates whether the transaction will cause an update.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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