I have an Observable that I want to send to a REST-Server. When the connection fails, I want to retry sending it forever. If in during the connection failure, the data changes, the new data should be sent instead.
I thought I could implement this with a JobQueue that has capacity 1 and would offer two kinds of methods: forceEnqueue(Job job) and weakEnqueue(Job job). Now, when a connection fails, the job could try to weakEnqueue() itself. This fails, if the queue is already full. If new data is available, it is being forcePushed into the queue, thus eliminating a possibly already enqueued retry-call.
I fail to implement this behaviour using BlockingQueue or ConcurrentLinkedQueue. Is there a thread-safe queue in java, that would support this kind of requirement, or am I trying to solve this problem in the wrong way?