public TestProjection(IActorRef probe) { _probe = probe; OnEvent<TestEvent>(e => { _probe.Forward(e); }); OnQuery<TestQuery>(q => { _probe.Forward(q); }); }
public Master() { mapper = Context.ActorOf( Props.Create<Mapper>() .WithRouter(new RoundRobinPool(NrMappers)) ); reducer = Context.ActorOf( Props.Create<Reducer>() .WithRouter(new RoundRobinPool(NrReducers)) ); aggregator = Context.ActorOf(Props.Create<Aggregator>()); // 1. forward a string to mapper Receive<string>(s => mapper.Tell(s)); // 2. forward map result to reducer Receive<MapResult>(m => reducer.Tell(m)); // 3. forward reduce result to aggregator Receive<ReduceResult>(r => aggregator.Tell(r)); // allow asking for aggregated result at any time Receive<GetResult>(g => aggregator.Forward(g)); }
public TestService(IActorRef testActorRef) { ReceiveAny(msg => { testActorRef.Forward(msg); Sender.Tell(msg.ToString() + "-ack"); }); }
public ForwardActor(IActorRef testActor) { _testActor = testActor; Context.Parent.Tell("one"); Receive<string>(s => s == "one", c => { _testActor.Forward("two"); }); }
protected override void OnReceive(object message) { message.Match() .With <ClusterEvent.CurrentClusterState>(HandleInitial) .With <ClusterEvent.MemberUp>(m => Add(m.Member)) .With <ClusterEvent.MemberExited>(m => Remove(m.Member)) .With <ClusterEvent.MemberRemoved>(m => Remove(m.Member)) .With <ActorIdentity>(identity => { if (identity.Subject != null) { // if the new singleton is defined, deliver all buffered messages var subject = identity.Subject; Log.Info("Singleton identified at [{0}]", subject.Path); _singleton = subject; Context.Watch(subject); CancelTimer(); SendBuffered(); } }) .With <TryToIdentifySingleton>(() => { var oldest = _membersByAge.FirstOrDefault(); if (oldest != null && _identityTimer != null) { var singletonAddress = new RootActorPath(oldest.Address) / _singletonPath; Log.Debug("Trying to identify singleton at [{0}]", singletonAddress); Context.ActorSelection(singletonAddress).Tell(new Identify(_identityId)); } }) .With <Terminated>(terminated => { if (Equals(_singleton, terminated.ActorRef)) { // buffering mode, identification of new will start when old node is removed _singleton = null; } }) .Default(msg => { if (_singleton != null) { if (Log.IsDebugEnabled) { Log.Debug("Forwarding message of type [{0}] to current singleton instance at [{1}]", msg.GetType(), _singleton.Path); } _singleton.Forward(msg); } else { Buffer(msg); } }); }
protected override bool Receive(object message) { return(message.Match().With <IdentifyReq>(req => { var actorSelection = Context.ActorSelection(req.Path); actorSelection.Tell(new Identify(null), Sender); }) .With <StopChild1>(child => { Context.Stop(Context.Child(child.Name)); }) .Default(o => { _testActor.Forward(o); }) .WasHandled); }
public FilterActor(IActorRef recepient) { Receive <IMessageMetadataEnvelop>(m => { // switch (m.Message) // { // case CreateNewStateCommand<> // } recepient.Forward(m); }); }
public Fw2(IActorRef aref) { var actorRef = ActorRefs.NoSender; Receive <TriggerAckMessage>(_ => actorRef.Tell(AckMessage)); ReceiveAny(msg => { actorRef = Sender; aref.Forward(msg); }); }
private void OnTransaction(Transaction tx) { if (ContainsTransaction(tx.Hash)) { SendRelayResult(tx, VerifyResult.AlreadyExists); } else { txrouter.Forward(new TransactionRouter.Preverify(tx, true)); } }
// Message handler private void OnSetDeviceStatus(SetDeviceStatus msg) { string uniqueDeviceActorName = ActorSystemReferences.ActorNames.DeviceMqttTranslatorActorNamePrefix + _deviceDto.DeviceId; IActorRef deviceActor = Context.Child(uniqueDeviceActorName); if (deviceActor.IsNobody()) { _mqttDeviceTranslatorActor = Context.ActorOf(Props.Create <DeviceMqttTranslatorActor>(_deviceDto.DeviceId), ActorSystemReferences.ActorNames.DeviceMqttTranslatorActorNamePrefix + _deviceDto.DeviceId); } _mqttDeviceTranslatorActor.Forward(msg); }
protected override bool Receive(object message) { if (message.ToString() == "self") { Sender.Tell(Self); } else { _inner.Forward(message); } return(true); }
public CalculationEngineActor() { Receive <Common.Core.IEventWrapper>(e => { switch (e.GetContent()) { case ICurvePointAdded _: case ICurveRecipeCreated _: _marketCurves.Forward(e); break; case IInstrumentPricingPublished _: _marketCurves.Forward(e); _instruments.Forward(e); break; default: break; } }); }
private Action Recovering(IActorRef recovery, TaskCompletionSource <object> promise) { return(() => { Receive <ReplicationReadEnvelope>(re => recovery.Forward(re)); Receive <RecoveryCompleted>(_ => { promise.SetResult(null); Become(Processing); }); }); }
protected override void OnReceive(object message) { if (message is SendEnd) { if (_target != null) { Context.ActorSelection(new RootActorPath(_target) / Self.Path.Elements).Tell(End.Instance); } return; } if (message is End) { _testActor.Forward(End.Instance); Sender.Tell(EndAck.Instance); return; } if (message is EndAck) { _testActor.Forward(EndAck.Instance); } }
public Unreliable(int dropMod, IActorRef target) { Receive <object>((message) => { _count++; if (_count % dropMod != 0) { target.Forward(message); } return(true); }); }
/// <summary> /// Forward all instances of <typeparamref name="TMessage"/> to the specified actor. /// </summary> /// <typeparam name="TMessage"> /// The base message type to forward. /// </typeparam> /// <param name="toActor"> /// The actor to which messages will be forwarded. /// </param> protected virtual void Forward <TMessage>(IActorRef toActor) { if (toActor == null) { throw new ArgumentNullException(nameof(toActor)); } Receive <TMessage>(message => { toActor.Forward(message); }); }
/// <summary> /// Initializes a new instance of the <see cref="CommunicationActor"/> class. /// </summary> /// <param name="lockingActor">The locking actor.</param> public CommunicationActor(IActorRef lockingActor) { this.lockingActor = lockingActor; Receive <ShutdownMsg>(msg => { Sender.Tell(new ReceivedMsg()); Context.System.Terminate(); }); Receive <ConfigureMsg>(msg => lockingActor.Forward(msg)); }
private void HandleShardRegionQuery(IShardRegionQuery query) { switch (query) { case GetCurrentRegions _: if (_coordinator != null) { _coordinator.Forward(query); } else { Sender.Tell(new CurrentRegions(ImmutableHashSet <Address> .Empty)); } break; case GetShardRegionState _: ReplyToRegionStateQuery(Sender); break; case GetShardRegionStats _: ReplyToRegionStatsQuery(Sender); break; case GetClusterShardingStats _: if (_coordinator != null) { _coordinator.Forward(query); } else { Sender.Tell(new ClusterShardingStats(ImmutableDictionary <Address, ShardRegionStats> .Empty)); } break; default: Unhandled(query); break; } }
private void LookupSagaMessageHandler(LookupSagaMessage message) { IActorRef actorRef = LookupWorkflow(message.ModuleKey, message.ModuleVersion); if (actorRef == ActorRefs.Nobody) { Sender.Tell(new LookupSagaFailedMessage(message)); } else { actorRef.Forward(message); } }
private void LookupModuleMessageHandler(LookupModuleMessage message) { IActorRef actorRef = LookupDataOwner(message.DataOwnerKey, message.DataOwnerVersion); if (actorRef == ActorRefs.Nobody) { Sender.Tell(new LookupModuleFailedMessage(message)); } else { actorRef.Forward(message); } }
public TestService(IActorRef testActorRef) { Receive <string>(cmd => cmd.Equals("shutdown"), msg => { Context.System.Terminate(); }); ReceiveAny(msg => { testActorRef.Forward(msg); Sender.Tell(new Reply(msg.ToString() + "-ack", Cluster.Get(Context.System).SelfAddress)); }); }
public UserActor(string userName) { _userName = userName; //Create Shopping Cart _cart = Context.ActorOf <CartActor>(); //Forward AddProduct Message to Cart Actor Receive <AddProduct>(m => _cart.Forward(m)); //Tell Cart to send it's status Receive <Login>(m => _cart.Tell(new FetchCartStatus(m.UserName), Sender)); }
public void Handle(IMessage m) { if (m.GetType() == typeof(connect)) { (new Thread(() => connect((m as connect).host, (m as connect).port))).Start(); } else if (m.GetType() == typeof(disconnect)) { if (client_.socket.IsConnected()) { logger_?.Tell(new log("aborting connection", logType.info, verbosity.high)); // connect client_.socket.eDisconnect(); } } else if (m.GetType() == typeof(connectionStatus)) { if (client_.socket.IsConnected()) { Sender.Tell(new connectionStatus(true), Self); } } else if (m.GetType() == typeof(historicalDataManager.request)) { if (client_.socket.IsConnected()) { var temp = (m as historicalDataManager.request); if (temp.correlation != null) { client_.socket.reqHistoricalData( temp.correlation.id, temp.contract, temp.endDatetime.ToString("yyyyMMdd"), temp.duration.ToString(), temp.barSize.ToString(), temp.type.ToString(), temp.useRTH, temp.formatDate, null); } } } else if (m.GetType() == typeof(registration)) { // pass-through dispatcher_?.Forward(m); } }
IActorRef CreateWorkingWriter(IActorRef relay = null) { return(Sys.ActorOf(conf => { conf.Receive <PersistenceRequest>((r, ctx) => { if (relay != null) { relay.Forward(r); } ctx.Sender.Tell(new PersistenceSuccess(r.PersistenceID)); }); })); }
protected override void OnReceive(object message) { Console.WriteLine(JsonConvert.SerializeObject(new { Message = $"{GetType().Name}.OnReceive", message }, Formatting.Indented)); switch (message) { case RequestAllTemperatures r: Context.ActorOf(DeviceGroupQuery.Props(_actorToDeviceId, r.RequestId, Sender, TimeSpan.FromSeconds(3))); break; case RequestTrackDevice trackMsg when trackMsg.GroupId.Equals(GroupId): if (_deviceIdToActor.TryGetValue(trackMsg.DeviceId, out IActorRef actorRef)) { actorRef.Forward(trackMsg); } else { Log.Info($"Creating device actor for {trackMsg.DeviceId}"); IActorRef deviceActor = Context.ActorOf(Device.Props(trackMsg.GroupId, trackMsg.DeviceId), $"device-{trackMsg.DeviceId}"); // Monitors the specified actor for termination. // When the actor terminates the instance watching // will receive a Terminated message. Context.Watch(deviceActor); _actorToDeviceId.Add(deviceActor, trackMsg.DeviceId); _deviceIdToActor.Add(trackMsg.DeviceId, deviceActor); // Forwards the message using the current Sender. deviceActor.Forward(trackMsg); } break; case RequestDeviceList deviceList: Sender.Tell(new ReplyDeviceList(deviceList.RequestId, new HashSet <string>(_deviceIdToActor.Keys))); break; case RequestTrackDevice trackMsg: Log.Warning($"Ignoring TrackDevice request for {trackMsg.GroupId}. This actor is responsible for {GroupId}."); break; case Terminated t: string deviceId = _actorToDeviceId[t.ActorRef]; Log.Info($"Device actor for {deviceId} has been terminated"); _actorToDeviceId.Remove(t.ActorRef); _deviceIdToActor.Remove(deviceId); break; } }
public Server() { Receive <Request>(x => { Console.WriteLine($"Server: received request value: {x.Message}"); Sender.Tell(new Reply($"RESP - 1 for {x.Message}")); }); Receive <RequestComplex>(x => { Console.WriteLine($"Server: received request value: {x.Message}"); Sender.Tell(new Reply($"RESP - 1 for {x.Message}")); worker.Forward(new WorkerRequestComplex(x.Message)); }); }
private void HandleShardRegionQuery(IShardRegionQuery query) { if (query is GetCurrentRegions) { if (_coordinator != null) { _coordinator.Forward(query); } else { Sender.Tell(new CurrentRegions(ImmutableHashSet <Address> .Empty)); } } else if (query is GetShardRegionState) { ReplyToRegionStateQuery(Sender); } else if (query is GetShardRegionStats) { ReplyToRegionStatsQuery(Sender); } else if (query is GetClusterShardingStats) { if (_coordinator != null) { _coordinator.Forward(query); } else { Sender.Tell(new ClusterShardingStats(ImmutableDictionary <Address, ShardRegionStats> .Empty)); } } else { Unhandled(query); } }
public SomeActor() { Receive <string>(s => s.Equals("hello"), (message) => { Sender.Tell("world", Self); if (target != null) { target.Forward(message); } }); Receive <IActorRef>(actorRef => { target = actorRef; Sender.Tell("done"); }); }
// Message handlers private void OnSetDeviceStatus(SetDeviceStatus msg) { string uniqueDeviceActorName = ActorSystemReferences.ActorNames.DeviceActorNamePrefix + msg.DeviceId; IActorRef deviceActorRef = Context.Child(uniqueDeviceActorName); if (deviceActorRef.IsNobody()) { Sender.Tell(new SetDeviceStatusReceived(unexistingDevice: true), Self); } else { deviceActorRef.Forward(msg); } }
public PingBackAndForward() { Receive <string>(s => s.Equals(Ping.Name), (message) => { Sender.Tell(Pong, Self); if (!target.Equals(ActorRefs.NoSender)) { target.Forward(message); } }); Receive <IActorRef>(actorRef => { target = actorRef; Sender.Tell("done"); }); }
public PassivatingActor() { Child = Context.ActorOf(ShardedEntityActorProps.Create <TestEntity, TestCommand, TestEvent, TestState>( "test", OptionInitializers.Some("1"), () => new TestEntity(Context.System), 100, 1d.seconds(), "", "" ) ); Receive <Passivate>(stopMsg => Sender.Tell(stopMsg.StopMessage)); ReceiveAny(x => Child.Forward(x)); }
protected void Connected() { _log.Warning("Connected"); HandleListeners(); Receive <RequestBase>(m => Connection.Forward(m)); Receive <Connection.Disconnected>(dm => { NotifyStateChanged(dm); Become(Disconnected); Self.Tell(new Reconnect()); }); }
public void Tell(TStart starter) { if (starter == null) { return; } if (_forward) { _delegator.Forward(starter); } else { _delegator.Tell(starter); } }
private void Normal() { Receive <BinaryTreeSetMessages.Operation>(op => { _loggingAdapter.Info($"Forwarding operation: {op.Id}"); _root.Forward(op); }); Receive <BinaryTreeSetMessages.Gc>(_ => { var newRoot = CreateRoot(); _root.Tell(new BinaryTreeNodeMessages.CopyTo(newRoot)); Become(GarbageCollecting(newRoot)); }); }
public ParentWithChildPropsActor(Props childProps) { _childActor = Context.ActorOf(childProps, "child"); Receive<ChildDoWorkMessage>(m => _childActor.Forward(m)); }
private Receive Active(IActorRef receptionist) { return message => message.Match() .With<Send>(send => receptionist.Forward(new Send(send.Path, send.Message, send.LocalAffinity))) .With<SendToAll>(toAll => receptionist.Forward(new SendToAll(toAll.Path, toAll.Message))) .With<Publish>(publish => receptionist.Forward(new Publish(publish.Topic, publish.Message))) .With<InternalMessage>(m => { switch (m) { case InternalMessage.HeartbeatTick: if (!_failureDetector.IsAvailable) { Log.Info("Lost contact with [{0}], restablishing connection", receptionist); SendGetContacts(); ScheduleRefreshContactsTick(Settings.EstablishingGetContactsInterval); Context.Become(Establishing); _failureDetector.HeartBeat(); } else { receptionist.Tell(ClusterReceptionist.Heartbeat.Instance); } break; case InternalMessage.RefreshContactsTick: receptionist.Tell(ClusterReceptionist.GetContacts.Instance); break; } }) .With<ClusterReceptionist.HeartbeatRsp>(_ => _failureDetector.HeartBeat()) .With<ClusterReceptionist.Contacts>(contacts => { if (contacts.ContactPoints.Length != 0) _contacts = contacts.ContactPoints.Select(Context.ActorSelection).ToArray(); }) .With<Terminated>(terminated => { Log.Info("Lost contact with [{0}], restablishing connection", receptionist); SendGetContacts(); ScheduleRefreshContactsTick(Settings.EstablishingGetContactsInterval); Context.Become(Establishing); }) .With<ActorIdentity>(_ => { /* ok, from previous establish, already handled */ }) .WasHandled; }
public ProbeRelay(IActorRef target) { ReceiveAny(o => target.Forward(o)); }
public TestService(IActorRef testActorRef) { Receive<string>(cmd => cmd.Equals("shutdown"), msg => { Context.System.Terminate(); }); ReceiveAny(msg => { testActorRef.Forward(msg); Sender.Tell(new Reply(msg.ToString() + "-ack", Cluster.Get(Context.System).SelfAddress)); }); }
public ForwardActor(IActorRef testActor) { _testActor = testActor; ReceiveAny(msg => { _testActor.Forward(msg); }); }
public ProbeActor(IActorRef testActor) { _testActor = testActor; Receive<WatchIt>(w => { Context.Watch(w.Watchee); Sender.Tell(Ack.Instance); }); Receive<UnwatchIt>(w => { Context.Unwatch(w.Watchee); Sender.Tell(Ack.Instance); }); Receive<Terminated>(t => _testActor.Forward(new WrappedTerminated(t))); ReceiveAny(msg => _testActor.Forward(msg)); }
private Receive Active(IActorRef receptionist) { return message => { if (message is Send) { var send = (Send)message; receptionist.Forward(new PublishSubscribe.Send(send.Path, send.Message, send.LocalAffinity)); } else if (message is SendToAll) { var sendToAll = (SendToAll)message; receptionist.Forward(new PublishSubscribe.SendToAll(sendToAll.Path, sendToAll.Message)); } else if (message is Publish) { var publish = (Publish)message; receptionist.Forward(new PublishSubscribe.Publish(publish.Topic, publish.Message)); } else if (message is HeartbeatTick) { if (!_failureDetector.IsAvailable) { _log.Info("Lost contact with [{0}], restablishing connection", receptionist); SendGetContacts(); ScheduleRefreshContactsTick(_settings.EstablishingGetContactsInterval); Context.Become(Establishing); _failureDetector.HeartBeat(); } else { receptionist.Tell(ClusterReceptionist.Heartbeat.Instance); } } else if (message is ClusterReceptionist.HeartbeatRsp) { _failureDetector.HeartBeat(); } else if (message is RefreshContactsTick) { receptionist.Tell(ClusterReceptionist.GetContacts.Instance); } else if (message is ClusterReceptionist.Contacts) { var contacts = (ClusterReceptionist.Contacts)message; // refresh of contacts if (contacts.ContactPoints.Count > 0) { _contactPaths = contacts.ContactPoints.Select(ActorPath.Parse).ToImmutableHashSet(); _contacts = _contactPaths.Select(Context.ActorSelection).ToArray(); } PublishContactPoints(); } else if (message is ActorIdentity) { // ok, from previous establish, already handled } else { return ContactPointMessages(message); } return true; }; }
private void ForwardTo( IActorRef sender, GithubValidatorActor.InvalidRepo repo ) { sender.Forward( repo ); }
IActorRef CreateWorkingWriter(IActorRef relay = null) { return Sys.ActorOf(conf => { conf.Receive<PersistenceRequest>((r, ctx) => { if (relay != null) relay.Forward(r); ctx.Sender.Tell(new PersistenceSuccess(r.PersistenceID)); }); }); }