package tk.antoine_roux.wiki.service; import org.springframework.stereotype.Service; import tk.antoine_roux.wiki.model.request.JobRequest; import tk.antoine_roux.wiki.model.request.HookEvent; import tk.antoine_roux.wiki.model.response.JobResponse; import java.util.Optional; import java.util.concurrent.ConcurrentLinkedQueue; @Service public class JobManager { /** * concurrent list of {@link JobResponse} fill by {@link tk.antoine_roux.wiki.ControllerHandlers#webhook(HookEvent)} * and pop by {@link tk.antoine_roux.wiki.ControllerHandlers#jobRequest(JobRequest)} */ ConcurrentLinkedQueue jobQueue = new ConcurrentLinkedQueue<>(); public void stackJob(JobResponse newJob) { this.jobQueue.add(newJob); } public Optional popJob(JobRequest jobRequest) { return Optional.ofNullable(this.jobQueue.poll()); } }