public void ManageSubscriptions() { var bus = new EventStream(true); bus.Subscribe(TestActor, typeof(M)); bus.Publish(new M { Value = 42 }); ExpectMsg(new M { Value = 42 }); bus.Unsubscribe(TestActor); bus.Publish(new M { Value = 43 }); ExpectNoMsg(TimeSpan.FromSeconds(1)); }
public void ManageSubscriptions() { var bus = new EventStream(true); bus.StartUnsubscriber(Sys.AsInstanceOf<ActorSystemImpl>()); bus.Subscribe(TestActor, typeof(M)); bus.Publish(new M { Value = 42 }); ExpectMsg(new M { Value = 42 }); bus.Unsubscribe(TestActor); bus.Publish(new M { Value = 43 }); ExpectNoMsg(TimeSpan.FromSeconds(1)); }
protected override bool Receive(object message) { var deadLetter = (DeadLetter)message; var snd = deadLetter.Sender; var rcp = deadLetter.Recipient; _count++; var done = _maxCount != int.MaxValue && _count >= _maxCount; var doneMsg = done ? ", no more dead letters will be logged" : ""; if (!done) { var rcpPath = rcp == ActorRefs.NoSender ? "NoSender" : rcp.Path.ToString(); var sndPath = snd == ActorRefs.NoSender ? "NoSender" : snd.Path.ToString(); _eventStream.Publish(new Info(rcpPath, rcp.GetType(), string.Format("Message {0} from {1} to {2} was not delivered. {3} dead letters encountered.{4}", deadLetter.Message.GetType().Name, sndPath, rcpPath, _count, doneMsg))); } if (done) { ((IInternalActorRef)Self).Stop(); } return(true); }
/// <summary> /// Processor for user defined messages. /// </summary> /// <param name="message">The message.</param> protected override void OnReceive(object message) { var deadLetter = (DeadLetter)message; ActorRef snd = deadLetter.Sender; ActorRef rcp = deadLetter.Recipient; count++; bool done = maxCount != int.MaxValue && count >= maxCount; string doneMsg = done ? ", no more dead letters will be logged" : ""; if (!done) { string rcpPath = ""; if (rcp == ActorRef.NoSender) { rcpPath = "NoSender"; } string sndPath = ""; if (snd == ActorRef.NoSender) { sndPath = "NoSender"; } eventStream.Publish(new Info(rcpPath, rcp.GetType(), string.Format("Message {0} from {1} to {2} was not delivered. {3} dead letters encountered.{4}", deadLetter.Message.GetType().Name, sndPath, rcpPath, count, doneMsg))); } if (done) { Self.Stop(); } }
/// <summary> /// TBD /// </summary> /// <param name="message">TBD</param> /// <returns>TBD</returns> protected override bool Receive(object message) { var deadLetter = (DeadLetter)message; var snd = deadLetter.Sender; var rcp = deadLetter.Recipient; _count++; var done = _maxCount != int.MaxValue && _count >= _maxCount; var doneMsg = done ? ", no more dead letters will be logged" : ""; if (!done) { var rcpPath = rcp == ActorRefs.NoSender ? "NoSender" : rcp.Path.ToString(); var sndPath = snd == ActorRefs.NoSender ? "NoSender" : snd.Path.ToString(); _eventStream.Publish(new Info(rcpPath, rcp.GetType(), $"Message [{deadLetter.Message.GetType().Name}] from {sndPath} to {rcpPath} was not delivered. [{_count}] dead letters encountered {doneMsg}." + "This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' " + "and 'akka.log-dead-letters-during-shutdown'.")); } if (done) { Context.Stop(Self); } return(true); }
private void LogDeadLetter(object message, IActorRef snd, IActorRef recipient, string doneMsg) { var origin = ReferenceEquals(snd, Context.System.DeadLetters) ? "without sender" : $"from {snd.Path}"; _eventStream.Publish(new Info( recipient.Path.ToString(), recipient.GetType(), $"Message [{message.GetType().Name}] {origin} to {recipient.Path} was not delivered. [{_count.ToString()}] dead letters encountered{doneMsg}. " + $"If this is not an expected behavior then {recipient.Path} may have terminated unexpectedly. " + "This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' " + "and 'akka.log-dead-letters-during-shutdown'.")); }
private void LogDeadLetter(AllDeadLetters d, string doneMsg) { var origin = IsReal(d.Sender) ? $" from {d.Sender}" : ""; var unwrapped = WrappedMessage.Unwrap(d.Message); var messageStr = unwrapped?.GetType().Name ?? "null"; var wrappedIn = (d.Message is IWrappedMessage) ? $" wrapped in [${d.Message.GetType().Name}]" : ""; string logMessage; switch (d) { case Dropped dropped: var destination = IsReal(d.Recipient) ? $" to {d.Recipient}" : ""; logMessage = $"Message [{messageStr}]{wrappedIn}{origin}{destination} was dropped. {dropped.Reason}. " + $"[{_count}] dead letters encountered{doneMsg}. "; break; case UnhandledMessage unhandled: destination = IsReal(d.Recipient) ? $" to {d.Recipient}" : ""; logMessage = $"Message [{messageStr}]{wrappedIn}{origin}{destination} was unhandled. " + $"[{_count}] dead letters encountered{doneMsg}. "; break; default: logMessage = $"Message [{messageStr}]{wrappedIn}{origin} to {d.Recipient} was not delivered. " + $"[{_count}] dead letters encountered{doneMsg}. " + $"If this is not an expected behavior then {d.Recipient} may have terminated unexpectedly. "; break; } _eventStream.Publish(new Info( d.Recipient.Path.ToString(), d.Recipient.GetType(), logMessage + "This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' " + "and 'akka.log-dead-letters-during-shutdown'.")); }
public void ManageLogLevels() { var bus = new EventStream(false); bus.StartDefaultLoggers((ActorSystemImpl)Sys); bus.Publish(new SetTarget(TestActor)); ExpectMsg("OK", TimeSpan.FromSeconds(5)); verifyLevel(bus, LogLevel.InfoLevel); bus.SetLogLevel(LogLevel.WarningLevel); verifyLevel(bus, LogLevel.WarningLevel); bus.SetLogLevel(LogLevel.DebugLevel); verifyLevel(bus, LogLevel.DebugLevel); bus.SetLogLevel(LogLevel.ErrorLevel); verifyLevel(bus, LogLevel.ErrorLevel); }
public void ManageSubChannelsUsingClassesAndInterfacesUpdateOnUnsubscribeAll() { var es = new EventStream(false); var tm1 = new CC(); var tm2 = new CCATBT(); var a1 = CreateTestProbe(); var a2 = CreateTestProbe(); var a3 = CreateTestProbe(); var a4 = CreateTestProbe(); es.Subscribe(a1.Ref, typeof(AT)).ShouldBeTrue(); es.Subscribe(a2.Ref, typeof(BT)).ShouldBeTrue(); es.Subscribe(a3.Ref, typeof(CC)).ShouldBeTrue(); es.Subscribe(a4.Ref, typeof(CCATBT)).ShouldBeTrue(); es.Unsubscribe(a3.Ref).ShouldBeTrue(); es.Publish(tm1); es.Publish(tm2); a1.ExpectMsg((object)tm2); a2.ExpectMsg((object)tm2); a3.ExpectNoMsg(TimeSpan.FromSeconds(1)); a4.ExpectMsg((object)tm2); es.Unsubscribe(a1.Ref, typeof(AT)).ShouldBeTrue(); es.Unsubscribe(a2.Ref, typeof(BT)).ShouldBeTrue(); es.Unsubscribe(a3.Ref, typeof(CC)).ShouldBeFalse(); es.Unsubscribe(a4.Ref, typeof(CCATBT)).ShouldBeTrue(); }
public void ManageSubChannelsUsingClasses() { var a = new A(); var b1 = new B1(); var b2 = new B2(); var c = new C(); var bus = new EventStream(false); bus.Subscribe(TestActor, typeof(B2)); bus.Publish(c); bus.Publish(b2); ExpectMsg(b2); bus.Subscribe(TestActor, typeof(A)); bus.Publish(c); ExpectMsg(c); bus.Publish(b1); ExpectMsg(b1); bus.Unsubscribe(TestActor, typeof(B1)); bus.Publish(c); //should not publish bus.Publish(b2); //should publish bus.Publish(a); //should publish ExpectMsg(b2); ExpectMsg(a); ExpectNoMsg(TimeSpan.FromSeconds(1)); }
public void ManageSubChannelsUsingClassesAndInterfacesUpdateOnUnsubscribeAll() { var es = new EventStream(false); var tm1 = new CC(); var tm2 = new CCATBT(); var a1 = TestProbe(); var a2 = TestProbe(); var a3 = TestProbe(); var a4 = TestProbe(); es.Subscribe(a1.Ref, typeof(AT)).Then(Assert.True); es.Subscribe(a2.Ref, typeof(BT)).Then(Assert.True); es.Subscribe(a3.Ref, typeof(CC)).Then(Assert.True); es.Subscribe(a4.Ref, typeof(CCATBT)).Then(Assert.True); es.Unsubscribe(a3.Ref).Then(Assert.True); es.Publish(tm1); es.Publish(tm2); a1.expectMsg(tm2); a2.expectMsg(tm2); a3.expectNoMsg(TimeSpan.FromSeconds(1)); a4.expectMsg(tm2); es.Unsubscribe(a1.Ref, typeof(AT)).Then(Assert.True); es.Unsubscribe(a2.Ref, typeof(BT)).Then(Assert.True); es.Unsubscribe(a3.Ref, typeof(CC)).Then(Assert.False); es.Unsubscribe(a4.Ref, typeof(CCATBT)).Then(Assert.True); }
public void ManageLogLevels() { var bus = new EventStream(false); bus.StartDefaultLoggers(sys); bus.Publish(new SetTarget(testActor)); expectMsg("OK"); verifyLevel(bus, LogLevel.InfoLevel); bus.SetLogLevel(LogLevel.WarningLevel); verifyLevel(bus, LogLevel.WarningLevel); bus.SetLogLevel(LogLevel.DebugLevel); verifyLevel(bus, LogLevel.DebugLevel); bus.SetLogLevel(LogLevel.ErrorLevel); verifyLevel(bus, LogLevel.ErrorLevel); }
public void Manage_sub_channels_using_classes_and_interfaces_update_on_unsubscribe() { var es = new EventStream(false); var tm1 = new CC(); var tm2 = new CCATBT(); var a1 = CreateTestProbe(); var a2 = CreateTestProbe(); var a3 = CreateTestProbe(); var a4 = CreateTestProbe(); es.Subscribe(a1.Ref, typeof(AT)); es.Subscribe(a2.Ref, typeof(BT)); es.Subscribe(a3.Ref, typeof(CC)); es.Subscribe(a4.Ref, typeof(CCATBT)); es.Unsubscribe(a3.Ref, typeof(CC)); es.Publish(tm1); es.Publish(tm2); a1.ExpectMsg((object)tm2); a2.ExpectMsg((object)tm2); a3.ExpectNoMsg(TimeSpan.FromSeconds(1)); a4.ExpectMsg((object)tm2); es.Unsubscribe(a1.Ref, typeof(AT)).ShouldBeTrue(); es.Unsubscribe(a2.Ref, typeof(BT)).ShouldBeTrue(); es.Unsubscribe(a3.Ref, typeof(CC)).ShouldBeFalse(); es.Unsubscribe(a4.Ref, typeof(CCATBT)).ShouldBeTrue(); }