write via DirectInstance in indexed Chronicle: Do we have to fill all the members of the instance class?

36 views
Skip to first unread message

side cap

unread,
Apr 17, 2015, 11:41:07 AM4/17/15
to java-ch...@googlegroups.com
Hi,

Thanks so much for this unbelivable Chronicle api, first. 
i am just a newbie on learning steps and if someone from the forum could answer ?
i was wondering about the basic example provided on OpenHFT.net Technical Doc part.


final Event event = DataValueClasses.newDirectInstance(Event.class);

try (Chronicle chronicle = ChronicleQueueBuilder.vanilla(path).build()) {
    ExcerptAppender appender = chronicle.createAppender();
    for(int i=0; i<items; i++) {
        event.bytes(appender, 0);
        event.setOwner(0);
        event.setType(i / 10);
        event.setTimestamp(System.currentTimeMillis());
        event.setId(i);

        appender.startExcerpt(event.maxSize());
        appender.write(event);
        appender.finish();
    }

    appender.close();
}
is it possible to NOT writes all the members of the event object in the Chronicle and sometimes write/set All fields? 
Will the Chronicle save space or it will reserve/write even for empty values of non setted fields ?
When reading that Chronicle, in terms of performance, will the "deserialization" occurs on written fields or All the fields of the Event Class (eve those non written) ?
Thx,
David Alexander

Luca Burgazzoli

unread,
Apr 17, 2015, 12:23:16 PM4/17/15
to java-ch...@googlegroups.com
1) It is up to you to decide what and when a field has to be set but this is also linked to how you write data to chronicle as if you use the same set up as the example, your fields will be written first to a local buffer which is not automatically cleaned up so if you do not set them all, you'll may end up having unwanted data in chronicle; with a directReference object instead you are free to set only the fields you need.

2) not for objects created with DataValueClasses.newDirect* 

3) if you use a direct reference to read your data, de-serialization is done lazily and only for the fields you access

Note: the documentation has an error I will fix soon: with direct instance you should not call event.bytes(appender, 0);
--
You received this message because you are subscribed to the Google Groups "Chronicle" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-chronicl...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
lb
Reply all
Reply to author
Forward
0 new messages