private static void sendPaxosRequest(MoveRobotCommand command, int threadId) { logger.Info($"Sending move:{command.Move.ToString()}"); ClientRequest request = new ClientRequest(); request.Command = command; messageBroker.SendMessage(replicas[threadId].RoleState.MessageSender.UniqueId, request); }
public void Update(ICommand command) { MoveRobotCommand move = (command as MoveRobotCommand); if (move.Move == RobotMove.Left) { updatePosition(new Point(currentRobotPosition.X, currentRobotPosition.Y - 1)); } else if (move.Move == RobotMove.Down) { updatePosition(new Point(currentRobotPosition.X + 1, currentRobotPosition.Y)); } else if (move.Move == RobotMove.Up) { updatePosition(new Point(currentRobotPosition.X - 1, currentRobotPosition.Y)); } else if (move.Move == RobotMove.Right) { updatePosition(new Point(currentRobotPosition.X, currentRobotPosition.Y + 1)); } }
static void readUserInput() { while (true) { ConsoleKeyInfo pressedKey = Console.ReadKey(); if (pressedKey.Key == ConsoleKey.Spacebar) { Console.Clear(); foreach (Replica replica in replicas) { MovingRobotIntoMatrixStateMachine.DisplayMatrix(replica.RoleState.MessageSender.UniqueId, (replica.RoleState as ReplicaState).StateMachine as MovingRobotIntoMatrixStateMachine); } } //We will use two different client/threads to simulate simultaneous command send //use LEFT/RIGHT/UP/DOWN for thread 2, and "1234" for thread 1 else if (pressedKey.KeyChar >= '1' && pressedKey.KeyChar <= '4') { RobotMove move = RobotMove.Down; if (pressedKey.KeyChar == '1') { move = RobotMove.Left; } else if (pressedKey.KeyChar == '2') { move = RobotMove.Up; } else if (pressedKey.KeyChar == '3') { move = RobotMove.Right; } MoveRobotCommand command = new MoveRobotCommand(); command.Move = move; Thread thread = new Thread(() => { sendPaxosRequest(command, 0); }); thread.Start(); } else { RobotMove move = RobotMove.Down; if (pressedKey.Key == ConsoleKey.LeftArrow) { move = RobotMove.Left; } else if (pressedKey.Key == ConsoleKey.UpArrow) { move = RobotMove.Up; } else if (pressedKey.Key == ConsoleKey.RightArrow) { move = RobotMove.Right; } MoveRobotCommand command = new MoveRobotCommand(); command.Move = move; Thread thread = new Thread(() => { sendPaxosRequest(command, 1); }); thread.Start(); } } }