Documentation
¶
Index ¶
- Variables
- type BootableInterface
- type ComponentConfig
- type ComponentCreationInfo
- type ComponentFactoryInterface
- type ComponentInterface
- type ComponentRegistrarInterface
- type ComponentType
- type Configuration
- type Database
- type FactoryConfig
- type MultiStore
- type MutableDatabase
- type OperationConfiguration
- type PluginInterface
- type PluginManagerInterface
- type ReadOnlyDatabase
- type ServiceConfiguration
- type StartableInterface
- type Store
- type SystemComponentInterface
- type SystemInterface
- type SystemOperationInput
- type SystemOperationInterface
- type SystemOperationOutput
- type SystemServiceInterface
- type SystemStatusType
- type VersionedDatabase
Constants ¶
This section is empty.
Variables ¶
var ( ErrComponentNil = errors.New("component is nil") ErrComponentAlreadyExist = errors.New("component already exists") ErrFactoryNotFound = errors.New("factory not found") ErrComponentFactoryNil = errors.New("component factory is nil") ErrComponentFactoryAlreadyExists = errors.New("component factory already exists") ErrComponentNotFound = errors.New("component not found") ErrServiceAlreadyExists = errors.New("service already exists") ErrServiceNotRegistered = errors.New("service not registered") ErrOperationNotRegistered = errors.New("operation not registered") ErrOperationAlreadyExists = errors.New("operation already exists") ErrSystemNotInitialized = errors.New("system not initialized") ErrSystemNotStarted = errors.New("system not started") ErrSystemNotStopped = errors.New("system not stopped") ErrComponentTypeNotFound = errors.New("component type not found") )
Custom errors
var (
ErrStoreNotFound = errors.New("Store not found")
)
Create a new error
Functions ¶
This section is empty.
Types ¶
type BootableInterface ¶
type BootableInterface interface {
// Initialize initializes the component.
// Returns an error if the initialization fails.
Initialize(ctx *common.Context) error
}
BootableComponentInterface represents a component that can be initialized and started.
type ComponentConfig ¶
type ComponentConfig struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
FactoryID string `json:"factoryId"`
CustomConfig interface{} // Custom configuration
}
ComponentConfig represents the configuration for a component.
type ComponentCreationInfo ¶
type ComponentCreationInfo struct {
Config *ComponentConfig
Factory ComponentFactoryInterface
}
ComponentCreationInfo encapsulates the necessary information to create a component.
type ComponentFactoryInterface ¶
type ComponentFactoryInterface interface {
// CreateComponent creates a new instance of the component.
// Returns the created component and an error if the creation fails.
CreateComponent(config *ComponentConfig) (ComponentInterface, error)
}
ComponentFactoryInterface is responsible for creating
type ComponentInterface ¶
type ComponentInterface interface {
// ID returns the unique identifier of the component.
ID() string
// Name returns the name of the component.
Name() string
// Type returns the type of the component.
Type() ComponentType
// Description returns the description of the component.
Description() string
}
ComponentInterface represents a generic component in the system.
type ComponentRegistrarInterface ¶
type ComponentRegistrarInterface interface {
// GetComponentsByType retrieves components of the specified type.
// It returns a list of components and an error if the type is not found or other error.
GetComponentsByType(componentType ComponentType) []ComponentInterface
// GetComponent retrieves the component with the specified ID.
// It returns the component and an error if the component ID is not found or other error.
GetComponent(id string) (ComponentInterface, error)
// GetAllComponents returns a list of all registered components.
GetAllComponents() []ComponentInterface
// GetFactory retrieves the factory with the specified ID.
// It returns the factory and an error if the factory ID is not found or other error.
GetFactory(id string) (ComponentFactoryInterface, error)
// RegisterFactory registers a factory with the given ID.
// It returns an error if the registration fails.
RegisterFactory(ctx *common.Context, id string, factory ComponentFactoryInterface) error
// UnregisterFactory unregisters a factory with the specified ID.
// It returns an error if the ID is not found or other error.
UnregisterFactory(ctx *common.Context, id string) error
// CreateComponent creates a component with the given ID and factory ID.
// It returns the created component and an error if the creation fails.
CreateComponent(ctx *common.Context, config *ComponentConfig) (ComponentInterface, error)
// RemoveComponent removes a component with the specified ID from the registry.
// It returns an error if the ID is not found or other error.
RemoveComponent(ctx *common.Context, id string) error
}
ComponentRegistrarInterface defines the registry functionality for components and factories.
type ComponentType ¶
type ComponentType int
ComponentType represents the type of a component.
const ( // BasicComponentType represents the type of a basic component. BasicComponentType ComponentType = iota // SystemComponentType represents the type of a system component. SystemComponentType // OperationType represents the type of an operation component. OperationType // ServiceType represents the type of a service component. ServiceType // ModuleType represents the type of a module component. ApplicationComponentType )
type Configuration ¶
type Configuration struct {
Debug bool
Verbose bool
Services []*ServiceConfiguration // Service configurations
Operations []*OperationConfiguration // Operation configurations
CustomConfig interface{}
}
Configuration represents the system configuration.
type Database ¶
type Database interface {
ReadOnlyDatabase
MutableDatabase
VersionedDatabase
// Close closes the database.
Close() error
}
Database combines all the interfaces for a complete database interface.
type FactoryConfig ¶ added in v0.1.2
type FactoryConfig struct {
FactoryId string
ComponentIDs []string
Factory ComponentFactoryInterface
}
Utility type to help with component registration
type MultiStore ¶
type MultiStore interface {
Store
// GetStoreCount returns the total number of stores in the multistore.
GetStoreCount() int
// GetStore returns the store with the given namespace.
GetStore(namespace []byte) Store
// Creates and adds a new store with the given namespace.
// If a store with the same namespace already exists, it returns an error.
CreateStore(namespace string) (Store, bool, error)
}
MultiStore is a multi-store interface that manages multiple key-value stores.
type MutableDatabase ¶
type MutableDatabase interface {
// Set stores the key-value pair in the database. If the key already exists, its value will be updated.
Set(key, value []byte) error
// Delete removes the key-value pair from the database.
Delete(key []byte) error
}
MutableDatabase provides methods for modifying the database.
type OperationConfiguration ¶
type OperationConfiguration struct {
ComponentConfig
}
OperationConfiguration represents the configuration for an operation.
type PluginInterface ¶
type PluginInterface interface {
SystemServiceInterface
// RegisterResources registers resources into the system.
// Returns an error if resource registration fails.
RegisterResources(ctx *common.Context) error
}
PluginInterface represents a plugin in the system.
type PluginManagerInterface ¶
type PluginManagerInterface interface {
// Initialize initializes the manager.
// Returns an error if the initialization fails.
Initialize(ctx *common.Context, system SystemInterface) error
// AddPlugin adds a plugin to the plugin manager.
AddPlugin(ctx *common.Context, plugin PluginInterface) error
// RemovePlugin removes a plugin from the plugin manager.
RemovePlugin(plugin PluginInterface) error
// GetPlugin returns the plugin with the given name.
GetPlugin(name string) (PluginInterface, error)
// StartPlugins starts all plugins managed by the plugin manager.
StartPlugins(ctx *common.Context) error
// StopPlugins stops all plugins managed by the plugin manager.
StopPlugins(ctx *common.Context) error
// DiscoverPlugins discovers available plugins within the system.
DiscoverPlugins(ctx *common.Context) ([]PluginInterface, error)
// LoadRemotePlugin loads a plugin from a remote source.
LoadRemotePlugin(ctx *common.Context, pluginURL string) (PluginInterface, error)
}
PluginManagerInterface represents functionality for managing plugins.
type ReadOnlyDatabase ¶
type ReadOnlyDatabase interface {
// Get retrieves the value associated with the given key from the database.
Get(key []byte) ([]byte, error)
// Has checks if a key exists in the database.
Has(key []byte) (bool, error)
// Iterate iterates over all key-value pairs in the database and calls the given function for each pair.
// Iteration stops if the function returns true.
Iterate(fn func(key, value []byte) bool) error
// IterateRange iterates over key-value pairs with keys in the specified range
// and calls the given function for each pair. Iteration stops if the function returns true.
IterateRange(start, end []byte, ascending bool, fn func(key, value []byte) bool) error
// Hash returns the hash of the database.
Hash() []byte
// Version returns the version of the database.
Version() int64
// String returns a string representation of the database.
String() (string, error)
// WorkingVersion returns the current working version of the database.
WorkingVersion() int64
// WorkingHash returns the hash of the current working version of the database.
WorkingHash() []byte
// AvailableVersions returns a list of available versions.
AvailableVersions() []int
// IsEmpty checks if the database is empty.
IsEmpty() bool
}
ReadOnlyDatabase provides methods for reading data from the database.
type ServiceConfiguration ¶
type ServiceConfiguration struct {
ComponentConfig
RetryInterval time.Duration // Interval between retries
// Other service-specific configuration optionsetl.ErrScheduledProcessNotFound
CustomConfig interface{} // Custom configuration
}
type StartableInterface ¶
type StartableInterface interface {
// Start starts the component.
// Returns an error if the start operation fails.
Start(ctx *common.Context) error
// Stop stops the component.
// Returns an error if the stop operation fails.
Stop(ctx *common.Context) error
}
Startable defines the interface for instances that can be started and stopped.
type Store ¶
type Store interface {
Database
// Name returns the name of the store.
Name() string
// Path returns the path of the store.
Path() string
}
Store represents a database store.
type SystemComponentInterface ¶
type SystemComponentInterface interface {
ComponentInterface
// Initialize initializes the module.
// Returns an error if the initialization fails.
Initialize(ctx *common.Context, system SystemInterface) error
}
SystemComponentInterface represents a component in the system.
type SystemInterface ¶
type SystemInterface interface {
BootableInterface
StartableInterface
// Logger returns the system logger.
Logger() common.LoggerInterface
// EventBus returns the system event bus.
EventBus() common.EventBusInterface
// Configuration returns the system configuration.
Configuration() *Configuration
// ComponentRegistry returns the component registry
ComponentRegistry() ComponentRegistrarInterface
// MultiStore returns the multi-level store used by the system, which is a store of stores.
MultiStore() MultiStore
// PluginManager returns the plugin manager
PluginManager() PluginManagerInterface
// ExecuteOperation executes the operation with the given ID and input data.
// Returns the output of the operation and an error if the operation is not found or if execution fails.
ExecuteOperation(ctx *common.Context, operationID string, data *SystemOperationInput) (*SystemOperationOutput, error)
// StartService starts the service with the given ID.
// Returns an error if the service ID is not found or other error.
StartService(ctx *common.Context, serviceID string) error
// StopService stops the service with the given ID.
// Returns an error if the service ID is not found or other error.
StopService(ctx *common.Context, serviceID string) error
// RestartService restarts the service with the given ID.
// Returns an error if the service ID is not found or other error.
RestartService(ctx *common.Context, serviceID string) error
}
SystemInterface represents the core system in the application.
type SystemOperationInput ¶
type SystemOperationInput struct {
// Data is the input data for the operation.
Data interface{}
}
SystemOperationInput represents the input data for an operation.
type SystemOperationInterface ¶
type SystemOperationInterface interface {
SystemComponentInterface
// Execute performs the operation with the given context and input parameters,
// and returns any output or error encountered.
Execute(ctx *common.Context, input *SystemOperationInput) (*SystemOperationOutput, error)
}
SystemOperation represents a unit of work that can be executed.
type SystemOperationOutput ¶
type SystemOperationOutput struct {
// Data is the response data from the operation.
Data interface{}
}
SystemOperationOutput represents the response data from an operation.
type SystemServiceInterface ¶
type SystemServiceInterface interface {
StartableInterface
SystemComponentInterface
}
SystemServiceInterface represents a service within the system.
type SystemStatusType ¶
type SystemStatusType int
System status.
const ( SystemInitializedType SystemStatusType = iota SystemStartedType SystemStoppedType )
type VersionedDatabase ¶
type VersionedDatabase interface {
// Load loads the latest versioned database from disk.
Load() (int64, error)
// LoadVersion loads a specific version of the database from disk.
LoadVersion(targetVersion int64) (int64, error)
// SaveVersion saves a new version of the database to disk.
SaveVersion() ([]byte, int64, error)
// Rollback resets the working database to the latest saved version, discarding any unsaved modifications.
Rollback()
}
VersionedDatabase provides methods for managing versions of the database.