public void Run(object o) { while (true) { if (!_nodeInfo.HaveAcessRight) { break; } if (!PureCatClient.IsInitialized()) { Thread.Sleep(5000); continue; } PureCatClient.DoTransaction("System", "Status", () => { _nodeInfo.Refresh(); PureCatClient.GetProducer().LogHeartbeat("Heartbeat", AppEnv.IP, PureCatConstants.SUCCESS, XmlHelper.XmlSerialize(_nodeInfo, Encoding.UTF8)); PureCatClient.GetProducer().LogEvent("System", $"PureCat.Version : {PureCatClient.Version}", PureCatConstants.SUCCESS, PureCatClient.Version); }); Thread.Sleep(60000); } }
static void Add(int a, int b, CatContext context = null) { Thread.Sleep(_rand.Next(1000)); PureCatClient.LogRemoteCallServer(context); PureCatClient.LogEvent("Do", nameof(Add), "0", $"{a} + {b} = {a + b}"); Task.Factory.StartNew(() => PureCatClient.DoTransaction("Do", nameof(Add2), () => PureCatClient.LogRemoteCallClient("callAdd2"))); }
static CatContext DoTest() { var times = _rand.Next(1000); Thread.Sleep(times); PureCatClient.LogEvent("Do", nameof(DoTest), "0", $"sleep {times}"); return(PureCatClient.LogRemoteCallClient("callAdd")); }
internal Context GetContext() { if (PureCatClient.IsInitialized()) { var ctx = _mContext.Value; if (ctx != null) { return(ctx); } } return(null); }
static void Main(string[] args) { PureCatClient.Initialize(); while (true) { var a = DateTime.Now.Second; Console.WriteLine(DateTime.Now); var context = PureCatClient.DoTransaction("Do", nameof(DoTest), DoTest); var b = DateTime.Now.Second; PureCatClient.DoTransaction("Do", nameof(Add), () => Add(a, b, context)); Thread.Sleep(5000); } }
public DefaultForkedTransaction(string type, string name, IMessageManager messageManager) : base(type, name, messageManager) { Standalone = false; IMessageTree tree = messageManager.ThreadLocalMessageTree; if (tree != null) { _rootMessageId = tree.RootMessageId; _parentMessageId = tree.MessageId; // Detach parent transaction and this forked transaction, by calling linkAsRunAway(), at this earliest moment, // so that thread synchronization is not needed at all between them in the future. _forkedMessageId = PureCatClient.CreateMessageId(); } }
public ITransaction AddChild(IMessage message) { if (_mChildren == null) { _mChildren = new List <IMessage>(); } if (message != null) { _mChildren.Add(message); } else { PureCatClient.GetProducer().LogError(new Exception("null child message")); } return(this); }
static void Add2(int a, int b, CatContext context = null) { Thread.Sleep(_rand.Next(1000)); PureCatClient.LogRemoteCallServer(context); PureCatClient.LogEvent("Do", nameof(Add2), "0", $"{a} + {b} = {a + b}"); }