Documentation ¶
Index ¶
- type GenericStore
- func NewGenericStore[SharedObject any, ObjID comparable, InitParams any](getID func(obj SharedObject) ObjID, idLess func(a, b ObjID) bool, ...) *GenericStore[SharedObject, ObjID, InitParams]
- func NewStore[CustomSharedObject SharedObject[CustomSharedObject, InitParams], ...](getID func(obj CustomSharedObject) string, l utils.Logger) *GenericStore[CustomSharedObject, string, InitParams]
- func (s *GenericStore[SharedObject, ObjID, InitParams]) Close()
- func (s *GenericStore[SharedObject, ObjID, InitParams]) Get(objID ObjID) SharedObject
- func (s *GenericStore[SharedObject, ObjID, InitParams]) Init(initParams InitParams) error
- func (s *GenericStore[SharedObject, ObjID, InitParams]) RecentlyRegisteredSharedObjects() []ObjID
- func (s *GenericStore[SharedObject, ObjID, InitParams]) Register(obj interface{})
- func (s *GenericStore[SharedObject, ObjID, InitParams]) Start() error
- func (s *GenericStore[SharedObject, ObjID, InitParams]) Stop()
- func (s *GenericStore[SharedObject, ObjID, InitParams]) TopLevelDependencies() []ObjID
- type ObjCloseFunc
- type ObjInitFunc
- type ObjRequirementsFunc
- type ObjStartFunc
- type ObjStopFunc
- type SharedObject
- type SharedRegistry
- type SharedStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GenericStore ¶
type GenericStore[SharedObject any, ObjID comparable, InitParams any] struct { // contains filtered or unexported fields }
func NewGenericStore ¶
func NewGenericStore[SharedObject any, ObjID comparable, InitParams any]( getID func(obj SharedObject) ObjID, idLess func(a, b ObjID) bool, gatherRequirements ObjRequirementsFunc[SharedObject, ObjID, InitParams], initObj ObjInitFunc[SharedObject, InitParams], startObj ObjStartFunc[SharedObject, InitParams], stopObj ObjStopFunc[SharedObject], closeObj ObjCloseFunc[SharedObject], l utils.Logger, ) *GenericStore[SharedObject, ObjID, InitParams]
This is a generic store for shared objects. It can be used to support another interface instead of SharedObject. All lyfecycle functions are optional except Init.
func NewStore ¶
func NewStore[CustomSharedObject SharedObject[CustomSharedObject, InitParams], InitParams any](getID func(obj CustomSharedObject) string, l utils.Logger) *GenericStore[CustomSharedObject, string, InitParams]
func (*GenericStore[SharedObject, ObjID, InitParams]) Close ¶
func (s *GenericStore[SharedObject, ObjID, InitParams]) Close()
Close must be called after Stop. It is used to finalize objects. Can be used to free resources and ensure they are not used anywhere else. The only thing it does is calls Close() on all objects in the store.
func (*GenericStore[SharedObject, ObjID, InitParams]) Get ¶
func (s *GenericStore[SharedObject, ObjID, InitParams]) Get(objID ObjID) SharedObject
Returns object by its ID.
func (*GenericStore[SharedObject, ObjID, InitParams]) Init ¶
func (s *GenericStore[SharedObject, ObjID, InitParams]) Init(initParams InitParams) error
Init must be called first of all lifecycle methods. It is intended for gathering objects requirements and then setting their initial state. After Init has finished, object must be able to receive calls from other objects.
func (*GenericStore[SharedObject, ObjID, InitParams]) RecentlyRegisteredSharedObjects ¶
func (s *GenericStore[SharedObject, ObjID, InitParams]) RecentlyRegisteredSharedObjects() []ObjID
Returns objects, which were registered from last call of this method. It includes registration even if registered object was already in the store. This might be useful to retrieve requrements of the object without knowing what it does.
func (*GenericStore[SharedObject, ObjID, InitParams]) Register ¶
func (s *GenericStore[SharedObject, ObjID, InitParams]) Register(obj interface{})
Register object to be shared with other users. Expects pointer to pointer.
func (*GenericStore[SharedObject, ObjID, InitParams]) Start ¶
func (s *GenericStore[SharedObject, ObjID, InitParams]) Start() error
Start must be called after Init. It is used as PostInit hook. It is intended for starting background processes, timers, etc. The onlt thing it does is calls Start() on all objects in the store.
func (*GenericStore[SharedObject, ObjID, InitParams]) Stop ¶
func (s *GenericStore[SharedObject, ObjID, InitParams]) Stop()
Stop must be called after Start. It is used as PreClose hook. It is intended for stopping background processes, timers, etc. The only thing it does is calls Stop() on all objects in the store.
func (*GenericStore[SharedObject, ObjID, InitParams]) TopLevelDependencies ¶
func (s *GenericStore[SharedObject, ObjID, InitParams]) TopLevelDependencies() []ObjID
Returns all objects, which were registered in the store before Init() was called.
type ObjCloseFunc ¶
type ObjCloseFunc[SharedObject any] func(obj SharedObject)
type ObjInitFunc ¶
type ObjRequirementsFunc ¶
type ObjRequirementsFunc[SharedObject any, ObjID comparable, InitParams any] func(obj SharedObject, s *GenericStore[SharedObject, ObjID, InitParams])
type ObjStartFunc ¶
type ObjStopFunc ¶
type ObjStopFunc[SharedObject any] func(obj SharedObject)
type SharedObject ¶
type SharedObject[CustomSharedObject any, InitParams any] interface { // gather requirements of the object. You must call store.Register(obj) for each // object you depend on. RegisterDependencies(s SharedStore[CustomSharedObject, InitParams]) // It is intended for setting up initial state of the object. // When Init returns, object is expected to be able to receive calls from other objects. Init(p InitParams) error // It is intended for starting background processes, timers, etc. Start(p InitParams) error // It is intended for stopping background processes, timers, etc. Stop() // Can be used to free resources and ensure they are not used anywhere else. Close() }
type SharedRegistry ¶
type SharedRegistry[ObjType any] interface { // Expects pointer to pointer. Register(obj interface{}) }
type SharedStore ¶
type SharedStore[CustomSharedObject any, InitParams any] interface { SharedRegistry[CustomSharedObject] // It gathers objects requirements and then calls Init() on all objects. Init(params InitParams) error // It is intended for starting background processes, timers, etc. // The onlt thing it does is calls Start() on all objects in the store. Start() error // It is intended for stopping background processes, timers, etc. // The only thing it does is calls Stop() on all objects in the store. Stop() // Can be used to free resources and ensure they are not used anywhere else. // The only thing it does is calls Close() on all objects in the store. Close() Get(objID string) CustomSharedObject TopLevelDependencies() []string // It includes registration even if registered object was already in the store. // This might be useful to retrieve requrements of the object without knowing what it does. RecentlyRegisteredSharedObjects() []string }