Documentation
¶
Overview ¶
Package api contains the main API to Brawler.
Index ¶
- Constants
- Variables
- func EngineExists(name string) bool
- func GetEngineNames() []string
- func GetEventSourceNames() []string
- func RegisterEventSource(name string, engine string) brawler.EventPublisher
- func RunRumbleCode(procName, codeName, code string, wg *sync.WaitGroup) (string, error)
- type BrawlerEngine
- type LogMessage
- type LogWriter
- type MemoryLogWriter
Constants ¶
const ( ErrorRestAPI = "Rest API Error" ErrorRumbleParser = "Rumble Parser Error" ErrorRumbleRuntime = "Rumble Runtime Error" )
Error types for Brawler API
Variables ¶
DefaultLogLevel is the default log level which is used by every new engine
var EngineSinkDirectories = "sinks"
EngineSinkDirectories contains initialisation sinks for new engines. All .ram files will be loaded from <EngineSinkDirectories>/<engine name>
var EventSourceEngineCheckTime int64 = 5
EventSourceEngineCheckTime is the time in seconds an event source waits until it checks again for available engines.
var LogSize = 50
LogSize is the log size for each created processor
var NewLogWriter = func(engine string) LogWriter { return &MemoryLogWriter{datautil.NewRingBuffer(LogSize)} }
NewLogWriter returns a new log writer instance and is called when a new engine is created.
var ProcessorWorkerCount = 4
ProcessorWorkerCount is the worker count for each created processor
Result is a special log level indicating a result of a manually entered command
Functions ¶
func EngineExists ¶
EngineExists checks if a given engine exists.
func GetEngineNames ¶
func GetEngineNames() []string
GetEngineNames returns all available engine names.
func GetEventSourceNames ¶
func GetEventSourceNames() []string
GetEventSourceNames returns all registered event sources.
func RegisterEventSource ¶
func RegisterEventSource(name string, engine string) brawler.EventPublisher
RegisterEventSource registers a new event source which can inject external events into a Brawler engine. If the engine name is empty then the events are injected into all known engines. It returns an EventPublisher object which should be used by the event source to inject events.
Types ¶
type BrawlerEngine ¶
type BrawlerEngine struct { Proc engine.Processor // Actual processor which load rules and processes events Log LogWriter // Log of the processor LogLevel rumble.LogLevel // LogLevel of this engine RootVars parser.VarsScope // Root variable scope of the engine EchoNilResults bool // Flag if nil results should be echoed (used for consoles) Sinks map[string]*parser.ASTNode // Loaded Rumble sinks // contains filtered or unexported fields }
BrawlerEngine is used to define a processing unit in the API.
func GetEngine ¶
func GetEngine(name string, reset bool) *BrawlerEngine
GetEngine returns a BrawlerEngine of a certain namme. The engine is created if it does not exist. If the reset flag is set then all current loaded sinks are discarded and the default sinks are loaded again.
func (*BrawlerEngine) AddLogMessage ¶
func (re *BrawlerEngine) AddLogMessage(m *LogMessage)
AddLogMessage adds a log message to the log if it meets the current log level of the engine.
func (*BrawlerEngine) DefaultRootMonitorErrorObserver ¶
func (re *BrawlerEngine) DefaultRootMonitorErrorObserver(rm *engine.RootMonitor)
DefaultRootMonitorErrorObserver is the default observer for root monitor errors. The observer logs all encountered errors in the engine's log.
func (*BrawlerEngine) String ¶
func (re *BrawlerEngine) String() string
String returns a string representation of the engine.
type LogMessage ¶
LogMessage models a single log message
func (*LogMessage) String ¶
func (lm *LogMessage) String() string
type LogWriter ¶
type LogWriter interface { /* Add adds a new log message. */ Add(*LogMessage) /* Slice returns the contents of the current log as a slice. */ Slice() []*LogMessage /* Resets the current log. */ Reset() /* Size returns the current log size. */ Size() int /* String returns the current log as a string. */ String() string }
LogWriter models the log writer for a BrawlerEngine
type MemoryLogWriter ¶
type MemoryLogWriter struct {
*datautil.RingBuffer
}
MemoryLogWriter is a log writer which writes into a ring buffer in memory.
func (*MemoryLogWriter) Add ¶
func (lw *MemoryLogWriter) Add(m *LogMessage)
Add adds a new log message.
func (*MemoryLogWriter) Size ¶
func (lw *MemoryLogWriter) Size() int
Size returns the current log size.
func (*MemoryLogWriter) Slice ¶
func (lw *MemoryLogWriter) Slice() []*LogMessage
Slice returns the contents of the current log as a slice.
func (*MemoryLogWriter) String ¶
func (lw *MemoryLogWriter) String() string
String returns the current log as a string.