engine

package
v1.5.7 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: BSD-3-Clause Imports: 12 Imported by: 14

Documentation

Index

Constants

View Source
const (
	SortModel       = 1
	ConcurrentModel = 2
	MixModel        = 3
	InverseMixModel = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Gengine

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

func NewGengine

func NewGengine() *Gengine

func (*Gengine) Execute

func (g *Gengine) Execute(rb *builder.RuleBuilder, b bool) error

* sort execute model

when b is true it means when there are many rules, if one rule execute error,continue to execute rules after the occur error rule

func (*Gengine) ExecuteConcurrent

func (g *Gengine) ExecuteConcurrent(rb *builder.RuleBuilder) error

concurrent execute model in this mode, it will not consider the priority and not consider err control

func (*Gengine) ExecuteDAGModel added in v1.5.5

func (g *Gengine) ExecuteDAGModel(rb *builder.RuleBuilder, dag [][]string) error

DAG model

func (*Gengine) ExecuteInverseMixModel

func (g *Gengine) ExecuteInverseMixModel(rb *builder.RuleBuilder) error

inverse mix model

func (*Gengine) ExecuteMixModel

func (g *Gengine) ExecuteMixModel(rb *builder.RuleBuilder) error

mix model to execute rules

in this mode, it will not consider the priority,and it also concurrently to execute rules first to execute the most high priority rule,then concurrently to execute last rules without consider the priority

func (*Gengine) ExecuteMixModelWithStopTagDirect

func (g *Gengine) ExecuteMixModelWithStopTagDirect(rb *builder.RuleBuilder, sTag *Stag) error

*

mix execute model

base type :golang translate value not base type: golang translate pointer

if stopTag become true,it will not continue to execute stopTag is a name given by user, and user can use it to control rules execute behavior in rules, it can improve performance

it used in this scene: where the first rule execute finished, you don't want to execute to the last rules, you can use sTag to control it out of gengine

func (*Gengine) ExecuteNConcurrentMConcurrent

func (g *Gengine) ExecuteNConcurrentMConcurrent(nConcurrent, mConcurrent int, rb *builder.RuleBuilder, b bool) error
  1. first n piece rules to concurrent execute based without priority
  2. bool b means: if the first stage executed error, whether continue to execute the next concurrent stage if b == true, means continue, if false, means stop and return
  3. then m piece rules to concurrent execute based without priority

func (*Gengine) ExecuteNConcurrentMSort

func (g *Gengine) ExecuteNConcurrentMSort(nConcurrent, mSort int, rb *builder.RuleBuilder, b bool) error
  1. first n piece rules to concurrent execute based without priority
  2. bool b means: after concurrent execute stage,if a rule execute error whether continue to execute the last all rules, if b == true, means continue, if false, means stop and return
  3. then m piece rules to sort execute based on priority

func (*Gengine) ExecuteNSortMConcurrent

func (g *Gengine) ExecuteNSortMConcurrent(nSort, mConcurrent int, rb *builder.RuleBuilder, b bool) error

1.first n piece rules to sort execute based on priority 2.bool b means: when in sort execute stage,if a rule execute error whether continue to execute the last all rules,

if b == true, means continue, if false, means stop and return

3.then m piece rules to concurrent execute based without priority

func (*Gengine) ExecuteSelectedNConcurrentMConcurrent

func (g *Gengine) ExecuteSelectedNConcurrentMConcurrent(nConcurrent, mConcurrent int, rb *builder.RuleBuilder, b bool, names []string) error

based on selected rules

  1. first n piece rules to concurrent execute based without priority
  2. bool b means: if the first stage executed error, whether continue to execute the next concurrent stage if b == true, means continue, if false, means stop and return
  3. then m piece rules to concurrent execute based without priority

func (*Gengine) ExecuteSelectedNConcurrentMSort

func (g *Gengine) ExecuteSelectedNConcurrentMSort(nConcurrent, mSort int, rb *builder.RuleBuilder, b bool, names []string) error
  1. based on selected rules
  2. first n piece rules to concurrent execute based without priority
  3. bool b means: after concurrent execute stage,if a rule execute error whether continue to execute the last all rules, if b == true, means continue, if false, means stop and return
  4. then m piece rules to sort execute based on priority

func (*Gengine) ExecuteSelectedNSortMConcurrent

func (g *Gengine) ExecuteSelectedNSortMConcurrent(nSort, mConcurrent int, rb *builder.RuleBuilder, b bool, names []string) error

0.based on selected rules 1.first n piece rules to sort execute based on priority 2.bool b means: when in sort execute stage,if a rule execute error whether continue to execute the last all rules,

if b == true, means continue, if false, means stop and return

3.then m piece rules to concurrent execute based without priority

func (*Gengine) ExecuteSelectedRules

func (g *Gengine) ExecuteSelectedRules(rb *builder.RuleBuilder, names []string) error

* user can choose specified name rules to run with sort, and it will continue to execute the last rules,even if there rule execute error

func (*Gengine) ExecuteSelectedRulesConcurrent

func (g *Gengine) ExecuteSelectedRulesConcurrent(rb *builder.RuleBuilder, names []string) error

* user can choose specified name rules to concurrent run

func (*Gengine) ExecuteSelectedRulesInverseMixModel

func (g *Gengine) ExecuteSelectedRulesInverseMixModel(rb *builder.RuleBuilder, names []string) error

inverse mix model with user selected

func (*Gengine) ExecuteSelectedRulesMixModel

func (g *Gengine) ExecuteSelectedRulesMixModel(rb *builder.RuleBuilder, names []string) error

* user can choose specified name rules to run with mix model

func (*Gengine) ExecuteSelectedRulesWithControl

func (g *Gengine) ExecuteSelectedRulesWithControl(rb *builder.RuleBuilder, b bool, names []string) error

* user can choose specified name rules to run with sort b bool:control whether continue to execute last rules ,when a rule execute error; if b == true ,the func is same to ExecuteSelectedRules

func (*Gengine) ExecuteSelectedRulesWithControlAndStopTag

func (g *Gengine) ExecuteSelectedRulesWithControlAndStopTag(rb *builder.RuleBuilder, b bool, sTag *Stag, names []string) error

* user can choose specified name rules to run with sort b bool:control whether continue to execute last rules ,when a rule execute error; if b == true ,the func is same to ExecuteSelectedRules

func (*Gengine) ExecuteSelectedRulesWithControlAndStopTagAsGivenSortedName added in v1.5.6

func (g *Gengine) ExecuteSelectedRulesWithControlAndStopTagAsGivenSortedName(rb *builder.RuleBuilder, b bool, sTag *Stag, sortedNames []string) error

* user can choose specified name rules to run with given sorted name b bool:control whether continue to execute last rules ,when a rule execute error; if b == true ,the func is same to ExecuteSelectedRules

gengine won't sort the rules by the salience, and the executed order will based on the user given sorted names

func (*Gengine) ExecuteSelectedRulesWithControlAsGivenSortedName added in v1.5.6

func (g *Gengine) ExecuteSelectedRulesWithControlAsGivenSortedName(rb *builder.RuleBuilder, b bool, sortedNames []string) error

* user can choose specified name rules to run with given sorted name b bool:control whether continue to execute last rules ,when a rule execute error; if b == true ,the func is same to ExecuteSelectedRules

gengine won't sort the rules by the salience, and the executed order will based on the user given sorted names

func (*Gengine) ExecuteWithStopTagDirect

func (g *Gengine) ExecuteWithStopTagDirect(rb *builder.RuleBuilder, b bool, sTag *Stag) error

* sort execute model

when b is true it means when there are many rules, if one rule execute error,continue to execute rules after the occur error rule; if stopTag become true,it will not continue to execute

sTag is a struct given by user, and user can use it to control rules execute behavior in rules, it can improve performance

it used in this scene: where some high priority rules execute finished, you don't want to execute to the last rules, you can use sTag to control it out of gengine

func (*Gengine) GetRulesResultMap

func (g *Gengine) GetRulesResultMap() (map[string]interface{}, error)

type GenginePool

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

when you use NewGenginePool, you just think of it as the connection pool of mysql, the higher QPS you want to support, the more resource you need to give

func NewGenginePool

func NewGenginePool(poolMinLen, poolMaxLen int64, em int, rulesStr string, apiOuter map[string]interface{}) (*GenginePool, error)

best practise: when there has cost-time operate in your rule or you want to support high concurrency(> 200000QPS) , please set poolMinLen bigger Appropriately when you use NewGenginePool,you just think of it as the connection pool of mysql, the higher QPS you want to support, the more resource you need to give

func (*GenginePool) ClearPoolRules

func (gp *GenginePool) ClearPoolRules()

clear all rules in engine in pool

func (*GenginePool) Execute

func (gp *GenginePool) Execute(data map[string]interface{}, b bool) (error, map[string]interface{})

see gengine.go Execute

func (*GenginePool) ExecuteConcurrent

func (gp *GenginePool) ExecuteConcurrent(data map[string]interface{}) (error, map[string]interface{})

see gengine.go ExecuteConcurrent

func (*GenginePool) ExecuteDAGModel added in v1.5.5

func (gp *GenginePool) ExecuteDAGModel(dag [][]string, data map[string]interface{}) (error, map[string]interface{})

see gengine.go ExecuteDAGModel

func (*GenginePool) ExecuteInverseMixModel

func (gp *GenginePool) ExecuteInverseMixModel(data map[string]interface{}) (error, map[string]interface{})

//see gengine.go ExecuteInverseMixModel

func (*GenginePool) ExecuteMixModel

func (gp *GenginePool) ExecuteMixModel(data map[string]interface{}) (error, map[string]interface{})

see gengine.go ExecuteMixModel

func (*GenginePool) ExecuteMixModelWithStopTagDirect

func (gp *GenginePool) ExecuteMixModelWithStopTagDirect(data map[string]interface{}, sTag *Stag) (error, map[string]interface{})

see gengine.go ExecuteMixModelWithStopTagDirect

func (*GenginePool) ExecuteNConcurrentMConcurrent

func (gp *GenginePool) ExecuteNConcurrentMConcurrent(nSort, mConcurrent int, b bool, data map[string]interface{}) (error, map[string]interface{})

see gengine.go ExecuteNConcurrentMConcurrent

func (*GenginePool) ExecuteNConcurrentMSort

func (gp *GenginePool) ExecuteNConcurrentMSort(nSort, mConcurrent int, b bool, data map[string]interface{}) (error, map[string]interface{})

see gengine.go ExecuteNConcurrentMSort

func (*GenginePool) ExecuteNSortMConcurrent

func (gp *GenginePool) ExecuteNSortMConcurrent(nSort, mConcurrent int, b bool, data map[string]interface{}) (error, map[string]interface{})

see gengine.go ExecuteNSortMConcurrent

func (*GenginePool) ExecuteRulesWithMultiInputWithSpecifiedEM

func (gp *GenginePool) ExecuteRulesWithMultiInputWithSpecifiedEM(data map[string]interface{}) (error, map[string]interface{})

* user can input more data to use in engine it is no difference with ExecuteRules, you just can inject more data use this api

the return map[string]interface{} collection each rule returned result

func (*GenginePool) ExecuteRulesWithSpecifiedEM

func (gp *GenginePool) ExecuteRulesWithSpecifiedEM(reqName string, req interface{}, respName string, resp interface{}) (error, map[string]interface{})

execute rules as the user set execute model when init or update req, it is better to be ptr, or you will not get changed data resp, it is better to be ptr, or you will not get changed data the return map[string]interface{} collection each rule returned result

func (*GenginePool) ExecuteSelectedNConcurrentMConcurrent

func (gp *GenginePool) ExecuteSelectedNConcurrentMConcurrent(nSort, mConcurrent int, b bool, names []string, data map[string]interface{}) (error, map[string]interface{})

see gengine.go ExecuteSelectedNConcurrentMConcurrent

func (*GenginePool) ExecuteSelectedNConcurrentMSort

func (gp *GenginePool) ExecuteSelectedNConcurrentMSort(nSort, mConcurrent int, b bool, names []string, data map[string]interface{}) (error, map[string]interface{})

see gengine.go ExecuteSelectedNConcurrentMSort

func (*GenginePool) ExecuteSelectedNSortMConcurrent

func (gp *GenginePool) ExecuteSelectedNSortMConcurrent(nSort, mConcurrent int, b bool, names []string, data map[string]interface{}) (error, map[string]interface{})

see gengine.go ExecuteSelectedNSortMConcurrent

func (*GenginePool) ExecuteSelectedRules

func (gp *GenginePool) ExecuteSelectedRules(data map[string]interface{}, names []string) (error, map[string]interface{})

see gengine.go ExecuteSelectedRules

func (*GenginePool) ExecuteSelectedRulesConcurrent

func (gp *GenginePool) ExecuteSelectedRulesConcurrent(data map[string]interface{}, names []string) (error, map[string]interface{})

see gengine.go ExecuteSelectedRulesConcurrent

func (*GenginePool) ExecuteSelectedRulesInverseMixModel

func (gp *GenginePool) ExecuteSelectedRulesInverseMixModel(data map[string]interface{}, names []string) (error, map[string]interface{})

see gengine.go ExecuteSelectedRulesInverseMixModel

func (*GenginePool) ExecuteSelectedRulesMixModel

func (gp *GenginePool) ExecuteSelectedRulesMixModel(data map[string]interface{}, names []string) (error, map[string]interface{})

see gengine.go ExecuteSelectedRulesMixModel

func (*GenginePool) ExecuteSelectedRulesWithControl

func (gp *GenginePool) ExecuteSelectedRulesWithControl(data map[string]interface{}, b bool, names []string) (error, map[string]interface{})

see gengine.go ExecuteSelectedRulesWithControl

func (*GenginePool) ExecuteSelectedRulesWithControlAndStopTag

func (gp *GenginePool) ExecuteSelectedRulesWithControlAndStopTag(data map[string]interface{}, b bool, sTag *Stag, names []string) (error, map[string]interface{})

see gengine.go ExecuteSelectedRulesWithControlAndStopTag

func (*GenginePool) ExecuteSelectedRulesWithControlAndStopTagAsGivenSortedName added in v1.5.6

func (gp *GenginePool) ExecuteSelectedRulesWithControlAndStopTagAsGivenSortedName(data map[string]interface{}, b bool, sTag *Stag, sortedNames []string) (error, map[string]interface{})

see gengine.go ExecuteSelectedRulesWithControlAndStopTagAsGivenSortedName

func (*GenginePool) ExecuteSelectedRulesWithControlAsGivenSortedName added in v1.5.6

func (gp *GenginePool) ExecuteSelectedRulesWithControlAsGivenSortedName(data map[string]interface{}, b bool, sortedNames []string) (error, map[string]interface{})

see gengine.go ExecuteSelectedRulesWithControlAsGivenSortedName

func (*GenginePool) ExecuteSelectedWithSpecifiedEM

func (gp *GenginePool) ExecuteSelectedWithSpecifiedEM(data map[string]interface{}, names []string) (error, map[string]interface{})

** this make user could use exemodel to control the select-exemodel

the return map[string]interface{} collection each rule returned result

func (*GenginePool) ExecuteWithStopTagDirect

func (gp *GenginePool) ExecuteWithStopTagDirect(data map[string]interface{}, b bool, sTag *Stag) (error, map[string]interface{})

se gengine.go ExecuteWithStopTagDirect

func (*GenginePool) GetExecModel

func (gp *GenginePool) GetExecModel() int

get the execute model the user set

func (*GenginePool) GetRuleDesc

func (gp *GenginePool) GetRuleDesc(ruleName string) (string, error)

get the rule's description

func (*GenginePool) GetRuleSalience

func (gp *GenginePool) GetRuleSalience(ruleName string) (int64, error)

get the rule's salience

func (*GenginePool) GetRulesNumber

func (gp *GenginePool) GetRulesNumber() int

count how many different rules in pool

func (*GenginePool) IsExist

func (gp *GenginePool) IsExist(ruleNames []string) []bool

check the rule whether exist

func (*GenginePool) PluginLoader

func (gp *GenginePool) PluginLoader(absolutePathOfSO string) error

plugin_exportName_apiName.so _ is a separator plugin is prefix exportName is user export in plugin file apiName is plugin used in gengine

func (*GenginePool) RemoveRules

func (gp *GenginePool) RemoveRules(ruleNames []string) error

remove rules

func (*GenginePool) SetExecModel

func (gp *GenginePool) SetExecModel(execModel int) error

1 sort model 2 concurrent model 3 mix model 4 inverse mix model

func (*GenginePool) UpdatePooledRules

func (gp *GenginePool) UpdatePooledRules(ruleStr string) error

sync method update the all rules in all engine in the pool update success: return nil update failed: return error this is very different from connection pool, connection pool just need to init once while gengine pool need to update the rules whenever the user want to init

func (*GenginePool) UpdatePooledRulesIncremental

func (gp *GenginePool) UpdatePooledRulesIncremental(ruleStr string) error

sync method incremental update the rules in all engine in the pool incremental update success: return nil incremental update failed: return error if a rule already exists, this method will use the new rule to replace the old one if a rule doesn't exist, this method will add the new rule to the existed rules list see: func (builder *RuleBuilder)BuildRuleWithIncremental(ruleString string) in rule_builder.go

type Stag

type Stag struct {
	StopTag bool
}

Jump to

Keyboard shortcuts

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