Ejemplo n.º 1
0
        /// <summary>
        /// This patches the booked instances that are pending in case the configuration of the cluster changes. This
        /// should be called only when we learn a ConfigurationChangeState i.e. when we receive an accepted for
        /// such a message. This won't "learn" the message, as in applying it on the cluster configuration, but will
        /// just update properly the set of acceptors for pending instances.
        /// </summary>
        public override void PatchBookedInstances(ClusterMessage.ConfigurationChangeState value)
        {
            if (value.Join != null)
            {
                foreach (InstanceId instanceId in _bookedInstances.Keys)
                {
                    PaxosInstance instance = _paxosInstances.getPaxosInstance(instanceId);
                    if (instance.Acceptors != null)
                    {
                        instance.Acceptors.Remove(CommonState.configuration().Members[value.Join]);

                        GetLog(typeof(ProposerContext)).debug("For booked instance " + instance + " removed gone member " + CommonState.configuration().Members[value.Join] + " added joining member " + value.JoinUri);

                        if (!instance.Acceptors.Contains(value.JoinUri))
                        {
                            instance.Acceptors.Add(value.JoinUri);
                        }
                    }
                }
            }
            else if (value.Leave != null)
            {
                foreach (InstanceId instanceId in _bookedInstances.Keys)
                {
                    PaxosInstance instance = _paxosInstances.getPaxosInstance(instanceId);
                    if (instance.Acceptors != null)
                    {
                        GetLog(typeof(ProposerContext)).debug("For booked instance " + instance + " removed leaving member " + value.Leave + " (at URI " + CommonState.configuration().Members[value.Leave] + ")");
                        instance.Acceptors.Remove(CommonState.configuration().Members[value.Leave]);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void Elected(string roleName, InstanceId instanceId, InstanceId electorId, long version)
        {
            if (electorId != null)
            {
                if (electorId.Equals(MyId))
                {
                    GetLog(this.GetType()).debug("I elected instance " + instanceId + " for role " + roleName + " at version " + version);
                    if (version < _electorVersion)
                    {
                        return;
                    }
                }
                else if (electorId.Equals(_lastElector) && (version < _electorVersion && version > 1))
                {
                    GetLog(this.GetType()).warn("Election result for role " + roleName + " received from elector instance " + electorId + " with version " + version + ". I had version " + _electorVersion + " for elector " + _lastElector);
                    return;
                }
                else
                {
                    GetLog(this.GetType()).debug("Setting elector to " + electorId + " and its version to " + version);
                }

                this._electorVersion = version;
                this._lastElector    = electorId;
            }
            CommonState.configuration().elected(roleName, instanceId);
            _clusterListeners.notify(_executor, listener => listener.elected(roleName, instanceId, CommonState.configuration().getUriForId(instanceId)));
        }
Ejemplo n.º 3
0
 public ZText(ZEngine p_gameReference, CommonState p_state, string p_text, int p_width)
     : base(p_gameReference)
 {
     m_state = p_state;
     m_text  = p_text;
     m_width = p_width;
 }
Ejemplo n.º 4
0
        public override Task OnGameLogicTick()
        {
            CommonState common = RaceClient.Instance.States.GetState <CommonState>();

            Player  player    = new Player(PlayerId());
            Ped     playerPed = player.Character;
            Vector3 position  = playerPed.Position;
            Vector3 rotation  = playerPed.Rotation;
            Vector3 forward   = playerPed.ForwardVector;
            float   heading   = playerPed.Heading;

            common.LocalPlayer.Set(player, true);
            common.LocalPlayerPosition = position;
            common.LocalPlayerRotation = rotation;
            common.LocalPlayerHeading  = heading;

            //Ordered in clockwise (forward, right, back, left, up, down).
            common.LocalPlayerDirections = new Vector3[]
            {
                playerPed.ForwardVector,
                playerPed.RightVector,
                -playerPed.ForwardVector,
                -playerPed.RightVector,
                playerPed.UpVector,
                -playerPed.UpVector
            };

            return(Task.FromResult(0));
        }
Ejemplo n.º 5
0
        public override bool HasQuorum()
        {
            int availableMembers = ( int )Iterables.count(_heartbeatContext.Alive);
            int totalMembers     = CommonState.configuration().Members.Count;

            return(Quorums.isQuorum(availableMembers, totalMembers));
        }
Ejemplo n.º 6
0
 private ThreadSafeStream(ThreadSafeStream toClone)
 {
     _common = toClone._common;
     if (_common == null)
     {
         throw new ObjectDisposedException("toClone");
     }
 }
Ejemplo n.º 7
0
 public ZAnimation(ZEngine p_gameReference, CommonState p_state, int p_frameHeight, int p_frameWidth, int p_ticksBetweenFrames)
     : base(p_gameReference)
 {
     this.m_state              = p_state;
     this.m_frameHeight        = p_frameHeight;
     this.m_frameWidth         = p_frameWidth;
     this.m_ticksBetweenFrames = p_ticksBetweenFrames;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Copy constructor.
        /// </summary>
        private FlowState(CommonState /*!*/ common, TypeRefMask[] /*!*/ varsType)
        {
            Contract.ThrowIfNull(common);
            Contract.ThrowIfNull(varsType);

            _common   = common;
            _varsType = (TypeRefMask[])varsType.Clone();
        }
Ejemplo n.º 9
0
 public override void LearnedInstanceId(long instanceId)
 {
     this._lastLearnedInstanceId = Math.Max(_lastLearnedInstanceId, instanceId);
     if (_lastLearnedInstanceId > CommonState.lastKnownLearnedInstanceInCluster())
     {
         CommonState.setLastKnownLearnedInstanceInCluster(_lastLearnedInstanceId, null);
     }
 }
Ejemplo n.º 10
0
 public void Init()
 {
     page                   = _page.LIBRARIAN;
     colorSettings          = new ColorSettings(_colorSettings.LIGHT);
     borderThicknesSettings = new BorderThicknesSettings(2);
     commonState            = new CommonState();
     commonState.midi       = DependencyService.Get <IMidi>();
     rawData                = new byte[0];
     initDone               = true;
 }
Ejemplo n.º 11
0
        public override InstanceId NewInstanceId()
        {
            // Never propose something lower than last received instance id
            if (CommonState.lastKnownLearnedInstanceInCluster() >= CommonState.nextInstanceId())
            {
                CommonState.NextInstanceId = CommonState.lastKnownLearnedInstanceInCluster() + 1;
            }

            return(new InstanceId(CommonState.AndIncrementInstanceId));
        }
Ejemplo n.º 12
0
        public void OnCreatorStart(string trackName)
        {
            CommonState common = RC.States.GetState <CommonState>();

            if (!common.IsInRace.Get() && !common.IsInCreator.Get())
            {
                common.IsInCreator.Set(true);
                ChatHelper.SendMessage("Creator", $"Creator mode enabled, now creating track {trackName}", 0, 255, 0);
            }
        }
Ejemplo n.º 13
0
        public override void Left(InstanceId node)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.net.URI member = commonState.configuration().getUriForId(node);
            URI member = CommonState.configuration().getUriForId(node);

            CommonState.configuration().left(node);
            InvalidateElectorIfNecessary(node);
            _clusterListeners.notify(_executor, listener => listener.leftCluster(node, member));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Initial locals state for the Start block.
        /// </summary>
        internal FlowState(FlowContext /*!*/ flowcontext, CommonState /*!*/ common)
        {
            Contract.ThrowIfNull(flowcontext);

            _common          = common;
            _initializedMask = (ulong)0;

            var count = flowcontext.Locals.Length;

            _varsType = new TypeRefMask[count];
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates a new instance, wrapping an existing stream.
        /// </summary>
        /// <param name="toWrap">The stream to wrap</param>
        /// <param name="ownership">Whether to transfer ownership of <c>toWrap</c> to the new instance</param>
        /// <remarks>Do not directly modify <c>toWrap</c> after wrapping it, unless the thread-safe views
        /// will no longer be used.</remarks>
        public ThreadSafeStream(SparseStream toWrap, Ownership ownership)
        {
            if (!toWrap.CanSeek)
            {
                throw new ArgumentException("Wrapped stream must support seeking", "toWrap");
            }

            _common = new CommonState {
                WrappedStream = toWrap,
                WrappedStreamOwnership = ownership };
            _ownsCommon = true;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates a new instance, wrapping an existing stream.
        /// </summary>
        /// <param name="toWrap">The stream to wrap</param>
        /// <param name="ownership">Whether to transfer ownership of <c>toWrap</c> to the new instance</param>
        /// <remarks>Do not directly modify <c>toWrap</c> after wrapping it, unless the thread-safe views
        /// will no longer be used.</remarks>
        public ThreadSafeStream(SparseStream toWrap, Ownership ownership)
        {
            if (!toWrap.CanSeek)
            {
                throw new ArgumentException("Wrapped stream must support seeking", "toWrap");
            }

            _common = new CommonState {
                WrappedStream          = toWrap,
                WrappedStreamOwnership = ownership
            };
            _ownsCommon = true;
        }
Ejemplo n.º 17
0
        public override bool IsFailedBasedOnSuspicions(InstanceId node)
        {
            IList <InstanceId> suspicionsForNode = GetSuspicionsOf(node);
            int countOfInstancesSuspectedByMe    = GetSuspicionsFor(MyId).Count;

            /*
             * If more than half *non suspected instances* suspect this node, fail it. This takes care of partitions
             * that contain less than half of the cluster, ensuring that they will eventually detect the disconnect without
             * waiting to have a majority of suspicions. This is accomplished by counting as quorum only instances
             * that are not suspected by me.
             */
            return(suspicionsForNode.Count > (CommonState.configuration().Members.Count - countOfInstancesSuspectedByMe) / 2);
        }
Ejemplo n.º 18
0
        public override string MyName()
        {
            string name = parameter("name").apply(CommonState.boundAt());

            if (!string.ReferenceEquals(name, null))
            {
                return(name);
            }
            else
            {
                return(Me.ToString());
            }
        }
Ejemplo n.º 19
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public void acquiredConfiguration(final java.util.Map<org.neo4j.cluster.InstanceId, java.net.URI> memberList, final java.util.Map<String, org.neo4j.cluster.InstanceId> roles, final java.util.Set<org.neo4j.cluster.InstanceId> failedInstances)
        public override void AcquiredConfiguration(IDictionary <InstanceId, URI> memberList, IDictionary <string, InstanceId> roles, ISet <InstanceId> failedInstances)
        {
            CommonState.configuration().Members = memberList;
            CommonState.configuration().Roles   = roles;
            foreach (InstanceId failedInstance in failedInstances)
            {
                if (!failedInstance.Equals(Me))
                {
                    LogProvider.getLog(typeof(ClusterContextImpl)).debug("Adding instance " + failedInstance + " as failed from the start");
                    _heartbeatContext.failed(failedInstance);
                }
            }
        }
Ejemplo n.º 20
0
        public override void Initialize()
        {
            m_texture = new ZTexture(m_gameReference, new CommonState("texture", Color.White, new Vector2(30, 100), Vector2.Zero, 1f, 0, 0));
            this.AddToList(m_texture);


            CommonState textState = new CommonState();

            textState.filePath = "spritefont";
            textState.color    = Color.Black;
            textState.position = new Vector2(400, 100);
            textState.origin   = Vector2.Zero;
            textState.scale    = 1f;
            textState.rotation = 0;

            m_welcomeMsg = new ZText(m_gameReference, textState, "Hello, iam a text bounded in a box trying to achieve the purpose for which i was created.", 300);
            this.AddToList(m_welcomeMsg);


            m_timer = new ZTimer(20);
            this.AddToList(m_timer);

            m_sound = new ZSound(m_gameReference, "sound", false);
            this.AddToList(m_sound);


            CommonState animationState = new CommonState();

            animationState.filePath = "animation";
            animationState.color    = Color.White;
            animationState.position = new Vector2(450, 250);
            animationState.scale    = 1f;
            animationState.rotation = 0;
            animationState.origin   = Vector2.Zero;

            m_animation = new ZAnimation(m_gameReference, animationState, 75, 75, 2);
            this.AddToList(m_animation);

            m_exitBtn = new ExitButton(m_gameReference);
            m_exitBtn.OnButtonPress += new Action(m_exitBtn_OnButtonPress);
            this.AddToList(m_exitBtn);

            ZTexture bar      = new ZTexture(m_gameReference, new CommonState("bar", Color.White, new Vector2(400, 500), Vector2.Zero, 1f, 0, 0));
            ZTexture progress = new ZTexture(m_gameReference, new CommonState("progress", Color.White, new Vector2(400, 500), Vector2.Zero, 1f, 0, 0));

            m_loadingBar = new ZLoadingBar(m_gameReference, bar, progress);
            this.AddToList(m_loadingBar);

            base.Initialize();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Get all of the servers which suspect a specific member.
        /// </summary>
        /// <param name="instanceId"> for the member of interest. </param>
        /// <returns> a set of servers which suspect the specified member. </returns>
        public override IList <InstanceId> GetSuspicionsOf(InstanceId instanceId)
        {
            IList <InstanceId> suspicions = new List <InstanceId>();

            foreach (InstanceId member in CommonState.configuration().MemberIds)
            {
                ISet <InstanceId> memberSuspicions = _nodeSuspicions[member];
                if (memberSuspicions != null && !_failed.Contains(member) && memberSuspicions.Contains(instanceId))
                {
                    suspicions.Add(member);
                }
            }

            return(suspicions);
        }
Ejemplo n.º 22
0
        public override Task OnRefreshState()
        {
            RaceStateCollection RSC = RaceClient.Instance.States;

            commonState  = RSC.GetState <CommonState>();
            creatorState = RSC.GetState <CreatorState>();

            creatorState.PlaceCheckpoint.Observe(
                (state) => {
                checkpointState = state == true ? 1u : 0u;
                OnCheckpointStateChange();
            }
                );

            return(Wait(100));
        }
Ejemplo n.º 23
0
        public override void Joined(InstanceId instanceId, URI atURI)
        {
            CommonState.configuration().joined(instanceId, atURI);

            if (CommonState.configuration().Members.ContainsKey(Me))
            {
                // Make sure this node is in cluster before notifying of others joining and leaving
                _clusterListeners.notify(_executor, listener => listener.joinedCluster(instanceId, atURI));
            }
            // else:
            //   This typically happens in situations when several nodes join at once, and the ordering
            //   of join messages is a little out of whack.

            _currentlyJoiningInstances.Remove(instanceId);
            InvalidateElectorIfNecessary(instanceId);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Merge constructor.
        /// </summary>
        public FlowState(FlowState state1, FlowState state2)
        {
            Contract.ThrowIfNull(state1);
            Contract.ThrowIfNull(state2);
            Debug.Assert(state1._common == state2._common);

            //
            _varsType        = EnumeratorExtension.MixArrays(state1._varsType, state2._varsType, TypeRefMask.Or);
            _common          = state1._common;
            _initializedMask = state1._initializedMask & state2._initializedMask;

            // intersection of other variable flags
            if (state1._lessThanLongMax != null && state2._lessThanLongMax != null)
            {
                _lessThanLongMax = new HashSet <string>(state1._lessThanLongMax);
                _lessThanLongMax.Intersect(state2._lessThanLongMax);
            }
        }
Ejemplo n.º 25
0
        public void OnCreatorAddCheckpoint()
        {
            CommonState  common  = RC.States.GetState <CommonState>();
            CreatorState creator = RC.States.GetState <CreatorState>();

            if (!common.IsInCreator.Get())
            {
                ChatHelper.SendMessage("Creator", "You must be in creator mode to add checkpoints.", 255, 150, 0);
                return;
            }

            if (creator.PlaceCheckpoint.Get())
            {
                ChatHelper.SendMessage("Creator", "Already placing a new checkpoint...", 255, 0, 0);
                return;
            }

            creator.PlaceCheckpoint.Set(true);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Disposes of this instance, invalidating any remaining views.
        /// </summary>
        /// <param name="disposing"><c>true</c> if disposing, lese <c>false</c></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_ownsCommon && _common != null)
                {
                    lock (_common)
                    {
                        if (_common.WrappedStreamOwnership == Ownership.Dispose)
                        {
                            _common.WrappedStream.Dispose();
                        }
                        _common.Dispose();
                    }
                }
            }

            _common = null;
        }
Ejemplo n.º 27
0
        public override void Initialize()
        {
            CommonState normalState = new CommonState();

            normalState.filePath = "btn";
            normalState.color    = Color.White;
            normalState.position = new Vector2(450, 400);
            normalState.origin   = Vector2.Zero;
            normalState.scale    = 1f;
            normalState.rotation = 0;
            m_normalTexture      = new ZTexture(m_gameReference, normalState);

            CommonState highlightedState = new CommonState(normalState);

            highlightedState.filePath = "btnhover";

            m_highlightedTexture = new ZTexture(m_gameReference, highlightedState);

            base.Initialize();
        }
Ejemplo n.º 28
0
        private void CheckSelection()
        {
            // Make sure it selected single key.
            CommonState<CurveLoopType> preLoop = new CommonState<CurveLoopType>();
            CommonState<CurveLoopType> postLoop = new CommonState<CurveLoopType>();
            CommonState<EditCurveTangent> tangentInType =
                new CommonState<EditCurveTangent>();
            CommonState<EditCurveTangent> tangentOutType =
                new CommonState<EditCurveTangent>();

            int totalSelectCount = 0;
            EditCurve lastSelectedCurve = null;
            foreach (EditCurve curve in curves)
            {
                if (!curve.Editable || !curve.Visible ||
                        curve.Selection.Count == 0 ) continue;

                EditCurveKeySelection selection = curve.Selection;
                totalSelectCount += selection.Count;
                lastSelectedCurve = curve;

                preLoop.Add(curve.PreLoop);
                postLoop.Add(curve.PostLoop);

                foreach (long id in selection.Keys)
                {
                    EditCurveKey key;
                    if (curve.Keys.TryGetValue(id, out key))
                    {
                        if (key.Continuity == CurveContinuity.Smooth)
                        {
                            tangentInType.Add(key.TangentInType);
                            tangentOutType.Add(key.TangentOutType);
                        }
                        else
                        {
                            tangentInType.Add(EditCurveTangent.Stepped);
                            tangentOutType.Add(EditCurveTangent.Stepped);
                        }
                    }
                }
            }

            // Update Menus.
            CheckMenuItem(preInfinityToolStripMenuItem, preLoop.ValueString);
            CheckMenuItem(postInfinityToolStripMenuItem, postLoop.ValueString);

            bool sameValueString = String.Compare(tangentInType.ValueString,
                tangentOutType.ValueString) == 0;
            string tangentsString = sameValueString?
                        tangentInType.ValueString : String.Empty;

            CheckMenuItem(tangentsToolStripMenuItem, tangentsString);
            CheckMenuItem(inTangentToolStripMenuItem, tangentInType.ValueString);
            CheckMenuItem(outTangentToolStripMenuItem, tangentOutType.ValueString);

            // Are we just select one key?
            singleEditUpdating = true;
            if (totalSelectCount == 1)
            {
                singleEditCurve = lastSelectedCurve;

                EditCurveKey[] keys = lastSelectedCurve.GetSelectedKeys();
                singleEditKey = keys[0];
                keyPositionTextBox.Text =
                    String.Format( "{0:F3}", singleEditKey.Position );

                keyValueTextBox.Text = String.Format("{0:F3}", singleEditKey.Value);

                keyPositionLabel.Enabled = keyValueLabel.Enabled =
                    keyPositionTextBox.Enabled = keyValueTextBox.Enabled = true;
            }
            else
            {
                singleEditKey = null;
                singleEditCurve = null;
                keyPositionTextBox.Text = keyValueTextBox.Text = String.Empty;
                keyPositionLabel.Enabled = keyValueLabel.Enabled =
                    keyPositionTextBox.Enabled = keyValueTextBox.Enabled = false;
            }
            singleEditUpdating = false;
        }
Ejemplo n.º 29
0
 private ThreadSafeStream(ThreadSafeStream toClone)
 {
     _common = toClone._common;
     if (_common == null)
     {
         throw new ObjectDisposedException("toClone");
     }
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Disposes of this instance, invalidating any remaining views.
        /// </summary>
        /// <param name="disposing"><c>true</c> if disposing, lese <c>false</c></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_ownsCommon && _common != null)
                {
                    lock (_common)
                    {
                        if (_common.WrappedStreamOwnership == Ownership.Dispose)
                        {
                            _common.WrappedStream.Dispose();
                        }

                        _common.Dispose();
                    }
                }
            }

            _common = null;
        }
Ejemplo n.º 31
0
 public ZTexture(ZEngine p_gameReference, CommonState p_state)
     : base(p_gameReference)
 {
     m_state = p_state;
 }
Ejemplo n.º 32
0
 public override void Leave()
 {
     _lastDeliveredInstanceId = -1;
     _lastLearnedInstanceId   = -1;
     CommonState.setLastKnownLearnedInstanceInCluster(-1, null);
 }
Ejemplo n.º 33
0
 public override bool HasDeliveredAllKnownInstances()
 {
     return(_lastDeliveredInstanceId == CommonState.lastKnownLearnedInstanceInCluster());
 }
Ejemplo n.º 34
0
 public override void SetLastKnownLearnedInstanceInCluster(long lastKnownLearnedInstanceInCluster, Org.Neo4j.cluster.InstanceId instanceId)
 {
     CommonState.setLastKnownLearnedInstanceInCluster(lastKnownLearnedInstanceInCluster, instanceId);
 }