These are the steps which were taken to migrate Chornicle Logger from using Chronicle Queue v3 to v4.
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle</artifactId>
</dependency>
to the following artifactId.
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-queue</artifactId>
</dependency>
Note
|
As Chronicle Queue v3 and v4 use different packages you can use both versions at the same time. |
As Chronicle is the name of a family of products, the interface is now called ChronicleQueue to distinguish it from ChronicleMap for example.
We use the term acquire
to indicate an object will be created only as needed.
In this case, the method will create a new ExcerptAppender
for each thread once.
A thread cannot have more than one appender in use at once as this would cause a live lock.
This method no longer throws an IOException
Conflating the ExcerptAppender
and Bytes
cause a number of problems
including the use of flush()
and close()
which had different meanings between these two classes.
To use Bytes of an appender you can use either of these two patterns
// Writing Java 7 style without a lambda
try (DocumentContext dc = appender.writingDocument()) {
Bytes bytes = dc.wire().bytes();
// write to the bytes
}
// Reading Java 7 style without a lambda
try (DocumentContext dc = appender.readingDocument()) {
Bytes bytes = dc.wire().bytes();
// read from the bytes
}
// Writing Java 8 style with a lambda
appender.writeBytes(b -> b
.writeXxx(x)
.writeXxx(y));
// Reading Java 8 style with a lambda
tailer.readBytes(b -> {
int x = b.readInt();
String y = b.readUtf8();
});
There is two ways to use the Wire API
as field names and values.
a stream of values.
Using the Wire API to write values means the data is self describing. This allows for changes in type as well as automatic dumping of the data. Adding field names allows the data to be more descriptive as well and in any order or added/removed in future.
try (DocumentContext dc = appender.writingDocument()) {
ValueOut out = dc.wire().getValueOut();
out.int8(CODE);
out.int64(timestamp);
out.text(message);
}
Chronicle Bytes distinguishes between the read and write position, remaining and limit.
When reading you want to use
getter readPosition()
and setter readPosition(long)
- position to read next
getter readLimit()
and setter readLimit(long)
- last valid readPosition(). It is also the writePosition()
readRemaining() is readLimit() - readPosition();
When writing you want to use
getter writePosition()
and setter writePosition(long)
- position to write next
getter writeLimit()
and setter writeLimit(long)
- last valid writePosition().
writeRemaining() is writeLimit() - writePosition();
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )