@PostMapping("/httpush")
public Mono<ResponseEntity<HttpushResponseUtil>> httpush(@RequestParam("timestamp") String timestamp, @RequestParam("token") String token) throws InterruptedException{
Thread t = new Thread( ()-> {
long fecha_actual = 0;
long fecha_bd = 0;
fecha_actual = (timestamp.equals("null")) ? 0: Long.parseLong(timestamp);
long elapsedTime = 0;
int i = 0;
while (fecha_bd <= fecha_actual) {
List<HuellaTemp> updateTime = service.ObtenerUpdateTimePorSerial(token, "update_time").block();
if (updateTime.size() > 0) {
if(updateTime.get(0).getStatusPlantilla()=="Muestras Restantes: 0") {
break;
}
else if(updateTime.get(0).getUpdate_time() != null) {
fecha_bd = updateTime.get(0).getUpdate_time().getTime() / 1000;
}
}
elapsedTime = elapsedTime + 1;
if (elapsedTime == 600) {
break;
}
i++;
}
});
t.start();
t.join();
return service.ObtenerHuellaHttpush()
.map(httpush -> ResponseEntity
.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(httpush)
);
}
The code works but my goal is not to create blocking processes, and remove the extra thread. which was placed because the main thread does not allow blocking.
I need to consult a date stored in the database, for each iteration of while; This date updates each time the sensor captures a new state; For this reason, I must verify the date until it is greater than the one registered by url. Finally, when you are sure that the date has just been registered, check the status of the fingerprint in the database.
How can I achieve the same imperative behavior with reactive operators?