Ejemplo n.º 1
0
        public void RegisterCreateMachine(MachineId source, MachineId target)
        {
            LogCreate(source, target);
            CreateCount++;

            // The id of the created machine should not conflict with an id seen earlier
            Runtime.Assert(MS.ContainsKey(target.Value) == false, $"New ID {target} conflicts with an already existing id");

            DescriptiveName[target.Value] = target.ToString();

            // In case the runtime creates a machine, simply create a machine state for it,
            // with a fresh VC where the appropriate component is incremented.
            // no hb rule needs to be triggered
            if (source == null)
            {
                var newState = new InstrMachineState(target.Value, this.Log, Config.EnableRaceDetectorLogging);
                MS[target.Value] = newState;
                return;
            }

            DescriptiveName[source.Value] = source.ToString();

            var sourceMachineState = GetCurrentState(source);
            var targetState        = new InstrMachineState(target.Value, this.Log, Config.EnableRaceDetectorLogging);

            targetState.JoinEpochAndVC(sourceMachineState.VC);
            MS[target.Value] = targetState;
            sourceMachineState.IncrementEpochAndVC();
        }
Ejemplo n.º 2
0
        public SnowflakeIdState(long id, ISnowflakeId idGen)
        {
            Id              = id;
            _idGen          = idGen;
            MachineIdLength = _idGen.MaxMachineMask.ToString().Length;
            SequenceLength  = _idGen.SequenceMask.ToString().Length;

            Sequence = Id & _idGen.SequenceMask;

            MachineId = (Id >> _idGen.SequenceBits) & _idGen.MaxMachineMask;
            if (MachineId != _idGen.MachineId)
            {
                throw new ArgumentException($"MachineId:[{MachineId}] not Equal IdGen.MachineId:[{_idGen.MachineId}]",
                                            nameof(MachineId));
            }

            UtcTime = _idGen.EpochTime.AddMilliseconds((Id >> _idGen.TimestampShift) & _idGen.TimestampMask);
            var machineIdFormat = $"D{MachineIdLength}";
            var sequenceFormat  = $"D{SequenceLength}";

            IdString =
                $"{UtcTime.ToString(TIME_FORMAT)}{MachineId.ToString(machineIdFormat)}{Sequence.ToString(sequenceFormat)}";
        }
Ejemplo n.º 3
0
        //not particularly efficient and needs to be generalized
        internal void HandleMethodCall(MethodCall method_call)
        {
            //TODO: Ping and Introspect need to be abstracted and moved somewhere more appropriate once message filter infrastructure is complete

            //FIXME: these special cases are slightly broken for the case where the member but not the interface is specified in the message
            if (method_call.Interface == "org.freedesktop.DBus.Peer")
            {
                switch (method_call.Member)
                {
                case "Ping":
                    Send(MessageHelper.ConstructReply(method_call));
                    return;

                case "GetMachineId":
                    if (MachineId != UUID.Zero)
                    {
                        Send(MessageHelper.ConstructReply(method_call, MachineId.ToString()));
                        return;
                    }
                    else
                    {
                        // Might want to send back an error here?
                    }
                    break;
                }
            }

            if (method_call.Interface == "org.freedesktop.DBus.Introspectable" && method_call.Member == "Introspect")
            {
                Introspector intro = new Introspector();
                intro.root_path = method_call.Path;
                intro.WriteStart();

                //FIXME: do this properly
                //this is messy and inefficient
                List <string> linkNodes = new List <string> ();
                int           depth     = method_call.Path.Decomposed.Length;
                foreach (ObjectPath pth in RegisteredObjects.Keys)
                {
                    if (pth.Value == (method_call.Path.Value))
                    {
                        ExportObject exo = (ExportObject)RegisteredObjects[pth];
                        exo.WriteIntrospect(intro);
                    }
                    else
                    {
                        for (ObjectPath cur = pth; cur != null; cur = cur.Parent)
                        {
                            if (cur.Value == method_call.Path.Value)
                            {
                                string linkNode = pth.Decomposed[depth];
                                if (!linkNodes.Contains(linkNode))
                                {
                                    intro.WriteNode(linkNode);
                                    linkNodes.Add(linkNode);
                                }
                            }
                        }
                    }
                }

                intro.WriteEnd();

                Message reply = MessageHelper.ConstructReply(method_call, intro.xml);
                Send(reply);
                return;
            }

            BusObject bo;

            if (RegisteredObjects.TryGetValue(method_call.Path, out bo))
            {
                ExportObject eo = (ExportObject)bo;
                eo.HandleMethodCall(method_call);
            }
            else
            {
                MaybeSendUnknownMethodError(method_call);
            }
        }