Documentation
¶
Index ¶
- type EventPuller
- type SharedObject
- type SharedObjectBase
- func (o *SharedObjectBase[Ctx, InitParams]) Close()
- func (o *SharedObjectBase[Ctx, InitParams]) GetUpdateNode() updtree.Node[Ctx]
- func (o *SharedObjectBase[Ctx, InitParams]) HasUpdated() bool
- func (o *SharedObjectBase[Ctx, InitParams]) Hash() string
- func (p *SharedObjectBase[Ctx, InitParams]) Init(params InitParams) error
- func (o *SharedObjectBase[Ctx, InitParams]) Name() string
- func (s *SharedObjectBase[Ctx, InitParams]) NotifyUpdated(ctx Ctx, evtTime time.Time)
- func (o *SharedObjectBase[Ctx, InitParams]) RegisterDependencies(store objstore.SharedStore[SharedObject[Ctx, InitParams], InitParams])
- func (s *SharedObjectBase[Ctx, InitParams]) SetUpdateHandler(handler func(ctx Ctx, evtTime time.Time))
- func (o *SharedObjectBase[Ctx, InitParams]) Start(params InitParams) error
- func (o *SharedObjectBase[Ctx, InitParams]) Stop()
- func (o *SharedObjectBase[Ctx, InitParams]) Subscribe(subscriber updtree.Node[Ctx])
- func (o *SharedObjectBase[Ctx, InitParams]) SubscribeObj(subscriber SharedObject[Ctx, InitParams])
- type SharedObjectBaseWithEvent
- type SharedStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventPuller ¶
type EventPuller[Event any] interface { // Pulls all events from the storage published since last pull. Pull() []updtree.AccumulatedEvent[Event] // Discards all events except the last one. If no events were published since last pull, returns nil. Last() (lastPublishedEventIfExists *Event) }
type SharedObject ¶
type SharedObject[Ctx, InitParams any] interface { objstore.SharedObject[SharedObject[Ctx, InitParams], InitParams] updtree.UpdateSubscription[Ctx] }
type SharedObjectBase ¶
type SharedObjectBase[Ctx, InitParams any] struct { // contains filtered or unexported fields }
SharedObjectBase is a helper base struct for shared objects. It does three things: * implements SharedObject interface, * manages updtree.Node to provide method NotifyUpdated(), * calculates hash of the object based on its parameters, which then used as object ID. If in addition to that you also need event publishing capabilities, use SharedObjectBaseWithEvent.
func NewSharedObjectBase ¶
func NewSharedObjectBase[Ctx, InitParams any](name string, params ...interface{}) SharedObjectBase[Ctx, InitParams]
func (*SharedObjectBase[Ctx, InitParams]) Close ¶
func (o *SharedObjectBase[Ctx, InitParams]) Close()
One of lifecycle methods. See SharedObject interface for details.
func (*SharedObjectBase[Ctx, InitParams]) GetUpdateNode ¶
func (o *SharedObjectBase[Ctx, InitParams]) GetUpdateNode() updtree.Node[Ctx]
func (*SharedObjectBase[Ctx, InitParams]) HasUpdated ¶
func (o *SharedObjectBase[Ctx, InitParams]) HasUpdated() bool
Check that this node has been updated. Can be used, when processing updates and need to know which of subscriptions has been updated.
func (*SharedObjectBase[Ctx, InitParams]) Hash ¶
func (o *SharedObjectBase[Ctx, InitParams]) Hash() string
Hash is used as unique ID of the object. It is calculated based on object parameters and name. That's why it is important to pass ALL parameters into contructor.
func (*SharedObjectBase[Ctx, InitParams]) Init ¶
func (p *SharedObjectBase[Ctx, InitParams]) Init(params InitParams) error
One of lifecycle methods. See SharedObject interface for details.
func (*SharedObjectBase[Ctx, InitParams]) Name ¶
func (o *SharedObjectBase[Ctx, InitParams]) Name() string
Name returns object name. It is mostly for debugging purposes. However, it is still used as part of object hash. So avoid making it different for the objects of same type and parameters, because that would negate purpose of sharing.
func (*SharedObjectBase[Ctx, InitParams]) NotifyUpdated ¶
func (s *SharedObjectBase[Ctx, InitParams]) NotifyUpdated(ctx Ctx, evtTime time.Time)
NotifyUpdated notifies all subscribers that something changed.
func (*SharedObjectBase[Ctx, InitParams]) RegisterDependencies ¶
func (o *SharedObjectBase[Ctx, InitParams]) RegisterDependencies(store objstore.SharedStore[SharedObject[Ctx, InitParams], InitParams])
One of lifecycle methods. See SharedObject interface for details.
func (*SharedObjectBase[Ctx, InitParams]) SetUpdateHandler ¶
func (s *SharedObjectBase[Ctx, InitParams]) SetUpdateHandler(handler func(ctx Ctx, evtTime time.Time))
SetUpdateHandler sets function, which will be called when any of subscriptions has updated.
func (*SharedObjectBase[Ctx, InitParams]) Start ¶
func (o *SharedObjectBase[Ctx, InitParams]) Start(params InitParams) error
One of lifecycle methods. See SharedObject interface for details.
func (*SharedObjectBase[Ctx, InitParams]) Stop ¶
func (o *SharedObjectBase[Ctx, InitParams]) Stop()
One of lifecycle methods. See SharedObject interface for details.
func (*SharedObjectBase[Ctx, InitParams]) Subscribe ¶
func (o *SharedObjectBase[Ctx, InitParams]) Subscribe(subscriber updtree.Node[Ctx])
func (*SharedObjectBase[Ctx, InitParams]) SubscribeObj ¶
func (o *SharedObjectBase[Ctx, InitParams]) SubscribeObj(subscriber SharedObject[Ctx, InitParams])
SubscribeObj subscribes given object to updates of receiver.
type SharedObjectBaseWithEvent ¶ added in v1.0.1
type SharedObjectBaseWithEvent[Ctx, InitParams any, Event any] struct { SharedObjectBase[Ctx, InitParams] // contains filtered or unexported fields }
SharedObjectBaseWithEvent is same as SharedObjectBase, but with event publishing capabilities.
func NewSharedObjectBaseWithEvent ¶ added in v1.0.1
func NewSharedObjectBaseWithEvent[Ctx, InitParams any, Event any](name string, params ...interface{}) SharedObjectBaseWithEvent[Ctx, InitParams, Event]
NewSharedObjectBaseWithEvent creates new SharedObjectBaseWithEvent. SharedObjectBaseWithEvent is same as SharedObjectBase, but with event publishing capabilities.
func (*SharedObjectBaseWithEvent[Ctx, InitParams, Event]) NewEventPuller ¶ added in v1.0.1
func (o *SharedObjectBaseWithEvent[Ctx, InitParams, Event]) NewEventPuller() EventPuller[Event]
NewEventPuller returns new event puller for this object. Events must be pulled from it at least periodically, or it will cause memory leak.
func (*SharedObjectBaseWithEvent[Ctx, InitParams, Event]) PublishEvent ¶ added in v1.0.1
func (o *SharedObjectBaseWithEvent[Ctx, InitParams, Event]) PublishEvent(ctx Ctx, evtTime time.Time, evt Event)
PublishEvent publishes event and notifies all subscribers about update.
type SharedStore ¶
type SharedStore[Ctx, InitParams any] objstore.SharedStore[SharedObject[Ctx, InitParams], InitParams]
func NewSharedStore ¶
func NewSharedStore[Ctx, InitParams any](l utils.Logger) SharedStore[Ctx, InitParams]