Exemple #1
0
        private unsafe void LogSetKeyValue(K key, V value)
        {
            if (_allowBatches)
            {
                return;
            }
            var header = new MessageHeader {
                UUID        = _uuid,
                MessageType = MessageType.Set,
                Version     = this.Version
            };
            var commandBody = new SetRemoveCommandBody <K, V> {
                key   = key,
                value = value
            };
            MemoryStream ms  = null;
            var          len = MessageHeader.Size + TypeHelper <SetRemoveCommandBody <K, V> > .SizeOf(commandBody, ref ms);

            // version + len header
            if (TypeHelper <SetRemoveCommandBody <K, V> > .Size <= 0)
            {
                len = len + 8;
            }
            BufferClaim claim;

            _appendLog.Claim(len, out claim);
            *(MessageHeader *)(claim.Data) = header;
            // TODO reuse ms
            TypeHelper <SetRemoveCommandBody <K, V> > .StructureToPtr(commandBody, claim.Data + MessageHeader.Size);

            claim.ReservedValue = _pid;
            claim.Commit();
        }
Exemple #2
0
        // these methods are used to broadcast messages from this instance to
        // all other subscribers excluding this insatnce
        public unsafe void OnNext(T value)
        {
            BufferClaim  claim;
            MemoryStream ms = null;

            var header = new MessageHeader {
                UUID        = UUID,
                MessageType = MessageType.Broadcast,
            };

            var len = TypeHelper <T> .SizeOf(value, ref ms) + MessageHeader.Size;

            _appendLog.Claim(len, out claim);
            *(MessageHeader *)(claim.Data) = header;
            TypeHelper <T> .StructureToPtr(value, claim.Data + MessageHeader.Size, ms);

            claim.ReservedValue = _pid;
            claim.Commit();
        }
Exemple #3
0
        public unsafe void Broadcast(DirectBuffer buffer, UUID correlationId = default(UUID), long version = 0L)
        {
            var header = new MessageHeader {
                UUID        = correlationId,
                MessageType = MessageType.Broadcast,
                Version     = version
            };

            var         len = MessageHeader.Size + (int)buffer.Length;
            BufferClaim claim;

            _appendLog.Claim(len, out claim);
            *(MessageHeader *)(claim.Data) = header;
            claim.Buffer.WriteBytes(claim.Offset + MessageHeader.Size, buffer, 0, buffer.Length);
            claim.ReservedValue = Pid;
            claim.Commit();
        }