Inheritance: IServerToClientMessage
 public void OnNext(ServerToClientMessage data, long sequence, bool endOfBatch)
 {
     if (data.ReceiverClientId > 0)
         Publish(data.ReceiverClientId, data);
     else if (data.ReceiverClientId == 0)
         Publish(data);
 }
        public void SerializationPerformanceTest()
        {
            var sw = new Stopwatch();
            var serializer = new ProtobufSerializer();
            var instance = new ServerToClientMessage();

            sw.Start();
            for (int i = 0; i < 5000000; i++)
                serializer.Serialize(instance);

            sw.Stop();
            var elapsed = sw.ElapsedMilliseconds;

            double perItem = (double)elapsed/(double)5000000;
            Console.WriteLine("Total ms: " + elapsed);
            Console.WriteLine("Per item: " + perItem);
        }
        public void SerializeDeserializeTest()
        {
            var serializer = new ProtobufSerializer();
            var byteArray = new RingbufferByteArray();

            var item = new ServerToClientMessage();
            item.Message = "hello";
            item.MessageType = ServerToClientMessageTypeEnum.LimitOrderAccepted;

            byteArray.Set(serializer.Serialize(item));
            byte[] target = new byte[512];

            byteArray.GetContent(ref target);
            var deserialized = serializer.Deserialize<ServerToClientMessage>(target.Take(byteArray.ContentLength).ToArray());

            Assert.IsNotNull(deserialized);
            Assert.AreEqual("hello", deserialized.Message);
            Assert.AreEqual(ServerToClientMessageTypeEnum.LimitOrderAccepted, deserialized.MessageType);
        }
        public void ShouldSerializeAndDeserializeSeriesOfItems()
        {
            var serializer = new ProtobufSerializer();

            for (int i = 0; i < 1000; i++)
            {
                var item = new ServerToClientMessage();
                item.Message = i.ToString();
                item.MessageType = ServerToClientMessageTypeEnum.LimitOrderAccepted;
                item.LimitOrder = new LimitOrderDto();
                item.LimitOrder.ClientId = i;
                item.LimitOrder.ExchangeOrderId = (uint)i;

                var serialized = serializer.Serialize(item);

                var deserialized = serializer.Deserialize<ServerToClientMessage>(serialized);

                Assert.IsNotNull(deserialized);
                Assert.AreEqual(i.ToString(), deserialized.Message );
                Assert.AreEqual(ServerToClientMessageTypeEnum.LimitOrderAccepted, deserialized.MessageType);
                Assert.AreEqual(i, deserialized.LimitOrder.ClientId);
                Assert.AreEqual(i, deserialized.LimitOrder.ExchangeOrderId);
            }
        }
 public void Publish(ServerToClientMessage serverToClientMessage)
 {
     var serialized = serializer.Serialize(serverToClientMessage);
     publishSocket.SendMoreFrame("a").SendFrame(serialized);
 }
 public void Publish(int clientId, ServerToClientMessage serverToClientMessage)
 {
     var serialized = serializer.Serialize(serverToClientMessage);
     publishSocket.SendMoreFrame(clientId.ToString()).SendFrame(serialized);
 }
Exemplo n.º 7
0
        private void HandleServerMessage(ServerToClientMessage message)
        {
            switch (message.MessageType)
            {
                case ServerToClientMessageTypeEnum.StopLimitOrderSnapshot:
                    EventHandler<List<StopLimitOrderDto>> stopLimitOrderSnapshotHandler = StopLimitOrderSnapshot;
                    if (stopLimitOrderSnapshotHandler != null)
                        stopLimitOrderSnapshotHandler(this, message.StopLimitOrderList);
                    break;

                case ServerToClientMessageTypeEnum.StopLimitOrderAccepted:
                    EventHandler<StopLimitOrderDto> stopLimitOrderAcceptedHandler = StopLimitOrderAccepted;
                    if (stopLimitOrderAcceptedHandler != null)
                        stopLimitOrderAcceptedHandler(this, message.StopLimitOrder);
                    break;

                case ServerToClientMessageTypeEnum.StopLimitOrderChanged:
                    EventHandler<StopLimitOrderDto> stopLimitOrderChangedHandler = StopLimitOrderChanged;
                    if (stopLimitOrderChangedHandler != null)
                        stopLimitOrderChangedHandler(this, message.StopLimitOrder);
                    break;

                case ServerToClientMessageTypeEnum.StopLimitOrderDeleted:
                    EventHandler<StopLimitOrderDto> stopLimitOrderDeletedHandler = StopLimitOrderDeleted;
                    if (stopLimitOrderDeletedHandler != null)
                        stopLimitOrderDeletedHandler(this, message.StopLimitOrder);
                    break;

                case ServerToClientMessageTypeEnum.LimitOrderAccepted:
                    EventHandler<LimitOrderDto> acceptedHandler = LimitOrderAccepted;
                    if (acceptedHandler != null)
                        acceptedHandler(this, message.LimitOrder);
                    break;

                case ServerToClientMessageTypeEnum.LimitOrderDeleted:
                    EventHandler<LimitOrderDto> deletedHandler = LimitOrderDeleted;
                    if (deletedHandler != null)
                        deletedHandler(this, message.LimitOrder);
                    break;

                case ServerToClientMessageTypeEnum.LimitOrderChanged:
                    EventHandler<LimitOrderDto> changedHandler = LimitOrderChanged;
                    if (changedHandler != null)
                        changedHandler(this, message.LimitOrder);
                    break;

                case ServerToClientMessageTypeEnum.LimitOrderSnapshot:
                    EventHandler<List<LimitOrderDto>> snapshotHandler = LimitOrderSnapshot;
                    if (snapshotHandler != null)
                        snapshotHandler(this, message.LimitOrderList);
                    break;

                case ServerToClientMessageTypeEnum.Execution:
                    EventHandler<ExecutionDto> executionHandler = NewExecution;
                    if (executionHandler != null)
                        executionHandler(this, message.Execution);
                    break;

                case ServerToClientMessageTypeEnum.Level1:
                    EventHandler<MarketBestBidAskDto> level1Handler = Level1Updated;
                    if (level1Handler != null)
                        level1Handler(this, message.Level1);
                    break;
            }
        }
 public OutgoingQueue(ILogger logger, IMessagePublisher publisher)
 {
     this.logger = logger;
     this.publisher = publisher;
     serverToClientMessage = new ServerToClientMessage();
 }