private TypeDef BuildClusterType() => new TypeDef( "cluster", typeof(ClusterToken), (alias, nvs) => new ClusterToken(alias, (Lst <NamedValueToken>)nvs), 20, FuncSpec.Property("node-name", () => types.String), FuncSpec.Property("role", () => types.String), FuncSpec.Property("provider", () => types.String), FuncSpec.Property("connection", () => types.String), FuncSpec.Property("database", () => types.String), FuncSpec.Property("env", () => types.String), FuncSpec.Property("user-env", () => types.String), FuncSpec.Property("default", () => types.Bool) );
private TypeDef BuildRouterType() => new TypeDef( "router", typeof(ProcessToken), (_, nvs) => new ProcessToken((Lst <NamedValueToken>)nvs), 20, FuncSpec.Property("pid", () => types.ProcessId), FuncSpec.Property("flags", () => types.ProcessFlags), FuncSpec.Property("mailbox-size", () => types.Int), FuncSpec.Property("dispatch", () => types.DispatcherType), FuncSpec.Property("route", () => types.DispatcherType), FuncSpec.Property("workers", () => TypeDef.Array(() => processType)), FuncSpec.Property("worker-count", () => types.Int), FuncSpec.Property("worker-name", () => types.String), FuncSpec.Property("strategy", () => strategyType));
/// <summary> /// Automatically defined record-type constructor /// </summary> /// <param name="type"></param> /// <param name="ctor"></param> /// <param name="assembly"></param> /// <param name="name"></param> /// <param name="nodeName"></param> public TypeDef( Type type, Func <Option <string>, object, object> ctor, Types assembly, int order, string name = null, string nodeName = "" ) { if (type == null) { throw new ArgumentNullException(nameof(type)); } var info = type.GetTypeInfo(); Order = order; Ctor = ctor ?? ((_, x) => x); MapsTo = type; Name = name ?? MakeName(info.Name); BinaryOperators = LanguageExt.Map.empty <string, Func <ValueToken, ValueToken, ValueToken> >(); PrefixOperators = LanguageExt.Map.empty <string, Func <ValueToken, ValueToken> >(); PostfixOperators = LanguageExt.Map.empty <string, Func <ValueToken, ValueToken> >(); ConversionOperators = LanguageExt.Map.empty <string, Func <object, object> >(); GenericType = null; NodeName = nodeName; var props = from p in type.GetRuntimeProperties() where assembly.Exists(p.PropertyType) select FuncSpec.Property(MakeName(p.Name), () => assembly.Get(p.PropertyType)); var fields = from p in type.GetRuntimeFields() where assembly.Exists(p.FieldType) select FuncSpec.Property(MakeName(p.Name), () => assembly.Get(p.FieldType)); var methods = from m in type.GetRuntimeMethods() where m.IsStatic && assembly.Exists(m.ReturnType) && m.GetParameters().Map(p => p.ParameterType).ForAll(assembly.Exists) let ps = m.GetParameters().Map(p => new FieldSpec(p.Name, () => assembly.Get(p.ParameterType))).ToArray() select FuncSpec.Attrs(MakeName(m.Name), () => assembly.Get(m.ReturnType), locals => m.Invoke(null, locals.Values.ToArray()), ps); FuncSpecs = toArray(mconcat <MEnumerable <FuncSpec>, IEnumerable <FuncSpec> >(props, fields, methods)); ValueParser = BuildObjectParser(FuncSpecs).Memo(); }
TypeDef BuildStrategySpec(Types types, IEnumerable <FuncSpec> strategyFuncs) { TypeDef strategy = null; Func <Lst <NamedValueToken>, Lst <State <StrategyContext, Unit> > > compose = items => items.Map(x => (State <StrategyContext, Unit>)x.Value.Value); var oneForOne = FuncSpec.Property("one-for-one", () => strategy, () => strategy, value => Strategy.OneForOne((State <StrategyContext, Unit>)value)); var allForOne = FuncSpec.Property("all-for-one", () => strategy, () => strategy, value => Strategy.AllForOne((State <StrategyContext, Unit>)value)); var always = FuncSpec.Property("always", () => strategy, () => types.Directive, value => Strategy.Always((Directive)value)); var pause = FuncSpec.Property("pause", () => strategy, () => types.Time, value => Strategy.Pause((Time)value)); var retries1 = FuncSpec.Property("retries", () => strategy, () => types.Int, value => Strategy.Retries((int)value)); var retries2 = FuncSpec.Attrs( "retries", () => strategy, locals => Strategy.Retries((int)locals["count"], (Time)locals["duration"]), new FieldSpec("count", () => types.Int), new FieldSpec("duration", () => types.Time) ); var backoff1 = FuncSpec.Attrs( "backoff", () => strategy, locals => Strategy.Backoff((Time)locals["min"], (Time)locals["max"], (Time)locals["step"]), new FieldSpec("min", () => types.Time), new FieldSpec("max", () => types.Time), new FieldSpec("step", () => types.Time) ); var backoff2 = FuncSpec.Attrs( "backoff", () => strategy, locals => Strategy.Backoff((Time)locals["min"], (Time)locals["max"], (double)locals["scalar"]), new FieldSpec("min", () => types.Time), new FieldSpec("max", () => types.Time), new FieldSpec("scalar", () => types.Double) ); var backoff3 = FuncSpec.Property("backoff", () => strategy, () => types.Time, value => Strategy.Backoff((Time)value)); // match // | exception -> directive // | _ -> directive var match = FuncSpec.Special("match", () => strategy); // redirect when // | directive -> message-directive // | _ -> message-directive var redirect = FuncSpec.Special("redirect", () => strategy); strategy = new TypeDef( "strategy", typeof(State <StrategyContext, Unit>), (_, s) => Strategy.Compose(compose((Lst <NamedValueToken>)s).ToArray().ToArray()), 20, new[] { oneForOne, allForOne, always, pause, retries1, retries2, backoff1, backoff2, backoff3, match, redirect }.Append(strategyFuncs).ToArray() ); return(strategy); }