schedulerutils

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: Apache-2.0, BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const ElementIDLength = 32

ElementIDLength defines the length of an ElementID.

Variables

View Source
var (
	// ErrInboxExceeded is returned when a node has exceeded its allowed inbox size.
	ErrInboxExceeded = errors.New("maximum mana-scaled inbox length exceeded")
	// ErrInsufficientMana is returned when the mana is insufficient.
	ErrInsufficientMana = errors.New("insufficient node's mana to schedule the message")
	// ErrBufferFull is returned when the maximum buffer size is exceeded.
	ErrBufferFull = errors.New("maximum buffer size exceeded")
)

Functions

This section is empty.

Types

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) 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) 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, rep float64) error

Submit submits a message.

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