Documentation ¶
Index ¶
- Constants
- func Identity(m interface{}) interface{}
- type ActiveEventObserver
- type ActiveObserver
- type CallbackReceiver
- type Decorable
- type Decorator
- type Event
- type EventQueue
- type GlobalEventObserver
- type Observer
- type PassiveEventObserver
- type PassiveObserver
- type Producer
- type Proxy
- type Receiver
- type RoutineReceiver
- type Simulation
Constants ¶
const LazyQueueChanSize int = 100
Variables ¶
This section is empty.
Functions ¶
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 ¶
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
type EventQueue ¶
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 ¶
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 Proxy ¶
type Proxy func(interface{}) interface{}
A Proxy is a function to be executed before pushing a message into a channel.
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) 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