public Type GetMailboxType(Props props, Config dispatcherConfig) { if (!string.IsNullOrEmpty(props.Mailbox)) { return FromConfig(props.Mailbox); } var actortype = props.Type; var interfaces = actortype.GetInterfaces() .Where(i => i.IsGenericType) .Where(i => i.GetGenericTypeDefinition() == typeof (RequiresMessageQueue<>)) .Select(i => i.GetGenericArguments().First()) .ToList(); if (interfaces.Count > 0) { var config = _requirementsMapping[interfaces.First()]; var mailbox = config.GetString("mailbox-type"); var mailboxType = Type.GetType(mailbox); return mailboxType; } return FromConfig(DefaultMailboxId); }
public RoutedActorCell(ActorSystem system, InternalActorRef supervisor, Props routerProps, Props routeeProps, ActorPath path, Mailbox mailbox) : base(system, supervisor, routerProps, path, mailbox) { RouteeProps = routeeProps; routerConfig = routerProps.RouterConfig; Router = routerConfig.CreateRouter(system); routerConfig.Match() .With<Pool>(r => { var routees = new List<Routee>(); for (int i = 0; i < r.NrOfInstances; i++) { var routee = this.ActorOf(RouteeProps); routees.Add(new ActorRefRoutee(routee)); } AddRoutees(routees.ToArray()); }) .With<Group>(r => { var routees = routerConfig.GetRoutees(this).ToArray(); AddRoutees(routees); }); Self = new RoutedActorRef(path, this); }
public RootGuardianActorRef(ActorSystemImpl system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, //TODO: switch from Func<Mailbox> createMailbox to MailboxType mailboxType IInternalActorRef supervisor, ActorPath path, IInternalActorRef deadLetters, IReadOnlyDictionary<string, IInternalActorRef> extraNames) : base(system,props,dispatcher,createMailbox,supervisor,path) { _deadLetters = deadLetters; _extraNames = extraNames; }
/// <summary> /// Initializes a new instance of the <see cref="DaemonMsgCreate" /> class. /// </summary> /// <param name="props">The props.</param> /// <param name="deploy">The deploy.</param> /// <param name="path">The path.</param> /// <param name="supervisor">The supervisor.</param> public DaemonMsgCreate(Props props, Deploy deploy, string path, IActorRef supervisor) { Props = props; Deploy = deploy; Path = path; Supervisor = supervisor; }
public ActorCell(ActorSystemImpl system, InternalActorRef self, Props props, MessageDispatcher dispatcher, InternalActorRef parent) { _self = self; _props = props; _systemImpl = system; Parent = parent; Dispatcher = dispatcher; }
public PlayerActor(string name, Props propsForUserInteracting, IActorRef reader) { _reader = reader; _name = name; _playerUserInterface = Context.ActorOf(propsForUserInteracting, "ui"); _reader.Tell(_playerUserInterface); Become(Unregistered); }
public void Setup(BenchmarkContext context) { _selectionOpCounter = context.GetCounter(ActorSelectionCounterName); System = ActorSystem.Create("MailboxThroughputSpecBase" + Counter.GetAndIncrement()); _receiver = System.ActorOf(Props.Create(() => new BenchmarkActor(_selectionOpCounter, NumberOfMessages, _resetEvent))); _receiverActorPath = _receiver.Path; _oneMessageBenchmarkProps = Props.Create(() => new BenchmarkActor(_selectionOpCounter, 1, _resetEvent)); }
public IndexedProjectionStreamReader(IEventStoreReader reader, PersistedEventFactory factory) { Argument.Requires(reader != null, nameof(reader)); Argument.Requires(factory != null, nameof(factory)); _workerProps = Props.Create<ReadIndexedProjectionStreamWorker>(reader, factory); Receive<ReadIndexedProjectionStreamRequest>(r => HandleRequest(r)); }
public RepointableActorRef(ActorSystemImpl system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, IInternalActorRef supervisor, ActorPath path) { _system = system; _props = props; _dispatcher = dispatcher; _createMailbox = createMailbox; _supervisor = supervisor; _path = path; }
public static Props CreateProps(ProjectionStreamQuery query, IActorRef reader, IActorRef writer, GlobalOptions options, Props replayWorkerProps = null) { Argument.RequiresNotNull(query, nameof(query)); Argument.RequiresNotNull(reader, nameof(reader)); Argument.RequiresNotNull(writer, nameof(writer)); Argument.RequiresNotNull(options, nameof(options)); return Props.Create<ProjectionStream>(query, reader, writer, options, replayWorkerProps); }
public RepointableActorRef(ActorSystemImpl system, Props props, MessageDispatcher dispatcher, MailboxType mailboxType, IInternalActorRef supervisor, ActorPath path) { System = system; Props = props; Dispatcher = dispatcher; MailboxType = mailboxType; Supervisor = supervisor; _path = path; }
public ConsoleGuardianActor() { _reader = Context.ActorOf(Props.Create(() => new ConsoleReaderActor()), "reader"); _consoleUi = Props.Create(() => new ConsoleActor()); Receive<Message.CreatePlayer>(message => { Context.ActorOf(Props.Create(() => new PlayerActor(message.Name, _consoleUi, _reader)), (++_counter).ToString()); }); }
public EventStoreReader(IEventStore store, IPersistedEventFactory factory, GlobalOptions options) { _readProps = ReadWorker.CreateProps(store, factory); _readStreamProps = ReadStreamWorker.CreateProps(store, factory); _readIndexedProjectionProps = ReadIndexedProjectionStreamWorker.CreateProps(store, factory); _readProjectionCheckpointProps = ReadProjectionCheckpointWorker.CreateProps(store); _readHighestGlobalSequenceProps = ReadHighestGlobalSequenceWorker.CreateProps(store); Ready(); }
/// <summary> /// Inheritors should only call this constructor /// </summary> internal protected LocalActorRef(ActorSystem system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, IInternalActorRef supervisor, ActorPath path, Func<LocalActorRef, ActorCell> createActorCell) //TODO: switch from Func<Mailbox> createMailbox to MailboxType mailboxType { _system = system; _props = props; _dispatcher = dispatcher; _createMailbox = createMailbox; _supervisor = supervisor; _path = path; _cell = createActorCell(this); }
// test only public EventStoreReader(Props readProps, Props readStreamProps, Props readIndexedProjectionProps, Props readProjectionCheckpointProps, Props readHighestGlobalSequenceProps, GlobalOptions options) { _readProps = readProps; _readStreamProps = readStreamProps; _readIndexedProjectionProps = readIndexedProjectionProps; _readProjectionCheckpointProps = readProjectionCheckpointProps; _readHighestGlobalSequenceProps = readHighestGlobalSequenceProps; Ready(); }
public virtual AgentControllerInterface createAgent(object agentInfo) { if (agentInfo is Props) { return this.createAgent((Props) agentInfo); } Props agentProps = new Props(); agentProps.setProperty("classname", agentInfo.ToString()); return this.createAgent(agentProps); }
/// <summary> /// Initializes a new instance of the <see cref="RemoteActorRef"/> class. /// </summary> /// <param name="remote">The remote.</param> /// <param name="localAddressToUse">The local address to use.</param> /// <param name="path">The path.</param> /// <param name="parent">The parent.</param> /// <param name="props">The props.</param> /// <param name="deploy">The deploy.</param> internal RemoteActorRef(RemoteTransport remote, Address localAddressToUse, ActorPath path, InternalActorRef parent, Props props, Deploy deploy) { Remote = remote; LocalAddressToUse = localAddressToUse; Path = path; _parent = parent; _props = props; _deploy = deploy; }
//This mimics what's done in Akka`s construction of an LocalActorRef. //The actorCell is created in the overridable newActorCell() during creation of the instance. //Since we don't want calls to virtual members in C# we must supply it. // //This is the code from Akka: // private[akka] class LocalActorRef private[akka] ( // _system: ActorSystemImpl, // _props: Props, // _dispatcher: MessageDispatcher, // _mailboxType: MailboxType, // _supervisor: InternalActorRef, // override val path: ActorPath) extends ActorRefWithCell with LocalRef { // private val actorCell: ActorCell = newActorCell(_system, this, _props, _dispatcher, _supervisor) // actorCell.init(sendSupervise = true, _mailboxType) // ... // } public LocalActorRef(ActorSystemImpl system, Props props, MessageDispatcher dispatcher, Func<Mailbox> createMailbox, IInternalActorRef supervisor, ActorPath path) //TODO: switch from Func<Mailbox> createMailbox to MailboxType mailboxType : this(system, props, dispatcher, createMailbox, supervisor, path, self => { var cell= new ActorCell(system, self, props, dispatcher, supervisor); cell.Init(sendSupervise: true, createMailbox: createMailbox); return cell; }) { //Intentionally left blank }
public ResizablePoolCell(ActorSystemImpl system, IInternalActorRef self, Props routerProps, MessageDispatcher dispatcher, Props routeeProps, IInternalActorRef supervisor, Pool pool) : base(system,self, routerProps,dispatcher, routeeProps, supervisor) { if (pool.Resizer == null) throw new ArgumentException("RouterConfig must be a Pool with defined resizer"); resizer = pool.Resizer; _routerProps = routerProps; _pool = pool; _resizeCounter = new AtomicCounterLong(0); _resizeInProgress = new AtomicBoolean(); }
public ResizablePoolCell(ActorSystem system, InternalActorRef supervisor, Props routerProps, Props routeeProps, ActorPath path, Mailbox mailbox, Pool pool) : base(system, supervisor, routerProps, routeeProps, path, mailbox) { if (pool.Resizer == null) throw new ArgumentException("RouterConfig must be a Pool with defined resizer"); resizer = pool.Resizer; this._pool = pool; this._resizeCounter = 0; this._resizeInProgress = ResizeInProgressState.False; }
/// <summary> /// Initializes a new instance of the <see cref="BackoffSupervisor"/> class. /// </summary> /// <exception cref="ArgumentException"> /// This exception is thrown if the given <paramref name="minBackoff"/> is negative or greater than <paramref name="maxBackoff"/>. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// This exception is thrown if the given <paramref name="randomFactor"/> isn't between 0.0 and 1.0. /// </exception> public BackoffSupervisor(Props childProps, string childName, TimeSpan minBackoff, TimeSpan maxBackoff, double randomFactor) { if (minBackoff <= TimeSpan.Zero) throw new ArgumentException("MinBackoff must be greater than 0", nameof(minBackoff)); if (maxBackoff < minBackoff) throw new ArgumentException("MaxBackoff must be greater than MinBackoff", nameof(maxBackoff)); if (randomFactor < 0.0 || randomFactor > 1.0) throw new ArgumentOutOfRangeException(nameof(randomFactor), "RandomFactor must be between 0.0 and 1.0"); _childProps = childProps; _childName = childName; _minBackoff = minBackoff; _maxBackoff = maxBackoff; _randomFactor = randomFactor; }
public RoutedActorCell( ActorSystemImpl system, IInternalActorRef self, Props routerProps, MessageDispatcher dispatcher, Props routeeProps, IInternalActorRef supervisor) : base(system, self, routerProps, dispatcher, supervisor) { RouteeProps = routeeProps; RouterConfig = routerProps.RouterConfig; Router = null; }
private List<Query> ProcessArguments(ArrayList args, out Props props) { int capacity = (args != null) ? args.Count : 0; List<Query> list = new List<Query>(capacity); props = Props.None; for (int i = 0; i < capacity; i++) { Props props2; list.Add(this.ProcessNode((AstNode) args[i], Flags.None, out props2)); props |= props2; } return list; }
public RoutedActorRef( ActorSystemImpl system, Props routerProps, MessageDispatcher routerDispatcher, MailboxType routerMailbox, Props routeeProps, IInternalActorRef supervisor, ActorPath path) : base(system, routerProps, routerDispatcher, routerMailbox, supervisor, path) { _routeeProps = routeeProps; routerProps.RouterConfig.VerifyConfig(path); }
public Start(string typeName, Props entityProps, ClusterShardingSettings settings, IdExtractor idIdExtractor, ShardResolver shardResolver, IShardAllocationStrategy allocationStrategy, object handOffStopMessage) { if (string.IsNullOrEmpty(typeName)) throw new ArgumentNullException("typeName", "ClusterSharding start requires type name to be provided"); if (entityProps == null) throw new ArgumentNullException("entityProps", string.Format("ClusterSharding start requires Props for [{0}] to be provided", typeName)); TypeName = typeName; EntityProps = entityProps; Settings = settings; IdExtractor = idIdExtractor; ShardResolver = shardResolver; AllocationStrategy = allocationStrategy; HandOffStopMessage = handOffStopMessage; }
protected internal virtual AgentControllerInterface createAgent(Props agentProps) { AgentController controller = null; string classname = agentProps.getString("classname"); if (classname.Length > 0) { if (classname.Equals("com.neokernel.xml.XMLStartupAgent")) { classname = "Feng.NeoKernel.nk.LicenseFreeXMLStartupAgent"; } if (!classname.Equals("com.neokernel.xml.XMLStartupAgent") && !classname.Equals("com.neokernel.nk.Trmntr")) { this.println("Creating agent " + classname); } try { AgentInterface agent = null; IClassFactoryInterface defaultClassFactory = (IClassFactoryInterface) agentProps.getProperty("class_factory"); if (defaultClassFactory == null) { defaultClassFactory = NK.DefaultClassFactory; } agent = (AgentInterface) defaultClassFactory.createInstance(classname); Type type = agent.GetType(); if (!agentProps.hasProperty("name")) { string fullName = type.FullName; int num = fullName.LastIndexOf('.'); if (num > 0) { fullName = fullName.Substring(num + 1); } agentProps.setProperty("name", fullName); } agentProps.setDefault("agent_id", this.NextAgentID); agent.Props = agentProps; controller = new AgentController(agent); } catch (ArgumentException exception) { this.error("Could not create Agent: " + classname, exception); } catch (ClassFactoryException exception2) { this.error("Could not create Agent: " + classname, exception2); } } return controller; }
public void Props_created_with_null_type_must_throw() { Type missingType = null; object[] args = new object[0]; var argsEnumerable = Enumerable.Empty<object>(); var defaultStrategy = SupervisorStrategy.DefaultStrategy; var defaultDeploy = Deploy.Local; Props p = null; Assert.Throws<ArgumentNullException>("type", () => p = new Props(missingType, args)); Assert.Throws<ArgumentNullException>("type", () => p = new Props(missingType)); Assert.Throws<ArgumentNullException>("type", () => p = new Props(missingType, defaultStrategy, argsEnumerable)); Assert.Throws<ArgumentNullException>("type", () => p = new Props(missingType, defaultStrategy, args)); Assert.Throws<ArgumentNullException>("type", () => p = new Props(defaultDeploy, missingType, argsEnumerable)); Assert.Throws<ArgumentNullException>("type", () => p = Props.Create(missingType, args)); }
public override InternalActorRef ActorOf(ActorSystem system, Props props, InternalActorRef supervisor, ActorPath path) { Mailbox mailbox = System.Mailboxes.FromConfig(props.Mailbox); Deploy configDeploy = System.Provider.Deployer.Lookup(path); var deploy = configDeploy ?? props.Deploy ?? Deploy.None; if (deploy.Mailbox != null) props = props.WithMailbox(deploy.Mailbox); if (deploy.Dispatcher != null) props = props.WithDispatcher(deploy.Dispatcher); if (deploy.Scope is RemoteScope) { } //If this actor is a Router if (!(props.RouterConfig is NoRouter || props.RouterConfig == null)) { //if no Router config value was specified, override with procedural input if (deploy.RouterConfig is NoRouter) { deploy = deploy.WithRouterConfig(props.RouterConfig); } } props = props.WithDeploy(deploy); if (string.IsNullOrEmpty(props.Mailbox)) { // throw new NotSupportedException("Mailbox can not be configured as null or empty"); } if (string.IsNullOrEmpty(props.Dispatcher)) { //TODO: fix this.. // throw new NotSupportedException("Dispatcher can not be configured as null or empty"); } if (props.Deploy != null && props.Deploy.Scope is RemoteScope) { return RemoteActorOf(system, props, supervisor, path, mailbox); } return LocalActorOf(system, props, supervisor, path, mailbox); }
public ProjectionStream(ProjectionStreamQuery query, IActorRef reader, IActorRef writer, GlobalOptions options, Props replayWorkerProps) { _query = query; _reader = reader; _writer = writer; _options = options; _replayWorkerProps = replayWorkerProps ?? Props.Create<ProjectionReplayWorker>(); // subscribe to events in the stream Context.System.EventStream.Subscribe(Self, typeof(IPersistedEvent)); // request checkpoint var request = new ReadProjectionCheckpointRequest(_query.ProjectionStream); _lastRequestId = request.RequestID; _reader.Tell(request); Become(AwaitingCheckpoint); }
public RoutedActorRef(ActorSystemImpl system, Props routerProps, MessageDispatcher routerDispatcher, Func<Mailbox> createMailbox, Props routeeProps, IInternalActorRef supervisor, ActorPath path) : base(system, routerProps, routerDispatcher, createMailbox, supervisor, path) { _system = system; _routerProps = routerProps; _routerDispatcher = routerDispatcher; _createMailbox = createMailbox; _routeeProps = routeeProps; _supervisor = supervisor; //TODO: Implement: // // verify that a BalancingDispatcher is not used with a Router // if (!(routerProps.RouterConfig is NoRouter) && routerDispatcher is BalancingDispatcher) // { // throw new ConfigurationException("Configuration for " + this + // " is invalid - you can not use a 'BalancingDispatcher' as a Router's dispatcher, you can however use it for the routees."); // } // routerProps.RouterConfig.VerifyConfig(path); }
private Query ProcessFilter(Filter root, Flags flags, out Props props) { bool first = ((flags & Flags.Filter) == 0); Props propsCond; Query cond = ProcessNode(root.Condition, Flags.None, out propsCond); if ( CanBeNumber(cond) || (propsCond & (Props.HasPosition | Props.HasLast)) != 0 ) { propsCond |= Props.HasPosition; flags |= Flags.PosFilter; } // We don't want DescendantOverDescendant pattern to be recognized here (in case descendent::foo[expr]/descendant::bar) // So we clean this flag here: flags &= ~Flags.SmartDesc; // ToDo: Instead it would be nice to wrap descendent::foo[expr] into special query that will flatten it -- i.e. // remove all nodes that are descendant of other nodes. This is very easy because for sorted nodesets all children // follow its parent. One step caching. This can be easily done by rightmost DescendantQuery itself. // Interesting note! Can we guarantee that DescendantOverDescendant returns flat nodeset? This definitely true if it's input is flat. Query qyInput = ProcessNode(root.Input, flags | Flags.Filter, out props); if (root.Input.Type != AstNode.AstType.Filter) { // Props.PosFilter is for nested filters only. // We clean it here to avoid cleaning it in all other ast nodes. props &= ~Props.PosFilter; } if ((propsCond & Props.HasPosition) != 0) { // this condition is positional rightmost filter should be avare of this. props |= Props.PosFilter; } /*merging predicates*/ { FilterQuery qyFilter = qyInput as FilterQuery; if (qyFilter != null && (propsCond & Props.HasPosition) == 0 && qyFilter.Condition.StaticType != XPathResultType.Any) { Query prevCond = qyFilter.Condition; if (prevCond.StaticType == XPathResultType.Number) { prevCond = new LogicalExpr(Operator.Op.EQ, new NodeFunctions(FT.FuncPosition, null), prevCond); } cond = new BooleanExpr(Operator.Op.AND, prevCond, cond); qyInput = qyFilter.qyInput; } } if ((props & Props.PosFilter) != 0 && qyInput is DocumentOrderQuery) { qyInput = ((DocumentOrderQuery)qyInput).input; } if (_firstInput == null) { _firstInput = qyInput as BaseAxisQuery; } bool merge = (qyInput.Properties & QueryProps.Merge) != 0; bool reverse = (qyInput.Properties & QueryProps.Reverse) != 0; if ((propsCond & Props.HasPosition) != 0) { if (reverse) { qyInput = new ReversePositionQuery(qyInput); } else if ((propsCond & Props.HasLast) != 0) { qyInput = new ForwardPositionQuery(qyInput); } } if (first && _firstInput != null) { if (merge && (props & Props.PosFilter) != 0) { qyInput = new FilterQuery(qyInput, cond, /*noPosition:*/ false); Query parent = _firstInput.qyInput; if (!(parent is ContextQuery)) { // we don't need to wrap filter with MergeFilterQuery when cardinality is parent <: ? _firstInput.qyInput = new ContextQuery(); _firstInput = null; return(new MergeFilterQuery(parent, qyInput)); } _firstInput = null; return(qyInput); } _firstInput = null; } return(new FilterQuery(qyInput, cond, /*noPosition:*/ (propsCond & Props.HasPosition) == 0)); }
/// <summary> /// TBD /// </summary> /// <typeparam name="TActor">TBD</typeparam> /// <param name="factory">TBD</param> /// <param name="name">TBD</param> /// <returns>TBD</returns> public static IActorRef ActorOf <TActor>(this IActorRefFactory factory, string name = null) where TActor : ActorBase, new() { return(factory.ActorOf(Props.Create <TActor>(), name: name)); }
public void CanSerializeProps() { var message = Props.Create <BlackHoleActor>().WithMailbox("abc").WithDispatcher("def"); AssertEqual(message); }
private Props CreateWatchWithAndForwarderProps(IActorRef target, IActorRef forwardToActor, object message) { return(Props.Create(() => new WatchWithAndForwardActor(target, forwardToActor, message))); }
/// <summary> /// TBD /// </summary> /// <param name="props">TBD</param> /// <param name="attributes">TBD</param> /// <param name="shape">TBD</param> public ActorSubscriberSink(Props props, Attributes attributes, SinkShape <TIn> shape) : base(shape) { _props = props; _attributes = attributes; }
/// <summary> /// Create a new actor as child of <see cref="Sys" />. /// </summary> /// <param name="props">The props configuration object</param> public IActorRef ActorOf(Props props) { return(Sys.ActorOf(props, null)); }
/// <summary> /// Create a new actor as child of <see cref="Sys" />. /// </summary> /// <typeparam name="TActor">The type of the actor. It must have a parameterless public constructor</typeparam> public IActorRef ActorOf <TActor>() where TActor : ActorBase, new() { return(Sys.ActorOf(Props.Create <TActor>(), null)); }
/// <summary> /// Create a new actor as child of <see cref="Sys" />. /// </summary> /// <param name="props">The props configuration object</param> /// <param name="name">The name of the actor.</param> public IActorRef ActorOf(Props props, string name) { return(Sys.ActorOf(props, name)); }
/// <summary> /// Create a new <see cref="FSM{TState,TData}"/> as child of <see cref="Sys"/> /// and returns it as <see cref="TestFSMRef{TActor,TState,TData}"/> to enable inspecting and modifying the FSM directly. /// Uses an expression that calls the constructor of <typeparamref name="TFsmActor"/>. /// </summary> /// <typeparam name="TFsmActor">The type of the actor.</typeparam> /// <typeparam name="TState">The type of state name</typeparam> /// <typeparam name="TData">The type of state data</typeparam> /// <param name="factory">An expression that calls the constructor of <typeparamref name="TFsmActor"/></param> /// <param name="name">Optional: The name.</param> /// <param name="withLogging">Optional: If set to <c>true</c> logs state changes of the FSM as Debug messages. Default is <c>false</c>.</param> public TestFSMRef <TFsmActor, TState, TData> ActorOfAsTestFSMRef <TFsmActor, TState, TData>(Expression <Func <TFsmActor> > factory, string name = null, bool withLogging = false) where TFsmActor : FSM <TState, TData> { return(new TestFSMRef <TFsmActor, TState, TData>(Sys, Props.Create(factory), NoSupervisor, name, withLogging)); }
/// <summary> /// /// </summary> private void InitializeActors() { ClientMgr = System.ActorOf <ClientManager>("client-manager"); MessageProc = System.ActorOf(Props.Create(() => new MessageProcessor()).WithRouter(new RoundRobinPool(MSG_PROC_INSTANCES)), "message-proc"); MapMgr = System.ActorOf <MapManager>("map-manager"); }
/// <summary> /// Create a new <see cref="FSM{TState,TData}"/> as child of <see cref="Sys"/> /// and returns it as <see cref="TestFSMRef{TActor,TState,TData}"/> to enable inspecting and modifying the FSM directly. /// </summary> /// <typeparam name="TFsmActor">The type of the actor. It must be a <see cref="FSM{TState,TData}"/> and have a public parameterless constructor</typeparam> /// <typeparam name="TState">The type of state name</typeparam> /// <typeparam name="TData">The type of state data</typeparam> /// <param name="props">The <see cref="Props"/> object</param> /// <param name="name">Optional: The name.</param> /// <param name="withLogging">Optional: If set to <c>true</c> logs state changes of the FSM as Debug messages. Default is <c>false</c>.</param> public TestFSMRef <TFsmActor, TState, TData> ActorOfAsTestFSMRef <TFsmActor, TState, TData>(Props props, string name = null, bool withLogging = false) where TFsmActor : FSM <TState, TData> { return(new TestFSMRef <TFsmActor, TState, TData>(Sys, props, NoSupervisor, name, withLogging)); }
private Query ProcessFunction(Function root, out Props props) { props = Props.None; Query qy = null; switch (root.TypeOfFunction) { case FT.FuncLast: qy = new NodeFunctions(root.TypeOfFunction, null); props |= Props.HasLast; return(qy); case FT.FuncPosition: qy = new NodeFunctions(root.TypeOfFunction, null); props |= Props.HasPosition; return(qy); case FT.FuncCount: return(new NodeFunctions(FT.FuncCount, ProcessNode((AstNode)(root.ArgumentList[0]), Flags.None, out props) )); case FT.FuncID: qy = new IDQuery(ProcessNode((AstNode)(root.ArgumentList[0]), Flags.None, out props)); props |= Props.NonFlat; return(qy); case FT.FuncLocalName: case FT.FuncNameSpaceUri: case FT.FuncName: if (root.ArgumentList != null && root.ArgumentList.Count > 0) { return(new NodeFunctions(root.TypeOfFunction, ProcessNode((AstNode)(root.ArgumentList[0]), Flags.None, out props) )); } else { return(new NodeFunctions(root.TypeOfFunction, null)); } case FT.FuncString: case FT.FuncConcat: case FT.FuncStartsWith: case FT.FuncContains: case FT.FuncSubstringBefore: case FT.FuncSubstringAfter: case FT.FuncSubstring: case FT.FuncStringLength: case FT.FuncNormalize: case FT.FuncTranslate: return(new StringFunctions(root.TypeOfFunction, ProcessArguments(root.ArgumentList, out props))); case FT.FuncNumber: case FT.FuncSum: case FT.FuncFloor: case FT.FuncCeiling: case FT.FuncRound: if (root.ArgumentList != null && root.ArgumentList.Count > 0) { return(new NumberFunctions(root.TypeOfFunction, ProcessNode((AstNode)root.ArgumentList[0], Flags.None, out props) )); } else { return(new NumberFunctions(Function.FunctionType.FuncNumber, null)); } case FT.FuncTrue: case FT.FuncFalse: return(new BooleanFunctions(root.TypeOfFunction, null)); case FT.FuncNot: case FT.FuncLang: case FT.FuncBoolean: return(new BooleanFunctions(root.TypeOfFunction, ProcessNode((AstNode)root.ArgumentList[0], Flags.None, out props) )); case FT.FuncUserDefined: _needContext = true; if (!_allowCurrent && root.Name == "current" && root.Prefix.Length == 0) { throw XPathException.Create(SR.Xp_CurrentNotAllowed); } if (!_allowKey && root.Name == "key" && root.Prefix.Length == 0) { throw XPathException.Create(SR.Xp_InvalidKeyPattern, _query); } qy = new FunctionQuery(root.Prefix, root.Name, ProcessArguments(root.ArgumentList, out props)); props |= Props.NonFlat; return(qy); default: throw XPathException.Create(SR.Xp_NotSupported, _query); } }
public IActorRef ActorOf(Props props, string name = null) { return(_actorSystem.ActorOf(props, name)); }
/// <summary> /// Create a new actor as child of <see cref="Sys"/> and returns it as <see cref="TestActorRef{TActor}"/> /// to enable access to the underlying actor instance via <see cref="TestActorRefBase{TActor}.UnderlyingActor"/>. /// Uses an expression that calls the constructor of <typeparamref name="TActor"/>. /// <example> /// <code>ActorOf<MyActor>(()=>new MyActor("value", 4711), "test-actor")</code> /// </example> /// </summary> /// <typeparam name="TActor">The type of the actor.</typeparam> /// <param name="factory">An expression that calls the constructor of <typeparamref name="TActor"/></param> /// <param name="name">Optional: The name.</param> public TestActorRef <TActor> ActorOfAsTestActorRef <TActor>(Expression <Func <TActor> > factory, string name = null) where TActor : ActorBase { return(new TestActorRef <TActor>(Sys, Props.Create(factory), NoSupervisor, name)); }
public static Reporter CreateReporter(IActorRefFactory factory, string?name = "Reporter") => new Reporter(factory.ActorOf(Props.Create(() => new ReporterActor()).WithSupervisorStrategy(SupervisorStrategy.StoppingStrategy), name));
/// <summary> /// Create a new actor as child of <see cref="Sys"/> and returns it as <see cref="TestActorRef{TActor}"/> /// to enable access to the underlying actor instance via <see cref="TestActorRefBase{TActor}.UnderlyingActor"/>. /// </summary> /// <typeparam name="TActor">The type of the actor. It must have a parameterless public constructor</typeparam> /// <param name="name">Optional: The name.</param> public TestActorRef <TActor> ActorOfAsTestActorRef <TActor>(string name = null) where TActor : ActorBase, new() { return(new TestActorRef <TActor>(Sys, Props.Create <TActor>(), NoSupervisor, name)); }
public static Props Prop(IActorRef client, long transactionTimeoutMs, long txnIdLeastBits, long txnIdMostBits) { return(Props.Create(() => new TransactionActor(client, transactionTimeoutMs, txnIdLeastBits, txnIdMostBits))); }
/// <summary> /// Create a new actor as child of <see cref="Sys"/> and returns it as <see cref="TestActorRef{TActor}"/> /// to enable access to the underlying actor instance via <see cref="TestActorRefBase{TActor}.UnderlyingActor"/>. /// </summary> /// <typeparam name="TActor">The type of the actor. It must have a parameterless public constructor</typeparam> /// <param name="props">The <see cref="Props"/> object</param> /// <param name="name">Optional: The name.</param> public TestActorRef <TActor> ActorOfAsTestActorRef <TActor>(Props props, string name = null) where TActor : ActorBase { return(new TestActorRef <TActor>(Sys, props, NoSupervisor, name)); }
/// <summary> /// Creates props for the current cluster singleton manager using <see cref="PoisonPill"/> /// as the default termination message. /// </summary> /// <param name="singletonProps"><see cref="Actor.Props"/> of the singleton actor instance.</param> /// <param name="settings">Cluster singleton manager settings.</param> /// <returns></returns> public static Props Props(Props singletonProps, ClusterSingletonManagerSettings settings) { return(Props(singletonProps, PoisonPill.Instance, settings)); }
static void Main(string[] args) { // First part demo // var system = ActorSystem.Create("MySystem"); // // var musicPlayer = system.ActorOf<MusicPlayerActor>("musicPlayer"); // // Console.ReadKey(); // musicPlayer.Tell(new PlayMessage("track 1")); // // Console.ReadKey(); // musicPlayer.Tell(new PlayMessage("track 2")); // // Console.ReadKey(); // musicPlayer.Tell(new StopMessage()); // // Console.ReadKey(); // musicPlayer.Tell(new StopMessage()); // // system.Terminate().Wait(); // // Console.ReadKey(); // second part demo (Failure Recovery) ColorConsole.WriteLineGray("Creating MatchStatActorSystem"); var matchStatActorSystem = ActorSystem.Create("MatchStatActorSystem"); ColorConsole.WriteLineGray("Creating actor supervisory hierarchy"); matchStatActorSystem.ActorOf(Props.Create <StatCoordinatorActor>(), "StatCoordinator"); do { ShortPause(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkGray; ColorConsole.WriteLineGray("enter a command and hit enter"); var command = Console.ReadLine(); if (command.StartsWith("show")) { string matchId = command.Split(',')[1]; var message = new ShowMatchStatsMessage(matchId); matchStatActorSystem.ActorSelection("/user/StatCoordinator").Tell(message); } if (command.StartsWith("terminate")) { string matchId = command.Split(',')[1]; var message = new TerminateMatchMessage(matchId); matchStatActorSystem.ActorSelection("/user/StatCoordinator").Tell(message); } if (command == "exit") { matchStatActorSystem.Terminate().Wait(); ColorConsole.WriteLineGray("Actor system shutdown"); Console.ReadKey(); Environment.Exit(1); } } while (true); }
/// <summary> /// Creates props for the current cluster singleton manager. /// </summary> /// <param name="singletonProps"><see cref="Actor.Props"/> of the singleton actor instance.</param> /// <param name="terminationMessage"> /// When handing over to a new oldest node this <paramref name="terminationMessage"/> is sent to the singleton actor /// to tell it to finish its work, close resources, and stop. The hand-over to the new oldest node /// is completed when the singleton actor is terminated. Note that <see cref="PoisonPill"/> is a /// perfectly fine <paramref name="terminationMessage"/> if you only need to stop the actor. /// </param> /// <param name="settings">Cluster singleton manager settings.</param> public static Props Props(Props singletonProps, object terminationMessage, ClusterSingletonManagerSettings settings) { return(Actor.Props.Create(() => new ClusterSingletonManager(singletonProps, terminationMessage, settings)).WithDeploy(Deploy.Local)); }
public static IActorRef CreateListner(IActorRefFactory factory, Action <string> listner, Action <IOperationResult> onCompled, TimeSpan timeout, string?name = "LogListner") => factory.ActorOf(Props.Create(() => new Listner(listner, onCompled, timeout)).WithSupervisorStrategy(SupervisorStrategy.StoppingStrategy), name);
public DepositMade() { _storage = Context.ActorOf(Props.Create <FileSystemStorage>(), SystemData.StorageActor.Name); Become(RetrievingEntity); _log = Context.GetLogger(); }
private Props CreateWatchAndForwarderProps(IActorRef target, IActorRef forwardToActor) { return(Props.Create(() => new WatchAndForwardActor(target, forwardToActor))); }
/// <summary> /// Create a new actor as child of <see cref="Sys" />. /// </summary> /// <typeparam name="TActor">The type of the actor. It must have a parameterless public constructor</typeparam> /// <param name="name">The name of the actor.</param> public IActorRef ActorOf <TActor>(string name) where TActor : ActorBase, new() { return(Sys.ActorOf(Props.Create <TActor>(), name)); }
public void An_ActorRefFactory_must_only_create_one_instance_of_an_actor_with_a_specific_address_in_a_concurrent_environment() { var impl = (ActorSystemImpl)Sys; var provider = impl.Provider; Assert.IsType <LocalActorRefProvider>(provider); for (var i = 0; i < 100; i++) { var timeout = Dilated(TimeSpan.FromSeconds(5)); var address = "new-actor" + i; var actors = Enumerable.Range(0, 4).Select(x => Task.Run(() => Sys.ActorOf(Props.Create(() => new BlackHoleActor()), address))).ToArray(); // Use WhenAll with empty ContinueWith to swallow all exceptions, so we can inspect the tasks afterwards. Task.WhenAll(actors).ContinueWith(a => { }).Wait(timeout); Assert.True(actors.Any(x => x.Status == TaskStatus.RanToCompletion && x.Result != null), "Failed to create any Actors"); Assert.True(actors.Any(x => x.Status == TaskStatus.Faulted && x.Exception.InnerException is InvalidActorNameException), "Succeeded in creating all Actors. Some should have failed."); } }
/// <summary> /// Create a new actor as child of <see cref="Sys" /> using an expression that calls the constructor /// of <typeparamref name="TActor"/>. /// <example> /// <code>ActorOf<MyActor>(()=>new MyActor("value", 4711), "test-actor")</code> /// </example> /// </summary> /// <typeparam name="TActor">The type of the actor.</typeparam> /// <param name="factory">An expression that calls the constructor of <typeparamref name="TActor"/></param> /// <param name="name">The name of the actor.</param> public IActorRef ActorOf <TActor>(Expression <Func <TActor> > factory, string name) where TActor : ActorBase { return(Sys.ActorOf(Props.Create(factory), name)); }
public DeathWatchSpec() { _supervisor = Sys.ActorOf(Props.Create(() => new Supervisor(SupervisorStrategy.DefaultStrategy)), "watchers"); _terminal = Sys.ActorOf(Props.Empty); }
/// <summary> /// Create a new <see cref="FSM{TState,TData}"/> as child of <see cref="Sys"/> /// and returns it as <see cref="TestFSMRef{TActor,TState,TData}"/> to enable inspecting and modifying the FSM directly. /// <typeparamref name="TFsmActor"/> must have a public parameterless constructor. /// </summary> /// <typeparam name="TFsmActor">The type of the actor. It must have a parameterless public constructor</typeparam> /// <typeparam name="TState">The type of state name</typeparam> /// <typeparam name="TData">The type of state data</typeparam> /// <param name="name">Optional: The name.</param> /// <param name="withLogging">Optional: If set to <c>true</c> logs state changes of the FSM as Debug messages. Default is <c>false</c>.</param> public TestFSMRef <TFsmActor, TState, TData> ActorOfAsTestFSMRef <TFsmActor, TState, TData>(string name = null, bool withLogging = false) where TFsmActor : FSM <TState, TData>, new() { return(new TestFSMRef <TFsmActor, TState, TData>(Sys, Props.Create <TFsmActor>(), NoSupervisor, name, withLogging)); }
private BackoffOptions OnFailureOptions(Props props, int maxNrOfRetries = -1) => Backoff.OnFailure(props, "c1", 100.Milliseconds(), 3.Seconds(), 0.2, maxNrOfRetries);