public static void HelloWorldWithLazyActorInstantiation() { string messageStr = "HelloWorld2."; try { Telegraph.Instance.Register(new LocalQueueOperator()); // performs a reset when we assign a new operator Telegraph.Instance.Register <ValueTypeMessage <byte>, LazyInstantiationActor>(() => new LazyInstantiationActor()); } catch (FailedRegistrationException ex) { Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(ex.GetType().ToString() + ":" + ex.Message); Console.ResetColor(); throw; } for (int i = 0; i < 10; ++i) { IActorMessage msg = new ValueTypeMessage <byte>(Encoding.ASCII.GetBytes(messageStr + i.ToString())); Telegraph.Instance.Tell(msg); } Telegraph.Instance.Ask(new ControlMessages.HangUp()).Wait(); }
private static void TestValType <T>(IActorMessageSerializationActor serialization, IActorMessageDeserializationActor deserialization, T val) where T : IEquatable <T> { ValueTypeMessage <T> intType = new ValueTypeMessage <T>(val); var typeVal = (T)intType.Message; string id = intType.Id; SerializeMessage <IActorMessage> sMsg = new SerializeMessage <IActorMessage>(intType); if (!serialization.OnMessageRecieved(sMsg)) { Assert.Fail(string.Format("Seriaization of {0} Failed", val.GetType().Name)); } DeserializeMessage <IActorMessage> dMsg = new DeserializeMessage <IActorMessage>(sMsg.ProcessingResult as byte[]); if (!deserialization.OnMessageRecieved(dMsg)) { Assert.Fail(string.Format("DeSeriaization of {0} Failed", val.GetType().Name)); } Assert.IsTrue((dMsg.ProcessingResult as ValueTypeMessage <T>).Message.Equals(typeVal)); Assert.IsTrue((dMsg.ProcessingResult as IActorMessageIdentifier).Id.Equals(id)); }
static void LogExceptions() { System.Diagnostics.Debug.WriteLine("LogExceptions"); Telegraph.Instance.Register(new LocalQueueOperator()); // performs a reset. string messageStr = "LogExceptions."; // this is using the sequential local concurrency type which will create a new Actor for each message. DefaultActor da = new DefaultActor(); da.OnMessageHandler = delegate(IActorMessage s) { throw new NullReferenceException(); }; Telegraph.Instance.Register <byte[], DefaultActor>(() => da); Telegraph.Instance.Register(typeof(NullReferenceException), HandleExceptionWithPrintingIt); for (int i = 0; i < 10; ++i) { IActorMessage msg = new ValueTypeMessage <byte>(Encoding.ASCII.GetBytes(messageStr + i.ToString())); Telegraph.Instance.Tell(msg); } Telegraph.Instance.Ask(new ControlMessages.HangUp()).Wait(); }