statemanager

package
v0.0.0-...-767acde Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2016 License: GPL-2.0 Imports: 13 Imported by: 5

Documentation

Overview

Package statemanager stores the global state and provides mechanisms for updating the state, listing for state updates, registering commands, and triggering commands

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("State Not Found")

ErrNotFound is returned when the key name is not in the current state

View Source
var ErrUnknownType = errors.New("Unknown State Type")

ErrUnknownType is returned when the type passed to the statemanager is not one of the supported types (currently string, int64, bool)

View Source
var ErrUpdaterNotFound = errors.New("Updater Not Found")

ErrUpdaterNotFound is returned when an updater cannot be located for the key name

Functions

func BaseFilePath

func BaseFilePath() string

BaseFilePath returns the base directory for loading or saving files

func Command

func Command(name string, data []string) error

Command requests the command registered with name be called and passed data as parameters. Returns nil error on success, errCommandNotFound, errCommandArguments, or an error from the registered command function

func Initialize

func Initialize()

Initialize starts up the statemanager

func Lock

func Lock()

Lock places the statemanager in a locked state, should be called before any updates to the state are made, but only once.

func ParseIDs

func ParseIDs(k string) []string

ParseIDs returns all values within () in the input string. Example Scoreboard.Team(1).Skater(abc123).Name returns ["1", "abc123"]

func RegisterCommand

func RegisterCommand(name string, c CommandFunc)

RegisterCommand registers the CommandFunc with the command subsystem with name

func RegisterPatternUpdaterBool

func RegisterPatternUpdaterBool(name string, groupPriority uint8, u UpdaterPatternBoolFunc)

RegisterPatternUpdaterBool adds a bool updater to the statemanager.

func RegisterPatternUpdaterInt64

func RegisterPatternUpdaterInt64(name string, groupPriority uint8, u UpdaterPatternInt64Func)

RegisterPatternUpdaterInt64 adds an int64 updater to the statemanager.

func RegisterPatternUpdaterString

func RegisterPatternUpdaterString(name string, groupPriority uint8, u UpdaterPatternStringFunc)

RegisterPatternUpdaterString adds a string updater to the statemanager.

func RegisterPatternUpdaterTime

func RegisterPatternUpdaterTime(name string, groupPriority uint8, u UpdaterPatternTimeFunc)

RegisterPatternUpdaterTime adds a time updater to the statemanager.

func RegisterUpdaterBool

func RegisterUpdaterBool(name string, groupPriority uint8, u UpdaterBoolFunc)

RegisterUpdaterBool adds a bool updater to the statemanager.

func RegisterUpdaterInt64

func RegisterUpdaterInt64(name string, groupPriority uint8, u UpdaterInt64Func)

RegisterUpdaterInt64 adds an int64 updater to the statemanager.

func RegisterUpdaterString

func RegisterUpdaterString(name string, groupPriority uint8, u UpdaterStringFunc)

RegisterUpdaterString adds a string updater to the statemanager.

func RegisterUpdaterTime

func RegisterUpdaterTime(name string, groupPriority uint8, u UpdaterTimeFunc)

RegisterUpdaterTime adds a time updater to the statemanager.

func SetBaseFilePath

func SetBaseFilePath(p ...string)

SetBaseFilePath sets the base directory for loading or saving files

func SetDebug

func SetDebug(d bool)

SetDebug turns debugging information on or off (sent to log)

func StateDelete

func StateDelete(k string) error

func StateSet

func StateSet(keyName string, value string) error

StateSet attempts to update the state to value using keyName to lookup a handler. It returns an error on failure.

func StateSetGroup

func StateSetGroup(values map[string]string)

StateSetGroup attempts to update the state using a map of key/values to lookup handlers. Calls StateSet for each key/values using the groupPriority of the registered updater to call lower numbers (higher priority) first. Allows setting things like min/max values before the actual number.

func StateUpdateBool

func StateUpdateBool(k string, v bool) error

func StateUpdateInt64

func StateUpdateInt64(k string, v int64) error

func StateUpdateString

func StateUpdateString(k string, v string) error

func StateUpdateTime

func StateUpdateTime(k string, v time.Time) error

func Unlock

func Unlock()

Unlock removes the lock from the statemanager and starts the processing of any updates to listeners waiting for changes

func UnregisterCommand

func UnregisterCommand(name string)

UnregisterCommand removes the CommandFunc registered with name from the command subsystem

func UnregisterUpdater

func UnregisterUpdater(name string)

UnregisterUpdater removes an updater from the statemanager.

Types

type CommandFunc

type CommandFunc func([]string) error

CommandFunc is a callback function when a command is triggered. Commands can be registered by RegisterCommand and unregistered by UnregisterCommand

type Listener

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

Listener allows functions to listen for changes in the state of the scoreboard

func NewListener

func NewListener(name string, cb func(map[string]*string)) *Listener

NewListener creates a listener with name describing the listener (for log messages) and cb is a callback function which gets called on changes to the state filtered by Listener.RegisterPaths

func (*Listener) Close

func (l *Listener) Close()

Close closes the listener. After this call it the callback will never be called for this listener again.

func (*Listener) RegisterPaths

func (l *Listener) RegisterPaths(paths []string)

RegisterPaths adds the paths to the listener to get updates. See PatternMatch for examples of how the pattern matching is done. The callback will immediately be called with and matching paths before returning to the caller.

func (*Listener) UnregisterPaths

func (l *Listener) UnregisterPaths(paths []string)

UnregisterPaths removes the paths from the listener.

type Saver

type Saver struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Saver handles saving part (or all) of the state to a file

func NewSaver

func NewSaver(name, base string, interval time.Duration, version, setFromFile bool) *Saver

NewSaver creates a new saver. name: name of the file base: pattern to match (see PatternMatch for examples of matching) interval: time between saves. Zero if you want/need a save on every change, will only

save if something has actually changed

version: save older versions of the file (move file to file.1, file.1 to file.2, etc) NOT IMPLEMENTED!

func (*Saver) Close

func (s *Saver) Close()

Close unregisters the Saver from the statemanager and stops the saving go routine (issuing one last save in case there were changes since last save)

type UpdaterBoolFunc

type UpdaterBoolFunc func(bool) error

UpdaterBoolFunc is a callback type for bool updates from the state engine

type UpdaterInt64Func

type UpdaterInt64Func func(int64) error

UpdaterInt64Func is a callback type for int64 updates from the state engine

type UpdaterPatternBoolFunc

type UpdaterPatternBoolFunc func(string, bool) error

UpdaterPatternBoolFunc is a callback type for bool updates from the state engine

type UpdaterPatternInt64Func

type UpdaterPatternInt64Func func(string, int64) error

UpdaterPatternInt64Func is a callback type for int64 updates from the state engine

type UpdaterPatternStringFunc

type UpdaterPatternStringFunc func(string, string) error

UpdaterPatternStringFunc is a callback type for string updates from the state engine

type UpdaterPatternTimeFunc

type UpdaterPatternTimeFunc func(string, time.Time) error

UpdaterPatternTimeFunc is a callback type for time updates from the state engine

type UpdaterStringFunc

type UpdaterStringFunc func(string) error

UpdaterStringFunc is a callback type for string updates from the state engine

type UpdaterTimeFunc

type UpdaterTimeFunc func(time.Time) error

UpdaterTimeFunc is a callback type for time updates from the state engine

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL