/// <summary> /// /// </summary> /// <param name="jsonConfiguration">json representation of Raft.NodeSettings</param> /// <param name="dbreezePath"></param> /// <param name="port"></param> /// <param name="log"></param> /// <param name="OnCommit"></param> /// <returns></returns> public static TcpRaftNode GetFromConfig(string jsonConfiguration, string dbreezePath, int port, IWarningLog log, Func <string, ulong, byte[], bool> OnCommit) { try { TcpRaftNode rn = null; NodeSettings ns = NodeSettings.BiserJsonDecode(jsonConfiguration); //Biser.JsonEncoder encc = new Biser.JsonEncoder(new NodeSettings() { TcpClusterEndPoints = eps, RaftEntitiesSettings = reSettings }); //var str = encc.GetJSON(Biser.JsonSettings.JsonStringStyle.Prettify); //NodeSettings nhz = NodeSettings.BiserJsonDecode(str); //encc = new Biser.JsonEncoder(nhz); //str = encc.GetJSON(Biser.JsonSettings.JsonStringStyle.Prettify); rn = new TcpRaftNode(ns, dbreezePath, OnCommit, port, log); return(rn); } catch (Exception ex) { if (log != null) { log.Log(new WarningLogEntry { LogType = WarningLogEntry.eLogType.ERROR, Exception = ex, Method = "TcpRaftNode.GetFromConfig JSON" }); } } return(null); }
public TcpPeer(TcpClient client, TcpRaftNode rn) { _client = client; trn = rn; try { stream = _client.GetStream(); SetupSprot(); } catch (Exception ex) { return; } trn.GetNodeByEntityName("default").TM.FireEventEach(10000, (o) => { if (Handshake == null) { this.Dispose(); } }, null, true); Task.Run(async() => await Read()); }
public TcpSpider(TcpRaftNode trn) { this.trn = trn; }
public TcpPeer(string hostname, int port, TcpRaftNode rn) { trn = rn; Task.Run(async() => await Connect(hostname, port)); }
public static TcpRaftNode GetFromConfig(int configVersion, string configuration, string dbreezePath, int port, IWarningLog log, Func <string, ulong, byte[], bool> OnCommit) { //Setip for configVersion=1 try { TcpRaftNode rn = null; var re_settings = new RaftEntitySettings() { EntityName = "default", VerboseRaft = false, VerboseTransport = false }; string[] sev; List <TcpClusterEndPoint> eps = new List <TcpClusterEndPoint>(); List <RaftEntitySettings> reSettings = new List <RaftEntitySettings>(); string entityName = ""; StringReader strReader = new StringReader(configuration); while (true) { var el = strReader.ReadLine(); if (el == null) { break; } var se = el.Split(new char[] { ':' }); if (se.Length < 2) { continue; } switch (se[0].Trim().ToLower()) { case "endpoint": sev = se[1].Split(new char[] { ',' }); eps.Add(new TcpClusterEndPoint() { Host = sev[0].Trim(), Port = Convert.ToInt32(sev[1].Trim()) }); break; //case "dbreeze": // dbreeze = String.Join(":",se.Skip(1)); // break; case "entity": entityName = se[1].Trim(); if (entityName.ToLower().Equals("default")) { continue; } //flushing default entity and starting new one if (String.IsNullOrEmpty(entityName)) { throw new Exception("Raft.Net: configuration entity name must not be empty and must be unique among other entities"); } reSettings.Add(re_settings); re_settings = new RaftEntitySettings { EntityName = entityName }; break; case "verboseraft": if (se[1].Trim().ToLower().Equals("true")) { re_settings.VerboseRaft = true; } break; case "verbosetransport": if (se[1].Trim().ToLower().Equals("true")) { re_settings.VerboseTransport = true; } break; case "delayedpersistenceisactive": if (se[1].Trim().ToLower().Equals("true")) { re_settings.DelayedPersistenceIsActive = true; } break; case "delayedpersistencems": re_settings.DelayedPersistenceMs = Convert.ToUInt32(se[1].Trim()); break; case "inmemoryentity": if (se[1].Trim().ToLower().Equals("true")) { re_settings.InMemoryEntity = true; } break; case "inmemoryentitystartsyncfromlatestentity": if (se[1].Trim().ToLower().Equals("true")) { re_settings.InMemoryEntityStartSyncFromLatestEntity = true; } break; }//DelayedPersistenceMs } reSettings.Add(re_settings); rn = new TcpRaftNode(new NodeSettings() { TcpClusterEndPoints = eps, RaftEntitiesSettings = reSettings }, dbreezePath, OnCommit, port, log); return(rn); } catch (Exception ex) { throw ex; } }