anagent: github.com/mudler/anagent Index | Files

package anagent

import "github.com/mudler/anagent"

Index

Package Files

anagent.go util.go

Constants

const VERSION = "0.1"

VERSION contains the Anagent version number

func GetMD5Hash Uses

func GetMD5Hash(text string) string

GetMD5Hash is a utility function to get MD5 digest of the supplied string.

type Anagent Uses

type Anagent struct {
    inject.Injector
    sync.Mutex

    // Fatal         bool
    Started       bool
    BusyLoop      bool
    StartedAccess *sync.Mutex
    // contains filtered or unexported fields
}

Anagent represents the top level application. inject.Injector methods can be invoked to map services on a global level.

func New Uses

func New() *Anagent

New creates a bare bones Anagent instance. Use this method if you want to have full control over the middleware that is used.

func (*Anagent) AddRecurringTimerSeconds Uses

func (a *Anagent) AddRecurringTimerSeconds(seconds int64, handler Handler) TimerID

AddRecurringTimerSeconds is used to set a recurring timer, that will fire after the seconds supplied. It requires seconds supplied as int64 and at the end the callback to be fired at the desired time.

func (*Anagent) AddTimerSeconds Uses

func (a *Anagent) AddTimerSeconds(seconds int64, handler Handler) TimerID

AddTimerSeconds is used to set a non recurring timer, that will fire after the seconds supplied. It requires seconds supplied as int64 and at the end the callback to be fired at the desired time.

func (*Anagent) Emit Uses

func (a *Anagent) Emit(event interface{}) *Anagent

Emit Emits an event, it does accept only the event as argument, since the callback will have access to the service mapped by the injector

func (*Anagent) EmitSync Uses

func (a *Anagent) EmitSync(event interface{}) *Anagent

EmitSync Emits an event in a syncronized manner, it does accept only the event as argument, since the callback will have access to the service mapped by the injector

func (*Anagent) Emitter Uses

func (a *Anagent) Emitter() *emission.Emitter

Emitter returns the internal *emission.Emitter used structure use this to access directly to the Emitter, and override the dependency-injection features

func (*Anagent) GetTimer Uses

func (a *Anagent) GetTimer(id TimerID) *Timer

GetTimer is used to set a get a timer from the loop. It requires a TimerID

func (*Anagent) Handlers Uses

func (a *Anagent) Handlers(handlers ...Handler)

Handlers sets the entire middleware stack with the given Handlers. This will clear any current middleware handlers, and panics if any of the handlers is not a callable function

func (*Anagent) IsStarted Uses

func (a *Anagent) IsStarted() bool

IsStarted returns a boolean indicating if we started the loop with Start()

func (*Anagent) Next Uses

func (a *Anagent) Next(handler Handler)

Next adds a middleware Handler to the next tick, and removes it once executed.

func (*Anagent) On Uses

func (a *Anagent) On(event, listener interface{}) *Anagent

On Binds a callback to an event, mapping the arguments on a global level

func (*Anagent) Once Uses

func (a *Anagent) Once(event, listener interface{}) *Anagent

Once Binds a callback to an event, mapping the arguments on a global level It is fired only once.

func (*Anagent) RemoveTimer Uses

func (a *Anagent) RemoveTimer(id TimerID)

RemoveTimer is used to set a remove a timer from the loop. It requires a TimerID

func (*Anagent) RunLoop Uses

func (a *Anagent) RunLoop()

RunLoop starts a loop that never returns

func (*Anagent) SetDuration Uses

func (a *Anagent) SetDuration(id TimerID, after time.Duration) TimerID

SetDuration is used to change the duration of a timer. It requires a TimerID and a time.Duration

func (*Anagent) Start Uses

func (a *Anagent) Start()

Start starts the agent loop and never returns. ( unless you call Stop() )

func (*Anagent) Step Uses

func (a *Anagent) Step()

Step executes an agent step. It is idempotent, and even if there are delays in timings events gets executed in order as a best-effort in respecting setted timers.

func (*Anagent) Stop Uses

func (a *Anagent) Stop()

Stop stops the agent loop, in case Start() was called.

func (*Anagent) Timer Uses

func (a *Anagent) Timer(tid TimerID, ti time.Time, after time.Duration, recurring bool, handler Handler) TimerID

Timer is used to set a generic timer. You have to supply by yourself all the options that normally are exposed with other functions. It requires a TimerID (if empty is supplied, it is created for you), a time.Time indicating when the timer have to be fired, a time.Duration indicating the recurring span a boolean to set it as recurring or not and at the end the callback to be fired at the desired time.

func (*Anagent) TimerSeconds Uses

func (a *Anagent) TimerSeconds(seconds int64, recurring bool, handler Handler) TimerID

TimerSeconds is used to set a timer, that will fire after the seconds supplied. It requires seconds supplied as int64 a bool indicating if it is recurring or not, and at the end the callback to be fired at the desired time.

func (*Anagent) Use Uses

func (a *Anagent) Use(handler Handler)

Use adds a middleware Handler to the stack, and panics if the handler is not a callable func. Middleware Handlers are invoked in the order that they are added.

type Handler Uses

type Handler interface{}

Handler can be any callable function. Anagent attempts to inject services into the handler's argument list, and panics if an argument could not be fulfilled via dependency injection.

type Timer Uses

type Timer struct {
    // contains filtered or unexported fields
}

Timer represent the structure that holds the informations of the Timer timer it's a time.Time structure that defines when the timer should be fired, after contains the time.Duration of the recurring timer.

func (*Timer) After Uses

func (t *Timer) After(ti time.Duration)

After receives a time.Duration as arguments, and sets the timer recurring time.

type TimerID Uses

type TimerID string

TimerID is a string that represent the timers ID, it is used so we can access to them later or modify them during the agent execution.

func RandTimer Uses

func RandTimer(m map[TimerID]*Timer) (TimerID, *Timer)

Package anagent imports 8 packages (graph). Updated 2018-09-03. Refresh now. Tools for package owners.