Documentation ¶
Overview ¶
Package kernel is a simple microkernel that allows for Service's to be deployed within an application.
It manages the complete lifecycle of the application with muliple stages each called in sequence: Init, PostInit, Start & Run. Once the kernel gets to the Start phase then any Error will cause the Stop phase to be invoked to allow any Started service to cleanup.
For most simple applications you can simply use kernel.Launch( s ) where s is an uninitiated service and it will create a Kernel add that service and run it.
For more complex applications which need multiple unrelated services deployed then it can do by calling NewKernel() to create a new kernel, add each one via AddService() and then call Run() - this is what Launch() does internally.
A Service is simply an Object implementing the Service interface and one or more of the various lifecycle interfaces.
If a service has injectionPoints then it should implement Init() and call AddService to add them - the kernel will handle the rest.
Index ¶
- func Launch(services ...Service) error
- func Register(services ...Service)
- func RegisterAPI(api interface{}, service Service)
- type Daemon
- type InitialisableService
- type Kernel
- type MemUsage
- type NamedService
- type PostInitialisableService
- type RunnableService
- type Service
- type StartableService
- type StoppableService
- type Worker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Launch ¶
Launch is a convenience method to launch a single service. This does the boiler plate work and requires the single service adds any injectionPoints within it's Init() method, if any
Types ¶
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
func (*Daemon) ClearDaemon ¶
func (d *Daemon) ClearDaemon()
func (*Daemon) IsWebserver ¶
func (*Daemon) SetWebserver ¶
func (d *Daemon) SetWebserver()
type InitialisableService ¶
type InitialisableService interface { // Init initialises a Service when it's added to the Kernel Init(*Kernel) error }
InitialisableService a Service that expects to be called in the Init lifecycle phase
type Kernel ¶
type Kernel struct {
// contains filtered or unexported fields
}
Kernel is the core container for deployed services
func (*Kernel) AddService ¶
AddService adds a service to the kernel
type MemUsage ¶
type MemUsage struct {
// contains filtered or unexported fields
}
MemUsage is a Kernel service which will log on shutdown the duration of the process and how much memory it has used.
To use simply include it as the first service when launching the kernel:
func main() { err := kernel.Launch( &kernel.MemUsage{}, &mylib.MyService{} ) if err != nil { log.Fatal( err ) } }
When the service stops then some statistics are logged showing how long the process has run, how much memory it's used and how often the garbage collector has run.
Notes:
The process duration time is from when the Start phase begins. If the kernel fails before that then no stats are generated. This is because services only get stopped if they have started.
type NamedService ¶
type NamedService interface { // Name returns the unique name of this service Name() string }
NamedService is the original Service where the Name() function returns the unique name. This is now optional, a service does not require Name() anymore.
type PostInitialisableService ¶
type PostInitialisableService interface { // PostInit initialises a Service when it's added to the Kernel PostInit() error }
PostInitialisableService a Service that expects to be called in the PostInit lifecycle phase
type RunnableService ¶
type RunnableService interface { // Run executes the service Run() error }
RunnableService a Service that is expected to run in the Run lifecycle phase
type StartableService ¶
type StartableService interface { // Start called when the Kernel starts but before services Run Start() error }
StartableService a Service that expects to be called in the Start lifecycle phase
type StoppableService ¶
type StoppableService interface {
Stop()
}
StoppableService a Service that expects to be called when the kernel shutsdown if it's in the Start or Run lifecycle phases
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
func (*Worker) AddPriorityTask ¶
AddPriorityTask adds a task with a specific priority. Tasks with a higher priority value will run AFTER those with a lower value.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
A simple kernel service wich provides access to a single github.com/etcd-io/bbolt object store
|
A simple kernel service wich provides access to a single github.com/etcd-io/bbolt object store |
Package cron This provides the Kernel a managed Cron service.
|
Package cron This provides the Kernel a managed Cron service. |
A simple amqp library for connecting to RabbitMQ
|
A simple amqp library for connecting to RabbitMQ |
A basic REST server supporting HTTP.
|
A basic REST server supporting HTTP. |
test
|
|