public static NodeSettings BiserJsonDecode(string enc = null, Biser.JsonDecoder extDecoder = null, Biser.JsonSettings settings = null) //!!!!!!!!!!!!!! change return type { Biser.JsonDecoder decoder = null; if (extDecoder == null) { if (enc == null || String.IsNullOrEmpty(enc)) { return(null); } decoder = new Biser.JsonDecoder(enc, settings); if (decoder.CheckNull()) { return(null); } } else { //JSONSettings of the existing decoder will be used decoder = extDecoder; } NodeSettings m = new NodeSettings(); //!!!!!!!!!!!!!! change return type foreach (var props in decoder.GetDictionary <string>()) { switch (props) { case "RaftEntitiesSettings": m.RaftEntitiesSettings = decoder.CheckNull() ? null : new List <RaftEntitySettings>(); if (m.RaftEntitiesSettings != null) { foreach (var el in decoder.GetList()) { m.RaftEntitiesSettings.Add(RaftEntitySettings.BiserJsonDecode(null, decoder)); } } break; case "TcpClusterEndPoints": m.TcpClusterEndPoints = decoder.CheckNull() ? null : new List <TcpClusterEndPoint>(); if (m.TcpClusterEndPoints != null) { foreach (var el in decoder.GetList()) { m.TcpClusterEndPoints.Add(TcpClusterEndPoint.BiserJsonDecode(null, decoder)); } } break; default: decoder.SkipValue(); //MUST BE HERE break; } } return(m); } //eof
/// <summary> /// /// </summary> /// <param name="settings"></param> /// <param name="dbreezePath"></param> /// <param name="raftSender"></param> /// <param name="log"></param> /// <param name="OnCommit"></param> public RaftNode(RaftEntitySettings settings, DBreezeEngine dbEngine, IRaftComSender raftSender, IWarningLog log, Func <string, ulong, byte[], bool> OnCommit) { this.Log = log ?? throw new Exception("Raft.Net: ILog is not supplied"); this.OnCommit = OnCommit ?? throw new Exception("Raft.Net: OnCommit can'T be null"); this.db = dbEngine; Sender = raftSender; entitySettings = settings; //Starting time master this.TM = new TimeMaster(log); //Starting state logger NodeStateLog = new StateLog(this); }
/// <summary> /// /// </summary> /// <param name="settings"></param> /// <param name="dbEngine"></param> /// <param name="raftSender"></param> /// <param name="log"></param> /// <param name="OnCommit"></param> public RaftStateMachine(RaftEntitySettings settings, string workPath, IPeerConnector raftSender, IWarningLog log, IBusinessHandler handler) { this.Log = log ?? throw new Exception("Raft.Net: ILog is not supplied"); network = raftSender; entitySettings = settings; //Starting time master var TM = new TimeMaster(log); this.timerLoop = new StateMachineTimerLoop(TM, settings, this); //Starting state logger NodeStateLog = StateLogFactory.GetLog(this, workPath); this.logHandler = new StateMachineLogHandler(this, NodeStateLog, handler); //Adding AddLogEntryAsync cleanup this.timerLoop.StartClearup(); }
public static RaftEntitySettings BiserJsonDecode(string enc = null, Biser.JsonDecoder extDecoder = null, Biser.JsonSettings settings = null) //!!!!!!!!!!!!!! change return type { Biser.JsonDecoder decoder = null; if (extDecoder == null) { if (enc == null || String.IsNullOrEmpty(enc)) { return(null); } decoder = new Biser.JsonDecoder(enc, settings); if (decoder.CheckNull()) { return(null); } } else { //JSONSettings of the existing decoder will be used decoder = extDecoder; } RaftEntitySettings m = new RaftEntitySettings(); //!!!!!!!!!!!!!! change return type foreach (var props in decoder.GetDictionary <string>()) { switch (props) { case "EntityName": m.EntityName = decoder.GetString(); break; //case "LeaderHeartbeatMs": // m.LeaderHeartbeatMs = decoder.GetUInt(); // break; case "DelayedPersistenceMs": m.DelayedPersistenceMs = decoder.GetUInt(); break; //case "NoLeaderAddCommandResendIntervalMs": // m.NoLeaderAddCommandResendIntervalMs = decoder.GetUInt(); // break; case "DelayedPersistenceIsActive": m.DelayedPersistenceIsActive = decoder.GetBool(); break; case "InMemoryEntity": m.InMemoryEntity = decoder.GetBool(); break; case "InMemoryEntityStartSyncFromLatestEntity": m.InMemoryEntityStartSyncFromLatestEntity = decoder.GetBool(); break; //case "ElectionTimeoutMinMs": // m.ElectionTimeoutMinMs = decoder.GetInt(); // break; //case "ElectionTimeoutMaxMs": // m.ElectionTimeoutMaxMs = decoder.GetInt(); // break; //case "LeaderLogResendIntervalMs": // m.LeaderLogResendIntervalMs = decoder.GetUInt(); // break; //case "RaftNodeIdExternalForEmulator": // m.RaftNodeIdExternalForEmulator = decoder.GetInt(); // break; //case "InitialQuantityOfRaftNodesInTheCluster": // m.InitialQuantityOfRaftNodesInTheCluster = decoder.GetUInt(); // break; case "VerboseRaft": m.VerboseRaft = decoder.GetBool(); break; case "VerboseTransport": m.VerboseTransport = decoder.GetBool(); break; default: decoder.SkipValue(); //MUST BE HERE break; } } return(m); } //eof