Exemplo n.º 1
0
        public static object Deserializer(System.Type expected, global::Orleans.Serialization.BinaryTokenStreamReader stream)
        {
            Microsoft.AspNet.SignalR.Messaging.Message result = new Microsoft.AspNet.SignalR.Messaging.Message();
            result.CommandId = ((String)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(String), stream)));
            object objResult = ((object)(result));
            object temp2     = ((Encoding)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Encoding), stream)));

            fieldInfo2.SetValue(objResult, temp2);
            object temp3 = ((String)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(String), stream)));

            fieldInfo3.SetValue(objResult, temp3);
            object temp4 = ((Boolean)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Boolean), stream)));

            fieldInfo4.SetValue(objResult, temp4);
            object temp5 = ((String)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(String), stream)));

            fieldInfo5.SetValue(objResult, temp5);
            object temp6 = ((UInt64)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(UInt64), stream)));

            fieldInfo6.SetValue(objResult, temp6);
            object temp7 = ((String)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(String), stream)));

            fieldInfo7.SetValue(objResult, temp7);
            object temp8 = ((Int32)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Int32), stream)));

            fieldInfo8.SetValue(objResult, temp8);
            object temp9 = ((ArraySegment <Byte>)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(ArraySegment <Byte>), stream)));

            fieldInfo9.SetValue(objResult, temp9);
            object temp10 = ((Boolean)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Boolean), stream)));

            fieldInfo10.SetValue(objResult, temp10);
            return(objResult);
        }
 internal static Task Ack(this IMessageBus bus, string acker, string commandId)
 {
     // Prepare the ack
     var message = new Message(acker, AckSubscriber.Signal, null);
     message.CommandId = commandId;
     message.IsAck = true;
     return bus.Publish(message);
 }
        public override Task Publish(Message message)
        {
            Counters.MessageBusMessagesPublishedTotal.Increment();
            Counters.MessageBusMessagesPublishedPerSec.Increment();

            // TODO: Implement message batching here
            return Send(new[] { message });
        }
Exemplo n.º 4
0
 public static void Serializer(object untypedInput, Orleans.Serialization.BinaryTokenStreamWriter stream, System.Type expected)
 {
     Microsoft.AspNet.SignalR.Messaging.Message input = ((Microsoft.AspNet.SignalR.Messaging.Message)(untypedInput));
     Orleans.Serialization.SerializationManager.SerializeInner(input.CommandId, stream, typeof(String));
     Orleans.Serialization.SerializationManager.SerializeInner(input.Encoding, stream, typeof(Encoding));
     Orleans.Serialization.SerializationManager.SerializeInner(input.Filter, stream, typeof(String));
     Orleans.Serialization.SerializationManager.SerializeInner(input.IsAck, stream, typeof(Boolean));
     Orleans.Serialization.SerializationManager.SerializeInner(input.Key, stream, typeof(String));
     Orleans.Serialization.SerializationManager.SerializeInner(input.MappingId, stream, typeof(UInt64));
     Orleans.Serialization.SerializationManager.SerializeInner(input.Source, stream, typeof(String));
     Orleans.Serialization.SerializationManager.SerializeInner(input.StreamIndex, stream, typeof(Int32));
     Orleans.Serialization.SerializationManager.SerializeInner(input.Value, stream, typeof(ArraySegment <Byte>));
     Orleans.Serialization.SerializationManager.SerializeInner(input.WaitForAck, stream, typeof(Boolean));
 }
        void FromBytesToBytesProducesCorrectValues()
        {
            var message = new Message("source", "key", "value");
            var message2 = new Message("string", "more", "str");
            var message3 = new Message("s", "l", "n");
            var scaleoutMessage = new ScaleoutMessage(new List<Message>() { message, message2, message3 });

            var bytes = scaleoutMessage.ToBytes();
            var msg = ScaleoutMessage.FromBytes(bytes);

            Assert.True(scaleoutMessage.Messages.Count == 3);
            Assert.True(scaleoutMessage.Messages[0].Source == msg.Messages[0].Source, "Source is not the same");
            Assert.True(scaleoutMessage.Messages[0].Key == msg.Messages[0].Key, "Key is not the same");
            Assert.True(scaleoutMessage.Messages[0].GetString() == msg.Messages[0].GetString(), "Value is not the same");
        }
Exemplo n.º 6
0
        protected Task OnReceived(string streamId, ulong id, Message[] messages)
        {
            // Create a local dictionary for this payload
            var dictionary = new ConcurrentDictionary<string, LocalEventKeyInfo>();

            foreach (var m in messages)
            {
                // Get the payload info
                var info = dictionary.GetOrAdd(m.Key, _ => new LocalEventKeyInfo());

                // Save the min and max for this payload for later
                ulong localId = Save(m);

                // Set the topic pointer for this event key so we don't need to look it up later
                info.Store = Topics[m.Key].Store;

                info.MinLocal = Math.Min(localId, info.MinLocal);
                info.Count++;
            }

            // Create the mapping for this payload
            var mapping = new ScaleoutMapping(dictionary);

            // Get the stream for this payload
            var stream = _streams.GetOrAdd(streamId, _ => new Linktionary<ulong, ScaleoutMapping>());

            // Publish only after we've setup the mapping fully
            stream.Add(id, mapping);

            // Schedule after we're done
            foreach (var eventKey in dictionary.Keys)
            {
                ScheduleEvent(eventKey);
            }

            return TaskAsyncHelper.Empty;
        }
Exemplo n.º 7
0
        public static object DeepCopier(object original)
        {
            Microsoft.AspNet.SignalR.Messaging.Message input  = ((Microsoft.AspNet.SignalR.Messaging.Message)(original));
            Microsoft.AspNet.SignalR.Messaging.Message result = new Microsoft.AspNet.SignalR.Messaging.Message();
            Orleans.Serialization.SerializationContext.Current.RecordObject(original, result);
            result.CommandId = input.CommandId;
            object objResult = ((object)(result));
            object temp2     = ((Encoding)(Orleans.Serialization.SerializationManager.DeepCopyInner(input.Encoding)));

            fieldInfo2.SetValue(objResult, temp2);
            object temp3 = input.Filter;

            fieldInfo3.SetValue(objResult, temp3);
            object temp4 = input.IsAck;

            fieldInfo4.SetValue(objResult, temp4);
            object temp5 = input.Key;

            fieldInfo5.SetValue(objResult, temp5);
            object temp6 = input.MappingId;

            fieldInfo6.SetValue(objResult, temp6);
            object temp7 = input.Source;

            fieldInfo7.SetValue(objResult, temp7);
            object temp8 = input.StreamIndex;

            fieldInfo8.SetValue(objResult, temp8);
            object temp9 = ((ArraySegment <Byte>)(Orleans.Serialization.SerializationManager.DeepCopyInner(input.Value)));

            fieldInfo9.SetValue(objResult, temp9);
            object temp10 = input.WaitForAck;

            fieldInfo10.SetValue(objResult, temp10);
            return(objResult);
        }
Exemplo n.º 8
0
        private bool ExcludeMessage(Message message)
        {
            if (String.IsNullOrEmpty(message.Filter))
            {
                return false;
            }

            string[] exclude = message.Filter.Split('|');

            return exclude.Any(signal => Identity.Equals(signal, StringComparison.OrdinalIgnoreCase) ||
                                                    _signals.Contains(signal) ||
                                                    _groups.Contains(signal));
        }
Exemplo n.º 9
0
        private Message CreateMessage(string key, object value)
        {
            var command = value as Command;

            ArraySegment<byte> messageBuffer = GetMessageBuffer(value);

            var message = new Message(_connectionId, key, messageBuffer);

            if (command != null)
            {
                // Set the command id
                message.CommandId = command.Id;
                message.WaitForAck = command.WaitForAck;
            }

            return message;
        }
 public Task Publish(Message message)
 {
     Debug.WriteLine("Publish: " + message.Value);
     return _messageBus.Publish(message);
 }
 public Task Publish(Message message)
 {
     Debug.WriteLine("Publish: " + message.Encoding.GetString(message.Value.Array));
     return _messageBus.Publish(message);
 }
Exemplo n.º 12
0
 public Task SendMany(Message[] messages)
 {
     return Send(messages);
 }
Exemplo n.º 13
0
        protected ulong Save(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            // Don't mark topics as active when publishing
            Topic topic = GetTopic(message.Key);

            return topic.Store.Add(message);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Publishes a new message to the specified event on the bus.
        /// </summary>
        /// <param name="message">The message to publish.</param>
        public virtual Task Publish(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            Topic topic;
            if (Topics.TryGetValue(message.Key, out topic))
            {
                topic.Store.Add(message);
                ScheduleTopic(topic);
            }

            Counters.MessageBusMessagesPublishedTotal.Increment();
            Counters.MessageBusMessagesPublishedPerSec.Increment();

            return TaskAsyncHelper.Empty;
        }
Exemplo n.º 15
0
 public RedisMessage(long id, Message[] message)
 {
     Id = id;
     Messages = message;
 }
Exemplo n.º 16
0
 public override Task Publish(Message message)
 {
     // TODO: Buffer messages here and make it configurable
     return Send(new[] { message });
 }
Exemplo n.º 17
0
 protected override Task Send(Message[] messages)
 {
     foreach (var g in messages.GroupBy(m => m.Source))
     {
         int topic = Math.Abs(g.Key.GetHashCode()) % _topicsIndexes.Length;
         OnReceived(topic.ToString(), (ulong)Interlocked.Increment(ref _topicsIndexes[topic]), g.ToArray()).Wait();
     }
     return TaskAsyncHelper.Empty;
 }
        private static PersistentResponse GetWrappedResponse(string raw)
        {
            var data = Encoding.Default.GetBytes(raw);
            var message = new Message("foo", "key", new ArraySegment<byte>(data));

            var response = new PersistentResponse
            {
                Messages = new List<ArraySegment<Message>> 
                {
                    new ArraySegment<Message>(new Message[] { message })
                }
            };

            return response;
        }
Exemplo n.º 19
0
        public static Message ReadFrom(Stream stream)
        {
            var message = new Message();
            var binaryReader = new BinaryReader(stream);
            message.Source = binaryReader.ReadString();
            message.Key = binaryReader.ReadString();
            int bytes = binaryReader.ReadInt32();
            message.Value = new ArraySegment<byte>(binaryReader.ReadBytes(bytes));
            message.CommandId = binaryReader.ReadString();
            message.WaitForAck = binaryReader.ReadBoolean();
            message.IsAck = binaryReader.ReadBoolean();
            message.Filter = binaryReader.ReadString();

            return message;
        }
Exemplo n.º 20
0
 /// <summary>
 /// Sends messages to the backplane
 /// </summary>
 /// <param name="messages"></param>
 /// <returns></returns>
 protected abstract Task Send(Message[] messages);
Exemplo n.º 21
0
 public static object Deserializer(System.Type expected, global::Orleans.Serialization.BinaryTokenStreamReader stream)
 {
     Microsoft.AspNet.SignalR.Messaging.Message result = new Microsoft.AspNet.SignalR.Messaging.Message();
     result.CommandId = ((String)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(String), stream)));
     object objResult = ((object)(result));
     object temp2 = ((Encoding)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Encoding), stream)));
     fieldInfo2.SetValue(objResult, temp2);
     object temp3 = ((String)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(String), stream)));
     fieldInfo3.SetValue(objResult, temp3);
     object temp4 = ((Boolean)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Boolean), stream)));
     fieldInfo4.SetValue(objResult, temp4);
     object temp5 = ((String)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(String), stream)));
     fieldInfo5.SetValue(objResult, temp5);
     object temp6 = ((UInt64)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(UInt64), stream)));
     fieldInfo6.SetValue(objResult, temp6);
     object temp7 = ((String)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(String), stream)));
     fieldInfo7.SetValue(objResult, temp7);
     object temp8 = ((Int32)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Int32), stream)));
     fieldInfo8.SetValue(objResult, temp8);
     object temp9 = ((ArraySegment<Byte>)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(ArraySegment<Byte>), stream)));
     fieldInfo9.SetValue(objResult, temp9);
     object temp10 = ((Boolean)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Boolean), stream)));
     fieldInfo10.SetValue(objResult, temp10);
     return objResult;
 }
Exemplo n.º 22
0
        protected ulong Save(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            // Don't mark topics as active when publishing
            Topic topic = GetTopic(message.Key);

            ulong id = topic.Store.Add(message);

            Counters.MessageBusMessagesPublishedTotal.Increment();
            Counters.MessageBusMessagesPublishedPerSec.Increment();

            return id;
        }
Exemplo n.º 23
0
 protected override Task Send(Message[] messages)
 {
     return _sender.Send(messages);
 }
Exemplo n.º 24
0
        protected ulong Save(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            // GetTopic will return a topic for the given key. If topic exists and is Dying,
            // it will revive it and mark it as NoSubscriptions
            Topic topic = GetTopic(message.Key);
            // Mark the topic as used so it doesn't immediately expire (if it was in that state before).
            topic.MarkUsed();

            return topic.Store.Add(message);
        }
Exemplo n.º 25
0
        private Message CreateMessage(string key, object value)
        {
            var command = value as Command;
            var message = new Message(_connectionId, key, _serializer.Stringify(value));

            if (command != null)
            {
                // Set the command id
                message.CommandId = command.Id;
                message.WaitForAck = command.WaitForAck;
            }

            return message;
        }
Exemplo n.º 26
0
 public static object DeepCopier(object original)
 {
     Microsoft.AspNet.SignalR.Messaging.Message input = ((Microsoft.AspNet.SignalR.Messaging.Message)(original));
     Microsoft.AspNet.SignalR.Messaging.Message result = new Microsoft.AspNet.SignalR.Messaging.Message();
     Orleans.Serialization.SerializationContext.Current.RecordObject(original, result);
     result.CommandId = input.CommandId;
     object objResult = ((object)(result));
     object temp2 = ((Encoding)(Orleans.Serialization.SerializationManager.DeepCopyInner(input.Encoding)));
     fieldInfo2.SetValue(objResult, temp2);
     object temp3 = input.Filter;
     fieldInfo3.SetValue(objResult, temp3);
     object temp4 = input.IsAck;
     fieldInfo4.SetValue(objResult, temp4);
     object temp5 = input.Key;
     fieldInfo5.SetValue(objResult, temp5);
     object temp6 = input.MappingId;
     fieldInfo6.SetValue(objResult, temp6);
     object temp7 = input.Source;
     fieldInfo7.SetValue(objResult, temp7);
     object temp8 = input.StreamIndex;
     fieldInfo8.SetValue(objResult, temp8);
     object temp9 = ((ArraySegment<Byte>)(Orleans.Serialization.SerializationManager.DeepCopyInner(input.Value)));
     fieldInfo9.SetValue(objResult, temp9);
     object temp10 = input.WaitForAck;
     fieldInfo10.SetValue(objResult, temp10);
     return objResult;
 }
Exemplo n.º 27
0
        protected override Task Send(Message[] messages)
        {
            return _connectTask.Then(msgs =>
            {
                var taskCompletionSource = new TaskCompletionSource<object>();

                // Group messages by source (connection id)
                var messagesBySource = msgs.GroupBy(m => m.Source);

                SendImpl(messagesBySource.GetEnumerator(), taskCompletionSource);

                return taskCompletionSource.Task;
            },
            messages);
        }
Exemplo n.º 28
0
 public void Send(Message[] message)
 {
     this.action(message);
 }
Exemplo n.º 29
0
 protected override Task Send(Message[] messages)
 {
     return this.bus.SendAsync(messages);
 }