//Actor给Actor发送ActorMessage类型的信心 public void SendMsg(ActorMessage msg) { lock (m_lockobj) { m_msgQueue.Enqueue(msg); } }
public async System.Threading.Tasks.Task <Event> PublishEvent(ActorMessage source, ActorMessage destination, IMessageBroker messageBroker, EventAggregator.RoutingFilter routingFilter) { if (destination.Type == "TestEvent") { var @event = new HomeCenter.SourceGenerators.Tests.TestEvent(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } else if (destination.Type == "TestEvent2") { var @event = new HomeCenter.SourceGenerators.Tests.TestEvent2(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } var ev = new Event(); ev.SetProperties(source); ev.SetProperties(destination); await messageBroker.Publish(ev, routingFilter); return(ev); }
public async Task <Event> PublishEvent(ActorMessage source, ActorMessage destination, IMessageBroker messageBroker, RoutingFilter routingFilter) { if (destination.Type == "TestEvent") { var @event = new TestEvent(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } if (destination.Type == "TestEvent2") { var @event = new TestEvent2(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } var ev = new Event(); ev.SetProperties(source); ev.SetProperties(destination); await messageBroker.Publish(ev, routingFilter); return(ev); }
public void SendWithTranslate(ActorMessage source, ActorMessage destination, string address) { var command = _messageGenerator.CreateCommand(destination.Type); command.SetProperties(source); command.SetProperties(destination); Send(command, address); }
// This method blocks by calling TryReceive repeatidly, always sure to return a good result public bool TryReceive(out ActorMessage<MessageArgs> message) { message = default(ActorMessage<MessageArgs>); ActorMessage<MessageArgs> temp = message; bool result = Receive((m) => temp = m); message = temp; return result; }
//Actor给Actor发送string类型的信息 public void SendMsg(string msg) { var m = new ActorMessage(); m.msg = msg; lock (m_lockobj) { m_msgQueue.Enqueue(m); } }
//Actor给Actor发送ActorMessage类型的信心 public void SendMsg(ActorMessage msg) { if (msg == null) { return; } lock (m_lockobj) { m_msgQueue.Enqueue(msg); } }
//Actor给Actor发送Packet类型的信息 public void SendMsg(Packet packet) { var m = new ActorMessage() { packet = packet }; lock (m_lockobj) { m_msgQueue.Enqueue(m); } }
//Actor给Actor发送string类型的信息 public void SendMsg(string msg) { if (string.IsNullOrEmpty(msg)) { return; } var m = new ActorMessage(); m.msg = msg; lock (m_lockobj) { m_msgQueue.Enqueue(m); } }
private static void OnTimerElapsed(object sender, ElapsedEventArgs e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Published message for actor."); Console.ForegroundColor = _defaultConsoleForeground; ActorMessage actorMessage = new ActorMessage { Command = $"power={_cnt++}", Timestamp = DateTime.UtcNow }; string payload = JsonConvert.SerializeObject(actorMessage); mqttClient.PublishAsync("D6B02D87-FBDD-4D52-BA31-9A0623D8E67A/actors/switch1", payload).Wait(); }
//Actor给Actor发送Packet类型的信息 public void SendMsg(Packet packet) { if (packet == null) { return; } var m = new ActorMessage() { packet = packet }; lock (m_lockobj) { m_msgQueue.Enqueue(m); } }
protected override void ReceiveMsg(ActorMessage actorMsg) { if (!string.IsNullOrEmpty(actorMsg.msg)) { var cmds = actorMsg.msg.Split(SplitChar); if (cmds[0] == CreatePlayerActorStr) { var agentId = System.Convert.ToUInt32(cmds[1]); CreatePlayerActorCallback(agentId); } else if (cmds[0] == DestroyPlayerActorStr) { var agentId = System.Convert.ToUInt32(cmds[1]); DestroyPlayerActorCallback(agentId); //销毁PlayerActor } } }
protected override void ReceiveMsg(ActorMessage actorMsg) { if (actorMsg == null) { return; } if (!string.IsNullOrEmpty(actorMsg.msg)) { HandleMsgStr(actorMsg.msg); } if (actorMsg.packet != null) { //处理ActorMessage中携带Packet内容的情况 Packet packet = actorMsg.packet; HandlePacket(packet); } }
private IEnumerator Dispatch() { while (!m_isStop) { if (m_msgQueue.Count > 0) { ActorMessage msg = null; lock (m_lockobj) { msg = m_msgQueue.Dequeue(); } ReceiveMsg(msg); } else { yield return(null); } } }
public Task PublishWithTranslate(ActorMessage source, ActorMessage destination, RoutingFilter filter = null) { var ev = _messageGenerator.CreateEvent(source, destination); return(Publish(ev, filter)); }
public static TResult Response <TActor, TResult>(this ActorMessage <TActor, TResult> message, TResult result) where TActor : IActorGrain => result;
public CommandJob(ActorMessage message) => Message = message;
internal abstract void OnActorMessageReceived(ActorMessage actorData);
/// <summary> /// Helper method to use when building task responses for strongly typed messages which return results. /// If the type of returned result is changed in message declaration this will help catching it at compile time. /// </summary> /// <example> /// <para> /// class Query : ActorMessage<MyActor,int>{} /// </para> /// <para> /// Task<object> On(Query x) => x.TaskResult(42); /// </para> /// </example> /// <param name="message">The strongly typed message</param> /// <param name="result">The result to return</param> /// <typeparam name="TActor">The type of the actor to which this message belongs</typeparam> /// <typeparam name="TResult">The type of the returned result</typeparam> /// <returns>The value passed to <paramref name="result"/> argument wrapped in Task<object></returns> public static Task <object> TaskResult <TActor, TResult>(this ActorMessage <TActor, TResult> message, TResult result) where TActor : IActorGrain, IGrainWithStringKey => Task.FromResult <object>(result);
public Task <Event> PublishWithTranslate(ActorMessage source, ActorMessage destination, RoutingFilter filter = null) { throw new NotImplementedException(); }
//虚方法,用于子类重写 protected virtual void ReceiveMsg(ActorMessage msg) { }
public Task <Event> PublishWithTranslate(ActorMessage source, ActorMessage destination, RoutingFilter filter = null) { return(_messageGenerator.PublishEvent(source, destination, this, filter)); }
protected override void ReceiveMsg(ActorMessage actorMsg) { if (!string.IsNullOrEmpty(actorMsg.msg)) { } }
public void SendWithTranslate(ActorMessage source, ActorMessage destination, string address) { throw new NotImplementedException(); }
/// <summary> /// Helper method to use when building responses for strongly typed messages which return results. /// If the type of returned result is changed in message declaration this will help catching it at compile time. /// </summary> /// <example> /// <para> /// class Query : ActorMessage<MyActor,int>{} /// </para> /// <para> /// int On(Query x) => x.Result(42); /// </para> /// </example> /// <param name="message">The strongly typed message</param> /// <param name="result">The result to return</param> /// <typeparam name="TActor">The type of the actor to which this message belongs</typeparam> /// <typeparam name="TResult">The type of the returned result</typeparam> /// <returns>The value passed to <paramref name="result"/> argument</returns> public static TResult Result <TActor, TResult>(this ActorMessage <TActor, TResult> message, TResult result) where TActor : IActorGrain, IGrainWithStringKey => result;
public async System.Threading.Tasks.Task <HomeCenter.Model.Messages.Events.Event> PublishEvent(ActorMessage source, ActorMessage destination, HomeCenter.Model.Core.IMessageBroker messageBroker, HomeCenter.Broker.RoutingFilter routingFilter) { if (destination.Type == "DipswitchEvent") { var @event = new HomeCenter.Model.Messages.Events.Device.DipswitchEvent(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } else if (destination.Type == "InfraredEvent") { var @event = new HomeCenter.Model.Messages.Events.Device.InfraredEvent(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } else if (destination.Type == "MotionEvent") { var @event = new HomeCenter.Model.Messages.Events.Device.MotionEvent(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } else if (destination.Type == "PinValueChangedEvent") { var @event = new HomeCenter.Model.Messages.Events.Device.PinValueChangedEvent(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } else if (destination.Type == "PowerStateChangeEvent") { var @event = new HomeCenter.Model.Messages.Events.Device.PowerStateChangeEvent(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } else if (destination.Type == "PropertyChangedEvent") { var @event = new HomeCenter.Model.Messages.Events.Device.PropertyChangedEvent(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } else if (destination.Type == "SerialResultEvent") { var @event = new HomeCenter.Model.Messages.Events.Device.SerialResultEvent(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } else if (destination.Type == "ComponentStartedEvent") { var @event = new HomeCenter.Model.Messages.Events.Service.ComponentStartedEvent(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } else if (destination.Type == "SystemStartedEvent") { var @event = new HomeCenter.Model.Messages.Events.Service.SystemStartedEvent(); @event.SetProperties(source); @event.SetProperties(destination); await messageBroker.Publish(@event, routingFilter); return(@event); } { var ev = new HomeCenter.Model.Messages.Events.Event(); ev.SetProperties(source); ev.SetProperties(destination); await messageBroker.Publish(ev, routingFilter); return(ev); } }
internal override void OnActorMessageReceived(ActorMessage actorData) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"Received message for topic: {actorData.Command}"); Console.ForegroundColor = _defaultConsoleColor; }