Edward Q. Bridges
Edward Q. Bridges

Reputation: 18350

java fifo queue that allows pushing back?

is there a fifo queue implementation that provides for replacing the head element after a peek?

i'd like to use this to push a partially written buffer back onto the queue after a partial write onto a network connection (when using java nio selector).

this would be a bit cleaner than sticking the partially written buffer as an attachment on the selection key, but if there's no convenient implementation available I'll have to use that.

Upvotes: 0

Views: 698

Answers (2)

user207421
user207421

Reputation: 311016

After a peek the head element is undisturbed, so your question doesn't make sense. Just peek, try the write, and if there is nothing left then remove the buffer from the queue.

Upvotes: -1

Peter Lawrey
Peter Lawrey

Reputation: 533780

You can use a Deque which allows you to add to the start or the end.

However, if you have a partial write and your buffers are not huge, you could have a slow consumer and you might consider a different action such as closing the connection.

Upvotes: 3

Related Questions