Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlockingQueue implementation and other interfaces #198

Open
pschichtel opened this issue Sep 20, 2018 · 5 comments · May be fixed by #201
Open

BlockingQueue implementation and other interfaces #198

pschichtel opened this issue Sep 20, 2018 · 5 comments · May be fixed by #201

Comments

@pschichtel
Copy link

I quickly build a BlockingQueue<byte[]> (gist here) based on the QueueFile for a project where I intend to use tape as an offline buffer/resend queue in case the uplink goes down. I could have just build the minimal wrapper I needed, but I though "why not just implement BlockingQueue and see if someone else thinks it's useful?"

This made me wonder why none of Java's standard queuing interfaces have implementations here. Is there a specific reason for that?

If this is need interesting I can submit a PR for the BlockingQueue and implementations of Queue as well.

@JakeWharton
Copy link
Member

The main reason is that the queue is not safe for concurrent interaction. A quick glance at the BlockingQueue docs and your gist makes it seem like you are not fulfilling the contract of the interface:

BlockingQueue implementations are thread-safe.

@pschichtel
Copy link
Author

All operations to the backing QueueFile are synchronized, so there is no concurrent access to the QueueFile (unless of course someone shares the QueueFile instances to other places). This is similar to the ArrayBlockingQueue which synchronizes every operation to the backing array.
I've missed the locking in the add() method, but that's fixed locally.

@JakeWharton
Copy link
Member

Ah, haha. The add method was the only one I looked at!

I don't think I'm opposed to adding this if you're willing to send a PR and write tests.

pschichtel added a commit to pschichtel/tape that referenced this issue Oct 24, 2018
…e QueueFile

The resulting BlockingFileQueue is thread-safe and unbounded.
Thread-safety is implemented with a single lock around all operations against the backing queue.
pschichtel added a commit to pschichtel/tape that referenced this issue Oct 25, 2018
…e QueueFile

The resulting BlockingFileQueue is thread-safe and unbounded.
Thread-safety is implemented with a single lock around all operations against the backing queue.
pschichtel added a commit to pschichtel/tape that referenced this issue Oct 25, 2018
…e QueueFile

Switched to an ObjectQueue<T> as the backing store
pschichtel added a commit to pschichtel/tape that referenced this issue Oct 25, 2018
…e QueueFile

Switched to an ObjectQueue<T> as the backing store
pschichtel added a commit to pschichtel/tape that referenced this issue Oct 25, 2018
…e QueueFile

Switched to an ObjectQueue<T> as the backing store
pschichtel added a commit to pschichtel/tape that referenced this issue Oct 25, 2018
…e QueueFile

Switched to an ObjectQueue<T> as the backing store
pschichtel added a commit to pschichtel/tape that referenced this issue Oct 25, 2018
…e QueueFile

Switched to an ObjectQueue<T> as the backing store
pschichtel added a commit to pschichtel/tape that referenced this issue Oct 25, 2018
…e QueueFile

Switched to an ObjectQueue<T> as the backing store
pschichtel added a commit to pschichtel/tape that referenced this issue Oct 25, 2018
…e QueueFile

Switched to an ObjectQueue<T> as the backing store and delegate closable.
pschichtel added a commit to pschichtel/tape that referenced this issue Oct 25, 2018
…e QueueFile

QueueFile is now an ObjectQueue<byte[]> and can thus be used without overhead in the blocking queue. ObjectQueue's file():QueueFile method has been moved to FileObjectQueue where it fits better as InMemoryObjectQueue doesn't have a backing file.
Removed the ByteArrayConverter again as it was the initial attempt to optimize for byte[] queues.
pschichtel added a commit to pschichtel/tape that referenced this issue Oct 25, 2018
…e QueueFile

sneakyfy the IO exception as done in other places.
pschichtel added a commit to pschichtel/tape that referenced this issue Oct 26, 2018
…e QueueFile

Increased coverage and minor cleanup
pschichtel added a commit to pschichtel/tape that referenced this issue Oct 26, 2018
pschichtel added a commit to pschichtel/tape that referenced this issue Nov 3, 2018
pschichtel added a commit to pschichtel/tape that referenced this issue Nov 3, 2018
…e QueueFile

directly throw the sneaky exceptions
@pschichtel
Copy link
Author

Is this project still alive?

@pforhan
Copy link
Contributor

pforhan commented Jan 16, 2019

Used a lot of places but not heavily developed as it's pretty mature. I think there's a branch with a 2.0 proposal. -- https://github.com/square/tape/tree/2.0.0-RC1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants