Пример #1
0
        private void ProcessCommandMessage(CliClient client, string domain, ConcurrentDictionary <ulong, MessageEntry> messages, ObjectCommandEnvelope commandEnvelope)
        {
            BaseCommand responseCommand = null;

            switch ((CommandType)commandEnvelope.Command.Type)
            {
            case CommandType.ObjectCreate:
                responseCommand = new ObjectCreateCommand(commandEnvelope.Command);
                break;

            case CommandType.ObjectUpdatePosition:
                responseCommand = new ObjectUpdatePositionCommand(commandEnvelope.Command);
                break;

            case CommandType.ObjectDestroy:
                responseCommand = new ObjectDestroyCommand(commandEnvelope.Command);
                break;
            }
            if (!messages.ContainsKey(commandEnvelope.ToObjectId))
            {
                Log.WriteLine($"[{client.ClientId} ERROR: {domain} mMessage {commandEnvelope.ToObjectId} is missing");
                return;
            }
            messages[commandEnvelope.ToObjectId].ResponseTimeStamp = DateTime.Now;
            messages[commandEnvelope.ToObjectId].ResponseCount++;
            byte[] responseData = commandEnvelope.Serialize();
            byte[] requestData  = messages[commandEnvelope.ToObjectId].CommandEnvelope.Serialize();
            if (!ComparyBinary(responseData, requestData))
            {
                Log.WriteLine($"{client.ClientId} ERROR: {domain} message {commandEnvelope.ToObjectId} invalid response");
            }
        }
Пример #2
0
 protected override Task OnLoad()
 {
     ArgsReader            = new ArgsReader(Args);
     CliClient             = new CliClient(ArgsReader.GetOrDefault("server", ".\\"), ArgsReader.GetOrDefault("pipe", "htcsharp"));
     CliClient.Disconnect += CliClientOnDisconnect;
     return(Task.CompletedTask);
 }
Пример #3
0
        private MessageStatistic RunStatistics(CliClient client, MessageControlFlags flags, string domain, int messageCount, Func <ulong, BaseCommand> createCommand)
        {
            ConcurrentDictionary <ulong, MessageEntry> messages = new ConcurrentDictionary <ulong, MessageEntry>();

            client.OnCommand = (cmd) => ProcessCommandMessage(client, domain, messages, cmd);
            DateTime startTimeStamp = DateTime.Now;
            ulong    objectId       = (ulong)(client.ClientId * messageCount);

            for (int i = 0; i < messageCount; i++)
            {
                objectId++;
                BaseCommand           command    = createCommand(objectId);
                ObjectCommandEnvelope commandEnv = new ObjectCommandEnvelope(client.ClientId, command, objectId);
                messages.TryAdd(objectId, new MessageEntry {
                    RequestTimeStamp = DateTime.Now, ResponseTimeStamp = DateTime.MinValue, CommandEnvelope = commandEnv
                });
                client.ReliableMessaging.SendCommandEnvelope(commandEnv, flags);
                TimeSpan waitTime = client.ReliableMessaging.SynchronizeMessages();
                if (waitTime > TimeSpan.Zero)
                {
                    Thread.Sleep((int)waitTime.TotalMilliseconds);
                }
            }
            for (; ;)
            {
                if (DateTime.Now - client.LastMessageReceived > TimeSpan.FromSeconds(5))
                {
                    break;
                }
                Thread.Sleep(200);
                TimeSpan waitTime = client.ReliableMessaging.SynchronizeMessages();
                if (waitTime > TimeSpan.Zero)
                {
                    Thread.Sleep((int)waitTime.TotalMilliseconds);
                }
            }
            TimeSpan sumLatency   = TimeSpan.Zero;
            int      countSuccess = 0;

            foreach (var value in messages.Values)
            {
                if (value.ResponseTimeStamp == DateTime.MinValue)
                {
                    break;
                }
                countSuccess++;
                sumLatency += value.ResponseTimeStamp - value.RequestTimeStamp;
            }
            MessageStatistic messageStatistic = new MessageStatistic();

            messageStatistic.Duration         = client.LastMessageReceived - startTimeStamp;
            messageStatistic.MessagesTotal    = messageCount;
            messageStatistic.MessagesAnswered = countSuccess;
            return(messageStatistic);
        }
Пример #4
0
        private Task <ClientStatistic> RunStatisticsClient(object state, MessageControlFlags qos)
        {
            var task = new Task <ClientStatistic>(() =>
            {
                uint clientId = (uint)state;

                CliClient client  = new CliClient();
                AVector3 location = new AVector3
                {
                    X = clientId * Locator.AREASIZE,
                    Y = clientId * Locator.AREASIZE,
                    Z = clientId * Locator.AREASIZE,
                };

                client.Connect(Host, Port, 0, TokenSigningKey, clientId, location);
                AutoResetEvent eventFinished = new AutoResetEvent(false);
                var statistics      = new ClientStatistic();
                statistics.ClientId = clientId;
                client.ReliableMessaging.OnDeadLetter = (m) => statistics.DeadLetteredMessages++;
                client.OnConnected = () =>
                {
                    ulong areaId = Locator.GetAreaIdFromWorldPosition(location);

                    _testCountdownEventStart.Signal();
                    _testCountdownEventStart.Wait();

                    statistics.MessageStatistic.Add("CREATE", RunStatistics(client, qos, "Create objects", MessageCount, _ => new ObjectCreateCommand(0, _, 0, 0, 0, location, AQuaternion.Zero)));
                    _testCountdownEventCreated.Signal();
                    _testCountdownEventCreated.Wait();

                    statistics.MessageStatistic.Add("UPDATE", RunStatistics(client, qos, "Update positions", MessageCount, _ => new ObjectUpdatePositionCommand(_, location, AQuaternion.Zero, AVector3.Zero, AVector3.Zero, 0, 0)));
                    _testCountdownEventUpdate.Signal();
                    _testCountdownEventUpdate.Wait();

                    //statistics.MessageStatistic.Add("DELETE", RunStatistics(client, qos, "Destroy objects", MessageCount, _ => new ObjectDestroyCommand(0, 0, locationX, locationY, locationZ)));
                    _testCountdownEventDestroy.Signal();
                    _testCountdownEventDestroy.Wait();

                    statistics.UnackedMessages  = client.ReliableMessaging.MessageUnackedCount;
                    statistics.MessagesSent     = client.ReliableMessaging.MessageSentCount;
                    statistics.MessagesReceived = client.ReliableMessaging.MessageReceivedCount;
                    statistics.ResentMessages   = client.ReliableMessaging.MessageResentCount;

                    eventFinished.Set();
                };
                eventFinished.WaitOne();
                return(statistics);
            });

            return(task);
        }
Пример #5
0
 public LockCommand(CliClient parent)
 {
     this.parent = parent;
 }
 public ShutDownCommand(CliClient parent)
 {
     this.parent = parent;
 }
Пример #7
0
 public RestartCommand(CliClient parent)
 {
     this.parent = parent;
 }