model

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2018 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(model *FlowModel)

Register registers the specified flow model

Types

type EvalResult

type EvalResult int
const (
	EVAL_FAIL EvalResult = iota
	EVAL_DONE
	EVAL_REPEAT
	EVAL_WAIT
)

type FlowBehavior

type FlowBehavior interface {

	// Start the flow instance.  Returning true indicates that the
	// flow can start and eval will be scheduled on the Root Task.
	// Return false indicates that the flow could not be started
	// at this time.
	Start(context FlowContext) (start bool, evalCode int)

	// Resume the flow instance.  Returning true indicates that the
	// flow can resume.  Return false indicates that the flow
	// could not be resumed at this time.
	Resume(context FlowContext) bool //<---

	// TasksDone is called when the RootTask is Done.
	TasksDone(context FlowContext, doneCode int)

	// Done is called when the flow is done.
	Done(context FlowContext) //maybe return something to the state server?
}

FlowBehavior is the execution behavior of the Flow.

type FlowContext

type FlowContext interface {
	// FlowDefinition returns the Flow definition associated with this context
	FlowDefinition() *definition.Definition

	//State gets the state of the Flow instance
	State() int

	//SetState sets the state of the Flow instance
	SetState(state int)
}

FlowContext is the execution context of the Flow when executing a Flow Behavior function

type FlowModel

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

FlowModel defines the execution Model for a Flow. It contains the execution behaviors for Flows and Tasks.

func Get

func Get(id string) *FlowModel

Get gets specified FlowModel

func New

func New(name string) *FlowModel

New creates a new FlowModel from the specified Behaviors

func Registered

func Registered() []*FlowModel

Registered gets all the registered flow models

func (*FlowModel) GetFlowBehavior

func (pm *FlowModel) GetFlowBehavior() FlowBehavior

GetFlowBehavior returns FlowBehavior of the FlowModel

func (*FlowModel) GetTaskBehavior

func (pm *FlowModel) GetTaskBehavior(id int) TaskBehavior

GetTaskBehavior returns TaskBehavior with the specified ID in he FlowModel

func (*FlowModel) Name

func (pm *FlowModel) Name() string

Name returns the name of the FlowModel

func (*FlowModel) RegisterFlowBehavior

func (pm *FlowModel) RegisterFlowBehavior(flowBehavior FlowBehavior)

RegisterFlowBehavior registers the specified FlowBehavior with the Model

func (*FlowModel) RegisterTaskBehavior

func (pm *FlowModel) RegisterTaskBehavior(id int, taskBehavior TaskBehavior)

RegisterTaskBehavior registers the specified TaskBehavior with the Model

type LinkInst

type LinkInst interface {

	// Link returns the Link associated with this Link Instance
	Link() *definition.Link

	// State gets the state of the Link instance
	State() int

	// SetState sets the state of the Link instance
	SetState(state int)
}

LinkInst is the instance of a link

type TaskBehavior

type TaskBehavior interface {

	// Enter determines if a Task is ready to be evaluated, returning true
	// indicates that the task is ready to be evaluated.
	Enter(context TaskContext, enterCode int) (eval bool, evalCode int)

	// Eval is called when a Task is being evaluated.  Returning true indicates
	// that the task is done.  If err is set, it indicates that the
	// behavior intends for the flow ErrorHandler to handle the error
	Eval(context TaskContext, evalCode int) (evalResult EvalResult, doneCode int, err error)

	// PostEval is called when a task that didn't complete during the Eval
	// needs to be notified.  Returning true indicates that the task is done.
	// If err is set, it indicates that the  behavior intends for the
	// flow ErrorHandler to handle the error
	PostEval(context TaskContext, evalCode int, data interface{}) (done bool, doneCode int, err error)

	// Done is called when Eval, PostEval or ChildDone return true, indicating
	// that the task is done.  This step is used to finalize the task and
	// determine the next set of tasks to be entered.  Returning true indicates
	// that the parent task should be notified.  Also returns the set of Tasks
	// that should be entered next.
	Done(context TaskContext, doneCode int) (notifyParent bool, childDoneCode int, taskEntries []*TaskEntry, err error)

	// Error is called when there is an issue executing Eval, it returns a boolean indicating
	// if it handled the error, otherwise the error is handled by the global error handler
	Error(context TaskContext) (handled bool, taskEntry *TaskEntry)

	// ChildDone is called when child task is Done and has indicated that its
	// parent should be notified.  Returning true indicates that the task
	// is done.
	ChildDone(context TaskContext, childTask *definition.Task, childDoneCode int) (done bool, doneCode int)
}

TaskBehavior is the execution behavior of a Task.

type TaskContext

type TaskContext interface {

	// State gets the state of the Task instance
	State() int

	// SetState sets the state of the Task instance
	SetState(state int)

	// Task returns the Task associated with this context
	Task() *definition.Task

	// FromInstLinks returns the instances of predecessor Links of the current
	// task.
	FromInstLinks() []LinkInst

	// ToInstLinks returns the instances of successor Links of the current
	// task.
	ToInstLinks() []LinkInst

	// EnterLeadingChildren enters the set of child Tasks that
	// do not have any incoming links.
	// todo: should we allow cross-boundary links?
	EnterLeadingChildren(enterCode int)

	// EnterChildren enters the set of child Tasks specified,
	// If single TaskEntry with nil Task is supplied,
	// all the child tasks are entered with the specified code.
	EnterChildren(taskEntries []*TaskEntry)

	// ChildTaskInsts gets all the instances of child tasks of the
	// current task
	ChildTaskInsts() (taskInsts []TaskInst, hasChildTasks bool)

	// EvalLink evaluates the specified link
	EvalLink(link *definition.Link) (bool, error)

	// HasActivity flag indicating if the task has an Activity
	HasActivity() bool

	// EvalActivity evaluates the Activity associated with the Task
	EvalActivity() (done bool, err error)

	// Failed marks the Activity as failed
	Failed(err error)

	GetSetting(setting string) (value interface{}, exists bool)

	AddWorkingData(attr *data.Attribute)

	UpdateWorkingData(key string, value interface{}) error

	GetWorkingData(key string) (*data.Attribute, bool)
}

TaskContext is the execution context of the Task when executing a Task Behavior function

type TaskEntry

type TaskEntry struct {
	Task      *definition.Task
	EnterCode int
}

TaskEntry is a struct used to specify what Task to enter and its corresponding enter code

type TaskInst

type TaskInst interface {

	// Task returns the Task associated with this Task Instance
	Task() *definition.Task

	// State gets the state of the Task instance
	State() int
}

Jump to

Keyboard shortcuts

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