public ConfigurationRequestHandler(
     IRequestManager<ConfigurationSubscription, ConfigurationSubscriptionAnswer> subscriptionsRequestSource,
     IRequestManager<ConfigurationUpdate, ConfigurationUpdateAnswer> updateRequestManager, 
     IStatePersister persister)
 {
     this.persister = persister;
     this.allConfigurations = persister.Read();
     subscriptionsRequestSource.OnRequest += (sender, message) => OnNewSubscription(subscriptionsRequestSource,message);
     updateRequestManager.OnRequest += (sender, message) => OnNewUpdate(updateRequestManager,message);
 }
Beispiel #2
0
        public AutoPersistentState(IStatePersister persister)
        {
            if (persister == null)
            {
                throw new ArgumentNullException("persister");
            }

            _persister = persister;
            var state = persister.Load();

            base.Id             = state.Id;
            base.CurrentTerm    = state.CurrentTerm;
            base.LastVotedForId = state.LastVotedForId;
        }
Beispiel #3
0
        /// <summary>
        /// Aggregates two states loaded by the state loader and saves the resulting aggregation using the target state
        /// persister.
        /// </summary>
        /// <param name="sourceA">The first state to load <see cref="IStateLoader"/></param>
        /// <param name="sourceB">The second state to load <see cref="IStateLoader"/></param>
        /// <param name="target">The target persister <see cref="IStatePersister"/></param>
        public void AggregateStateTo(IStateLoader sourceA, IStateLoader sourceB, IStatePersister target)
        {
            Option <S> maybeStateA = sourceA.Load <S>(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this));
            Option <S> maybeStateB = sourceB.Load <S>(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this));

            S aggregated = (maybeStateA.HasValue, maybeStateB.HasValue) switch
            {
                (true, true) => maybeStateA.Value.Sum(maybeStateB.Value),
                (true, false) => maybeStateA.Value,
                (false, true) => maybeStateB.Value,
                _ => null
            };

            target.Persist(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this), new Option <S>(aggregated));
        }
Beispiel #4
0
 public DefaultRaftServer(
     ILogPersister logPersister,
     IStatePersister statePersister,
     ISnapshotOperator snapshotOperator,
     IStateMachine stateMachine,
     IPeerManager peerManager,
     RaftServerSettings settings,
     Peer meAsAPeer = null,
     IChaos chaos   = null)
 {
     _logPersister     = logPersister;
     _peerManager      = peerManager;
     _stateMachine     = stateMachine;
     _snapshotOperator = snapshotOperator;
     _settings         = settings;
     _state            = new AutoPersistentState(statePersister);
     _meAsAPeer        = meAsAPeer ?? new Peer("NoAddress", State.Id);
     _chaos            = chaos ?? new NoChaos();
 }
Beispiel #5
0
        private void WebFormView_Init(object sender, EventArgs e)
        {
            IWindsorContainer container = ContainerWebAccessorUtil.ObtainContainer();

            // Get the State
            IStatePersister statePersister = (IStatePersister)container[typeof(IStatePersister)];

            _state = statePersister.Load();
            // Acquire current view
            _state.CurrentView = ConfigUtil.Settings.GetView(this.Request.Path);
            _state.Save();

            ControllerTree tree = (ControllerTree)container["mvc.controllerTree"];
            PropertyControllerCollection propertiesController = tree.GetControllers(this.GetType().BaseType);

            if (propertiesController != null)
            {
                for (int i = 0; i < propertiesController.Count; i++)
                {
                    IController controller = container[propertiesController[i].ControllerType] as IController;
                    propertiesController[i].PropertyInfo.SetValue(this, controller, null);
                }
            }
        }
Beispiel #6
0
 /// <summary>
 /// Copy the state from source to target.
 /// </summary>
 /// <param name="source">The <see cref="IStateLoader"/> to read from.</param>
 /// <param name="target">The <see cref="IStatePersister"/> to write to.</param>
 public void CopyStateTo(IStateLoader source, IStatePersister target) =>
 target.Persist(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this), source.Load <S>(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this)));
Beispiel #7
0
 /// <summary>
 /// Save analyzer states.  Enables aggregate computation of metrics later, e.g., when a new partition is added to the dataset.
 /// </summary>
 /// <param name="statePersister">A state persister that saves the computed states for later aggregation.</param>
 /// <returns></returns>
 public VerificationRunBuilder SaveStateWith(IStatePersister statePersister)
 {
     this.statePersister = new Option <IStatePersister>(statePersister);
     return(this);
 }
Beispiel #8
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="viewManager">A view manager</param>
		/// <param name="statePersister">A state persister</param>
		public DefaultNavigator(IViewManager viewManager,IStatePersister statePersister)
		{
			_viewManager = viewManager;
			_statePersister = statePersister;
			_state = _statePersister.Load();
		}
 public void Setup()
 {
     _stateFactory = new StateFactory();
     _persister = new StatePersister();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="viewManager">A view manager</param>
 /// <param name="statePersister">A state persister</param>
 public DefaultNavigator(IViewManager viewManager, IStatePersister statePersister)
 {
     _viewManager    = viewManager;
     _statePersister = statePersister;
     _state          = _statePersister.Load();
 }
Beispiel #11
0
 public Machine(IStateFactory stateFactory, IStatePersister persister)
 {
     _stateFactory = stateFactory;
     _persister = persister;
 }