drl

package module
v0.0.0-...-306e406 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MPL-2.0 Imports: 7 Imported by: 16

Documentation

Index

Constants

View Source
const (
	// Zero value - the cache is open and ready to use
	OPEN = 0

	// Closed value - the cache shouldn't be used
	CLOSED = 1
)

Constants for IsOpen indicators.

Go 1.17 adds atomic.Value.Swap which is great, but 1.19 adds atomic.Bool and other types. This is a go <1.13 cludge.

Variables

This section is empty.

Functions

func Round

func Round(val float64, roundOn float64, places int) (newVal float64)

Types

type Cache

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

Cache is a synchronized map of items that auto-expire once stale

func NewCache

func NewCache(duration time.Duration) *Cache

NewCache is a helper to create instance of the Cache struct

func (*Cache) Close

func (c *Cache) Close()

Close frees up resources used by the cache.

func (*Cache) Count

func (c *Cache) Count() int

Count returns the number of items in the cache (helpful for tracking memory leaks)

func (*Cache) Get

func (c *Cache) Get(key string) (data Server, found bool)

Get is a thread-safe way to lookup items Every lookup, also touches the item, hence extending it's life

func (*Cache) GetNoExtend

func (c *Cache) GetNoExtend(key string) (data Server, found bool)

GetNoExtend is a thread-safe way to lookup items Every lookup, also touches the item, hence extending it's life

func (*Cache) IsOpen

func (c *Cache) IsOpen() bool

IsOpen returns true if cache is open. If true this means the cache is operational, since the cache uses a background goroutine to manage ttl, this will be false when that background process has been terminated marking this cache unsuitable for use.

func (*Cache) Set

func (c *Cache) Set(key string, data Server)

Set is a thread-safe way to add new items to the map

type DRL

type DRL struct {
	Servers *Cache

	ThisServerID      string
	CurrentTotal      int64
	RequestTokenValue int
	// contains filtered or unexported fields
}

func (*DRL) AddOrUpdateServer

func (d *DRL) AddOrUpdateServer(s Server) error

func (*DRL) Close

func (d *DRL) Close()

func (*DRL) CurrentTokenValue

func (d *DRL) CurrentTokenValue() int64

func (*DRL) Init

func (d *DRL) Init(ctx context.Context)

func (*DRL) IsOpen

func (d *DRL) IsOpen() bool

func (*DRL) Ready

func (d *DRL) Ready() bool

func (*DRL) Report

func (d *DRL) Report() string

func (*DRL) SetCurrentTokenValue

func (d *DRL) SetCurrentTokenValue(newValue int64)

type Item

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

Item represents a record in the cache map

type Server

type Server struct {
	HostName   string
	ID         string
	LoadPerSec int64
	Percentage float64
	TagHash    string
}

Jump to

Keyboard shortcuts

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