chaos

package module
v0.0.0-...-0ae699b Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

README

Chaos

chaos is a multiagent application Inspired by the jade library. https://en.wikipedia.org/wiki/Java_Agent_Development_Framework i try to build a POC to use the concurency model of Go and make the developement easier.

How to create an agent

a simple way to create an Agent without any behaviour

// main
func main() {
     neo := &chaos.Agent{
		Name:  "Neo",
		Setup: func(agent *chaos.Agent) {},
	}
	chaos.RegisterAgent(neo)
	chaos.Start()
}

Create an agent with Behaviour

for each agent a behaviour can be added in the setup method there are different type of beahviours

one shot behaviour

one shot behaviour have these signature func(agent *chaos.Agent) error and are added like this agent.AddOneShotBehaviour(...)

// you can declare an Action to later add as behaviour like this
func shootAction(agent *chaos.Agent) error {
	for i := 0; i < 5; i++ {
		fmt.Printf("[%v] Bang %v ... 🃏 \n", agent.Name, i)
	}
	return nil
}

func behaviourExample() {

	smith := &chaos.Agent{
		Name: "Smith",
		Setup: func(agent *chaos.Agent) {
			agent.AddOneShotBehaviour(shootAction)
		},
	}
	// register new created agent
	chaos.RegisterAgent(smith)
	// start agent
	chaos.Start()

}

Cylic behaviour

TODO: in progress

Waker Behabiour

TODO: in progress

Ticker Behaviour

TODO: in progress

Agent can send Message

TODO: in progress

Agents have global state

TODO: in progress

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAgent

func NewAgent(name string)

NewAgent create a new Simple Agent

func NewAgentWithSetup

func NewAgentWithSetup(name string, setUp setupFunc)

NewAgentWithSetup create a new Agent with a setUp function. the setup function will be executed before starting the agent

func NewAgentWithSetupAndTakeDown

func NewAgentWithSetupAndTakeDown(name string, setUp setupFunc, takeDown takeDownFunc)

NewAgentWithSetupAndTakeDown create a new Agent with a setUp and Takedown function. the setup function will be executed before starting the agent the takeDown function will be executed after all agent behaviour. before agent end of life

func RegisterAgent

func RegisterAgent(a *Agent)

RegisterAgent register a new Agent

func RegisterAgentAndScale

func RegisterAgentAndScale(a *Agent, scale int)

RegisterAgentAndScale register a new Agent and scale

func RegisterAndRunAgent

func RegisterAndRunAgent(wg *sync.WaitGroup, agent *Agent)

RegisterAndRunAgent ...

func Start

func Start()

Start start all agents

func StartAgent

func StartAgent(wg *sync.WaitGroup, agent *Agent)

StartAgent ...

func StopAgent

func StopAgent(agentID string)

StopAgent ..

Types

type Agent

type Agent struct {
	Name     string
	ID       string
	Setup    setupFunc
	TakeDown takeDownFunc
	// contains filtered or unexported fields
}

Agent ...

func (*Agent) AddCyclicBehaviour

func (a *Agent) AddCyclicBehaviour(b Behaviour)

AddCyclicBehaviour add new cyclic behaviour to the agent cyclic behaviours never complete and run forever

func (*Agent) AddOneShotBehaviour

func (a *Agent) AddOneShotBehaviour(b Behaviour)

AddOneShotBehaviour add new behaviour to the agent

func (*Agent) AddTickerBehaviour

func (a *Agent) AddTickerBehaviour(b DelayedBehaviour, tickerSecond int)

AddTickerBehaviour add new ticker behaviour to the agent waker behaviours execute repetitively after a given period of time

func (*Agent) AddWakerBehaviour

func (a *Agent) AddWakerBehaviour(b DelayedBehaviour, timeoutSecond int)

AddWakerBehaviour add new waker behaviour to the agent waker behaviours execute after a given timeout

func (*Agent) GetData

func (a *Agent) GetData(key string) string

GetData get value for the given key

func (*Agent) OnMessage

func (a *Agent) OnMessage(om func(message.Message))

OnMessage add a callback function to receive message send to this agent

func (*Agent) Send

func (a *Agent) Send(msg message.Message)

Send send message to another agent

func (*Agent) SendMessage

func (a *Agent) SendMessage(receiver string, msgBody string)

SendMessage send Inform Message

func (*Agent) SetData

func (a *Agent) SetData(key string, data string)

SetData save key value pair

type AgentStore

type AgentStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

AgentStore ...

func GetAgentStoreInstance

func GetAgentStoreInstance() *AgentStore

GetAgentStoreInstance ...

func (*AgentStore) Add

func (s *AgentStore) Add(a *Agent)

Add ...

func (*AgentStore) Count

func (s *AgentStore) Count() int

Count ...

func (*AgentStore) Get

func (s *AgentStore) Get(aid string) *Agent

Get ...

func (*AgentStore) List

func (s *AgentStore) List() map[string]*Agent

List ...

type Behaviour

type Behaviour func(*Agent) error

Behaviour ...

type DelayedBehaviour

type DelayedBehaviour func(*Agent, int) error

DelayedBehaviour ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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