events

package
v0.0.0-...-6d29b5c Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const LazyQueueChanSize int = 100

Variables

This section is empty.

Functions

func Identity

func Identity(m interface{}) interface{}

Types

type ActiveEventObserver

type ActiveEventObserver struct {
	*Decorator
	// contains filtered or unexported fields
}

An active event observer calls the proxy on receival of an event.

func NewActiveEventObserver

func NewActiveEventObserver(receiver Receiver) *ActiveEventObserver

func (*ActiveEventObserver) Receive

func (o *ActiveEventObserver) Receive(e *Event) *Event

type ActiveObserver

type ActiveObserver interface {
	Decorable
	Observer
}

An active observer is an observer which allows for a proxy. It's intent for usage is allowing for calling a Proxy at a higher level.

type CallbackReceiver

type CallbackReceiver interface {
	interfaces.Callback
	Receiver
}

func NewCallback

func NewCallback(exec func()) CallbackReceiver

type Decorable

type Decorable interface {
	SetProxy(Proxy)
}

An interface is a Decorable if it provides a proxy to be set. Before a message is pushed into a channel the proxy should process the message.

type Decorator

type Decorator struct {
	Proxy
}

A Decorator is the implementation of a Decorable.

func NewDecorator

func NewDecorator() *Decorator

func (*Decorator) SetProxy

func (d *Decorator) SetProxy(p Proxy)

type Event

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

func NewEvent

func NewEvent(timestamp int, payload interface{}, receiver Receiver) *Event

func (*Event) Payload

func (e *Event) Payload() interface{}

func (*Event) Receiver

func (e *Event) Receiver() Receiver

func (*Event) Timestamp

func (e *Event) Timestamp() int

type EventQueue

type EventQueue interface {
	Push(e *Event)
	Pop() *Event
}

The Event Queue is a priority queue ordered by timestamps which delivers Events to Receivers. The queue is thread-safe and it uses a head together with a push channel which allows faster pushes.

func NewLazyEventQueue

func NewLazyEventQueue() EventQueue

type GlobalEventObserver

type GlobalEventObserver struct {
	*Decorator
	// contains filtered or unexported fields
}

GlobalEventObserver is a passive observer which monitors all events. These events can be used for monitoring and logging purposes.

func NewGlobalEventObserver

func NewGlobalEventObserver() *GlobalEventObserver

func (*GlobalEventObserver) Receive

func (o *GlobalEventObserver) Receive(e *Event) *Event

func (*GlobalEventObserver) Recv

func (o *GlobalEventObserver) Recv() <-chan interface{}

type Observer

type Observer interface {
	Receiver
}

An observer is a special type of receiver that is used to monitor events related to a observer. When the simulation pops an event, all registered observers are notified. Registering an observer has priority over processing events, thus allowing registration at any moment.

type PassiveEventObserver

type PassiveEventObserver struct {
	*Decorator
	// contains filtered or unexported fields
}

A passive event observer is a PassiveObserver that calls a proxy function before delivering a message to the Recv channel.

func NewPassiveEventObserver

func NewPassiveEventObserver(receiver Receiver) *PassiveEventObserver

func (*PassiveEventObserver) Receive

func (o *PassiveEventObserver) Receive(e *Event) *Event

func (*PassiveEventObserver) Recv

func (o *PassiveEventObserver) Recv() <-chan interface{}

type PassiveObserver

type PassiveObserver interface {
	Decorable
	Observer

	Recv() <-chan interface{}
}

A passive observer keeps all the events that were received by it in a a channel. Moreover, it allows proxying the receival of an event by using using the Decorable interface. This means that the event can be processed before being put into the Recv channel.

type Producer

type Producer interface {
	Produce() *Event
}

type Proxy

type Proxy func(interface{}) interface{}

A Proxy is a function to be executed before pushing a message into a channel.

func NewProxy

func NewProxy(f func()) Proxy

Creates a Proxy from a function that doesn't return an interface.

type Receiver

type Receiver interface {
	Receive(*Event) *Event
}

type RoutineReceiver

type RoutineReceiver interface {
	interfaces.Routine
	Receiver
}

func NewRoutine

func NewRoutine(interval int, exec func()) RoutineReceiver

type Simulation

type Simulation struct {
	EventQueue
	// contains filtered or unexported fields
}

The Simulation works as follows. At each moment the event with the smallest timestamp is popped out of the priority queue. When we pop the element we also notify all the observers associated with the event’s receiver. Registering an observer has priority over processing events, thus allowing the user to register observers at any moment. Since we allow any process to read the time, updating the time with the time of the current event is protected via a read-write lock.

func NewLazySimulation

func NewLazySimulation() (s *Simulation)

func (*Simulation) Handle

func (s *Simulation) Handle()

Handling events synchronously.

func (*Simulation) HandleParallel

func (s *Simulation) HandleParallel()

Handling events in parallel.

We allow parallel exectution following the next pipeline: - pop all events with the time-stamp equal with now - group all these events in event groups by the receiver address - execute the receivers in parallel - wait for all receivers to finish their execution

func (*Simulation) RegisterObserver

func (s *Simulation) RegisterObserver(eventObserver Observer)

func (*Simulation) Run

func (s *Simulation) Run()

func (*Simulation) SetParallel

func (s *Simulation) SetParallel(parallel bool)

func (*Simulation) Stop

func (s *Simulation) Stop()

func (*Simulation) Time

func (s *Simulation) Time() int

Jump to

Keyboard shortcuts

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