-
Notifications
You must be signed in to change notification settings - Fork 522
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
ExcerptTailer.read(ByteBuffer) fails #112
Comments
You need to use nextIndex () on the Tailer first.
|
Thanks - I've gone through a few variations of this seeing what works and what doesn't. Using nextIndex(), here's a similar example that fails: String path = new File(System.getProperty("java.io.tmpdir"), "foo").getAbsolutePath() + "/"
+ UUID.randomUUID().toString();
try (IndexedChronicle chronicle = new IndexedChronicle(path, ChronicleConfig.TEST)) {
ExcerptAppender appender = chronicle.createAppender();
appender.startExcerpt(100);
ByteBuffer entry = ByteBuffer.allocate(4).putInt(5);
appender.write(entry);
appender.finish();
ExcerptTailer tailer = chronicle.createTailer();
if (tailer.nextIndex()) {
ByteBuffer input = ByteBuffer.allocate(4);
tailer.read(input);
// Fails
assert input.equals(entry);
}
} |
After you write to a ByteBuffer you need to flip() it. i.e. this leaves ByteBuffer entry = ByteBuffer.allocate(4).putInt(5); Instead of using ByteBuffers can you not write directly to/from the File path = File.createTempFile("foo", "");
} On 17 December 2014 at 22:10, Jonathan Halterman notifications@github.com
|
Oops this example doesn't fail. Ignore the comment. On 17 December 2014 at 22:23, Peter Lawrey <
|
We're exposing an API that allows ByteBuffers to be written through to a Chronicle and read back later - so we don't have control over the state of the ByteBuffer or its content when we receive it. Do you have an opinion on whether this is generally a good or bad idea? |
You need to flip() it and pass the original ByteBuffer to the ByteBuffer is a built in library so we have to support how it works On 17 December 2014 at 22:29, Jonathan Halterman notifications@github.com
|
A new tailer should point to the end of a chronicle-queue so if you want to read the data written before the tailer was created you should move it to the beginning - with toStart() - or set the index from which you want to start from - with index(..) |
Thanks - We'll use flip() to try and normalize the buffers we receive before attempting to write them out. |
When writing a simple ByteBuffer out and attempting to read it back via ExcerptTailer.read, the ByteBuffer is never read.
This appears to be because
ExcerptTailer.remaining()
is 0, which causes theread
to do nothing.The text was updated successfully, but these errors were encountered: