Menu

Example

Vitaliy Liptchinsky

Several examples on how to run a statelets code can be found in Program.fs in the Examples project.

In order to integrate external relations, a programmer needs to implement IContext interface. This interface contains three important methods:

type public IContext =
GetRelations - as an input parameter gets name of a relations and a list of initialized parameters. The method should return list of graph edges (records) that match the input parameters. If None is provided as input parameter, then the method should return all record for the given relation.

CreateRelation - triggers an external command, i.e., a BPMN process or web service call

SupportedRelations - returns names of all relations this context can return.

As a next step, a codefile should be parsed and interpreted. Once context is initialized, it should be wrapped in a RuntimeContext. RuntimeContext is necessary to deal with interproces coordination, also it provides some basic computational relations. For example:

let code = File.ReadAllText("usecase2.statelets")
let lexbuff = LexBuffer<char>.FromString(code)
let definitions = Parser.start Lexer.tokenize lexbuff

let context = new SimpleRuntimeContext(new MyCustomContext()) :> IContext
let runtime = new LanguageRuntime(definitions, context)

In order to launch certain statelets, one should use InterpretStatelet function:

runtime.InterpretStatelet(definitionOfSomeStatelet, parameters)

Currently multithreading and continous execution are not implemented, the time is descrete, i.e., execution is done step by step using the InterpretStateletsRound function.


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.