Exemple #1
0
        public RaftServiceNode(NodeSettings nodeSettings, string dbreezePath, IBusinessHandler handler, int port = 4250, string nodeName = "default", IWarningLog log = null)
        {
            if (nodeSettings == null)
            {
                nodeSettings = new NodeSettings();
            }
            this.NodeSettings = nodeSettings;
            this.NodeName     = nodeName;
            this.log          = log;
            this.port         = port;

            peerNetwork = new TcpPeerNetwork(this);
            //bool firstNode = true;
            if (this.NodeSettings.RaftEntitiesSettings == null)
            {
                this.NodeSettings.RaftEntitiesSettings = new RaftEntitySettings();
            }
            var re_settings = this.NodeSettings.RaftEntitiesSettings;

            if (String.IsNullOrEmpty(re_settings.EntityName))
            {
                throw new Exception("Raft.Net: entities must have unique names. Change RaftNodeSettings.EntityName.");
            }

            var rn = new RaftStateMachine(re_settings ?? new RaftEntitySettings(), dbreezePath, this.peerNetwork, this.log, handler);

            rn.SetNodesQuantityInTheCluster((uint)this.NodeSettings.TcpClusterEndPoints.Count);
            rn.NodeAddress.NodeAddressId = port; //for debug/emulation purposes

            rn.NodeAddress.NodeUId = Guid.NewGuid().ToByteArray().Substring(8, 8).To_Int64_BigEndian();
            rn.NodeName            = this.NodeName;
            this.raftNode          = rn;
            rn.NodeStart();
        }
 public HttpRaftServiceNode(NodeSettings nodeSettings,
                            string dbreezePath,
                            IBusinessHandler handler,
                            int port        = 4250,
                            string nodeName = "default",
                            int httpPort    = 10000,
                            ServiceChannelAdapter adapter = null,
                            IWarningLog log = null)
     : base(nodeSettings, dbreezePath, handler, port, nodeName, log)
 {
     this.httpPort = httpPort;
     this.adapter  = adapter;
     handler.SetNode(this);
     this.adapter.SetNode(this);
 }
Exemple #3
0
 public StateMachineLogHandler(RaftStateMachine stateMachine, IStateLog log, IBusinessHandler handler)
 {
     this.stateMachine         = stateMachine;
     this.log                  = log;
     this.businessLogicHandler = handler;
 }
Exemple #4
0
        /// <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();
        }