T
T
Therapyx2016-10-19 11:52:12
Java
Therapyx, 2016-10-19 11:52:12

Controlling the number of sent events with constant and real time adjustment.?

The bottom line is that you need to write an algorithm that would control the number of lines sent when reading the file, depending on the time written to these lines, real time (ms) and the specified maximum limit, which would be the control lever of the entire mechanism. And now to the details... ))
Let's imagine a common situation in the main:
the format of a line with Unix time, let it be like this)) -> line = "125342740, 43, 245": every 300 lines = plus 10ms.

while(line = reader.readLine()) != null) {
     sendEvent(line); // этот sendEvent надо обвернуть в оболочку, которая бы служила контроллером для ожидания или продолжения пересылки считывания фаила. подумал об:
     long time = split... //достаем время
     while(checkTime(time)) {
           sendEvent(line);
     }
}

where checkTime is a separate class with its own attributes, for example
Инициализация глобального таймера... пусть будет long timer;
class timeControl {
   private eventsToSend = x; //кол-во максимальных строк для отправки за промежуток "у" времени.
   private eventsToSendTimeLimit = y; //как раз таки это время для eventsToSend
   private timeStart = время первой строки для фиксации константного начала.
   
   public boolean checkTime(long time) {
      //иииии вот оно место где я взываю о помощи))) 
   }
}

If the above is not entirely clear, here is another real example.
Given:
- every 300 lines with the same time, the 301st line will be already with +10ms etc.
- real-time timer
=> Within 100ms of real time, all lines should be sent, for example, in 50ms of constant time (5 * 300 = 1500), BUT! if this number is greater than 1000, then the timer must wait until the end of 100ms without sending the remaining 500 rows.
As a result, of course, all this work can be automatically optimized so as not to drive it with your hands, but this is no longer so important.
If anyone has suggestions, how would it be more elegant to complete my crutch, or are there already better solutions? ) For if I continue to write now, then how did I think it over, I feel nothing good will come of it)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question