protected void PropageteRequestToWorkers(RestRequest request, Queue queue, Worker worker, Worker coworker) { var requestForMaster = request.AddParameter("Cooperator", coworker.Address); IRestResponse response; if (WorkerQueries.IsWorkerAlive(DBConnection, worker.Id)) { response = PropagateRequest(requestForMaster, worker); if (response.ResponseStatus == ResponseStatus.TimedOut || response.ResponseStatus == ResponseStatus.Error) { response = PropagateRequest(request, coworker); QueuesQueries.swapWorkers(DBConnection, queue); } } else { response = PropagateRequest(request, coworker); QueuesQueries.swapWorkers(DBConnection, queue); } if (response.StatusCode != HttpStatusCode.OK) { throw new BadRequestException(); } }
public QueuesAndTopics Get(QueuesAndTopicsRequest request) { if (Encrypt.EncryptToken(request.Time, request.WorkerId, request.Address, request.Token)) { var queues = QueuesQueries.GetWorkerQueues(DBConnection, request.WorkerId); var topics = TopicsQueries.GetWorkerTopics(DBConnection, request.WorkerId); return(new QueuesAndTopics { Queues = queues, Topics = topics }); } throw new BadRequestException(); }
protected void processRequest(string queueName, RestRequest request) { if (!QueuesQueries.QueueExists(DBConnection, queueName)) { throw new QueueNotExistsException(); } else { var queue = QueuesQueries.getQueueByName(DBConnection, queueName); var worker = WorkerQueries.GetWorkerById(DBConnection, queue.Worker); var coworker = WorkerQueries.GetWorkerById(DBConnection, queue.Cooperator); PropageteRequestToWorkers(request, queue, worker, coworker); } }
public Message Get(GetMessage request) { var requestToSend = new RestRequest($"queues/{request.QueueName}/messages", Method.GET); if (!QueuesQueries.QueueExists(DBConnection, request.QueueName)) { throw new QueueNotExistsException(); } else { var queue = QueuesQueries.getQueueByName(DBConnection, request.QueueName); var worker = WorkerQueries.GetWorkerById(DBConnection, queue.Worker); var coworker = WorkerQueries.GetWorkerById(DBConnection, queue.Cooperator); return(PropageteRequestToWorkers <Message>(requestToSend, queue, worker, coworker)); } }
public void Delete(DeleteQueue request) { var requestToSend = new RestRequest($"queues/{request.QueueName}", Method.DELETE); if (!QueuesQueries.QueueExists(DBConnection, request.QueueName)) { throw new QueueNotExistsException(); } else { var queue = QueuesQueries.getQueueByName(DBConnection, request.QueueName); var worker = WorkerQueries.GetWorkerById(DBConnection, queue.Worker); var coworker = WorkerQueries.GetWorkerById(DBConnection, queue.Cooperator); QueuesQueries.DeleteQueue(DBConnection, request.QueueName); PropageteRequestToWorkers(requestToSend, queue, worker, coworker); } }
public void Create(CreateQueue request) { var requestToSend = new RestRequest("queues", Method.POST); requestToSend.AddParameter("Name", request.Name); if (QueuesQueries.QueueExists(DBConnection, request.Name)) { throw new QueueAlreadyExistsException(); } else { Worker worker, coworker; CalculateQueueWorkers(request.Name, out worker, out coworker); var queue = QueuesQueries.CreateQueue(DBConnection, request.Name, worker.Id, coworker.Id); PropageteRequestToWorkers(requestToSend, queue, worker, coworker); } }
public IList <String> Get() { return(QueuesQueries.getQueuesNames(DBConnection)); }
protected override void swapWorkers(ICollection collection) { QueuesQueries.swapWorkers(DBConnection, (Queue)collection); }