schedulerutils

package
v0.8.18 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: Apache-2.0, BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ElementIDLength = 32

ElementIDLength defines the length of an ElementID.

Variables

View Source
var ErrInsufficientMana = errors.New("insufficient node's mana to schedule the message")

ErrInsufficientMana is returned when the mana is insufficient.

Functions

This section is empty.

Types

type AccessManaCache

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

AccessManaCache is a structure which provides access to cached access mana values. Mana values are refreshed after certain amount of time has passed.

func NewAccessManaCache

func NewAccessManaCache(accessManaMapRetrieverFunc func() map[identity.ID]float64, minMana float64) *AccessManaCache

NewAccessManaCache returns a new AccessManaCache.

func (*AccessManaCache) GetCachedMana

func (a *AccessManaCache) GetCachedMana(id identity.ID) float64

GetCachedMana returns cached access mana value for a given node and refreshes mana vectors if they expired currently returns at least MinMana.

func (*AccessManaCache) RawAccessManaVector

func (a *AccessManaCache) RawAccessManaVector() map[identity.ID]float64

RawAccessManaVector returns raw access mana vector retrieved from mana plugin.

type BufferQueue

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

BufferQueue represents a buffer of NodeQueue.

func NewBufferQueue

func NewBufferQueue(maxBuffer int, maxQueue float64) *BufferQueue

NewBufferQueue returns a new BufferQueue.

func (*BufferQueue) Current

func (b *BufferQueue) Current() *NodeQueue

Current returns the current NodeQueue in round robin order.

func (*BufferQueue) IDs

func (b *BufferQueue) IDs() (ids []ElementID)

IDs returns the IDs of all submitted messages (ready or not).

func (*BufferQueue) InsertNode

func (b *BufferQueue) InsertNode(nodeID identity.ID)

InsertNode creates a queue for the given node and adds it to the list of active nodes.

func (*BufferQueue) MaxSize

func (b *BufferQueue) MaxSize() int

MaxSize returns the max size (in bytes) of all messages in b.

func (*BufferQueue) Next

func (b *BufferQueue) Next() *NodeQueue

Next returns the next NodeQueue in round robin order.

func (*BufferQueue) NodeIDs

func (b *BufferQueue) NodeIDs() []identity.ID

NodeIDs returns the nodeIDs of all nodes.

func (*BufferQueue) NodeQueue

func (b *BufferQueue) NodeQueue(nodeID identity.ID) *NodeQueue

NodeQueue returns the queue for the corresponding node.

func (*BufferQueue) NumActiveNodes

func (b *BufferQueue) NumActiveNodes() int

NumActiveNodes returns the number of active nodes in b.

func (*BufferQueue) PopFront

func (b *BufferQueue) PopFront() Element

PopFront removes the first ready message from the queue of the current node.

func (*BufferQueue) Ready

func (b *BufferQueue) Ready(msg Element) bool

Ready marks a previously submitted message as ready to be scheduled.

func (*BufferQueue) ReadyMessagesCount

func (b *BufferQueue) ReadyMessagesCount() (readyMsgCount int)

ReadyMessagesCount returns the number of ready messages in the buffer.

func (*BufferQueue) RemoveNode

func (b *BufferQueue) RemoveNode(nodeID identity.ID)

RemoveNode removes all messages (submitted and ready) for the given node.

func (*BufferQueue) Size

func (b *BufferQueue) Size() int

Size returns the total size (in bytes) of all messages in b.

func (*BufferQueue) Submit

func (b *BufferQueue) Submit(msg Element, accessManaRetriever func(identity.ID) float64) []ElementID

Submit submits a message. Return messages dropped from the scheduler to make room for the submitted message. The submitted message can also be returned as dropped if the issuing node does not have enough access mana.

func (*BufferQueue) TotalMessagesCount

func (b *BufferQueue) TotalMessagesCount() (msgCount int)

TotalMessagesCount returns the number of messages in the buffer.

func (*BufferQueue) Unsubmit

func (b *BufferQueue) Unsubmit(msg Element) bool

Unsubmit removes a message from the submitted messages. If that message is already marked as ready, Unsubmit has no effect.

type Element

type Element interface {
	// IDBytes returns the ID of an Element as a byte slice.
	IDBytes() []byte

	// Size returns the size of the element.
	Size() int

	// IssuerPublicKey returns the issuer public key of the element.
	IssuerPublicKey() ed25519.PublicKey

	// IssuingTime returns the issuing time of the message.
	IssuingTime() time.Time
}

Element represents the generic interface for an message in NodeQueue.

type ElementHeap

type ElementHeap []Element

ElementHeap holds a heap of messages with respect to their IssuingTime.

func (ElementHeap) Len

func (h ElementHeap) Len() int

Len is the number of elements in the collection.

func (ElementHeap) Less

func (h ElementHeap) Less(i, j int) bool

Less reports whether the element with index i must sort before the element with index j.

func (*ElementHeap) Pop

func (h *ElementHeap) Pop() interface{}

Pop removes and returns element with index Len() - 1.

func (*ElementHeap) Push

func (h *ElementHeap) Push(x interface{})

Push adds x as element with index Len(). It panics if x is not Element.

func (ElementHeap) Swap

func (h ElementHeap) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type ElementID

type ElementID [ElementIDLength]byte

ElementID defines the ID of element.

func ElementIDFromBytes

func ElementIDFromBytes(bytes []byte) (result ElementID)

ElementIDFromBytes converts byte array to an ElementID.

type NodeQueue

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

NodeQueue keeps the submitted messages of a node.

func NewNodeQueue

func NewNodeQueue(nodeID identity.ID) *NodeQueue

NewNodeQueue returns a new NodeQueue.

func (*NodeQueue) Front

func (q *NodeQueue) Front() Element

Front returns the first ready message in the queue.

func (*NodeQueue) IDs

func (q *NodeQueue) IDs() (ids []ElementID)

IDs returns the IDs of all submitted messages (ready or not).

func (*NodeQueue) NodeID

func (q *NodeQueue) NodeID() identity.ID

NodeID returns the ID of the node belonging to the queue.

func (*NodeQueue) PopFront

func (q *NodeQueue) PopFront() Element

PopFront removes the first ready message from the queue.

func (*NodeQueue) Ready

func (q *NodeQueue) Ready(element Element) bool

Ready marks a previously submitted message as ready to be scheduled.

func (*NodeQueue) Size

func (q *NodeQueue) Size() int

Size returns the total size of the messages in the queue. This function is thread-safe.

func (*NodeQueue) Submit

func (q *NodeQueue) Submit(element Element) bool

Submit submits a message for the queue.

func (*NodeQueue) Unsubmit

func (q *NodeQueue) Unsubmit(element Element) bool

Unsubmit removes a previously submitted message from the queue.

Jump to

Keyboard shortcuts

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