gpt4 book ai didi

java - 如何写一个 Vanilla 编年史

转载 作者:行者123 更新时间:2023-11-30 11:15:02 25 4
gpt4 key购买 nike

有一个非常简单的 poc,比如这个:

    IndexedChronicle chronicle = getChronicle("basic");
ExcerptAppender appender = chronicle.createAppender();
appender.startExcerpt();
appender.writeObject(new MessageKey("type", 123L));
appender.finish();

ExcerptTailer tailer = chronicle.createTailer();
while(tailer.nextIndex()) {
MessageKey key = (MessageKey) tailer.readObject();
System.out.println("key " + key);
}

VanillaChronicle vcron = getVainllaChronicle("vanilla");
VanillaAppender app = vcron.createAppender();
app.startExcerpt();
app.writeObject(new MessageKey("type", 123L));
app.finish();

ExcerptTailer vtail = vcron.createTailer();
while(vtail.nextIndex()) {
MessageKey key = (MessageKey) vtail.readObject();
System.out.println("key " + key);
}

VanillaAppenderwriteObject 方法中给我一个 IndexOutOfBoundsException

但是,在 docs 中几乎没有什么不同,也没有什么特别的不同。

谁能建议应该如何使用它?

更新:

我重新安排了代码,使其与 peters 完全相同(实际上是将其复制),但我仍然遇到此异常:

Exception in thread "main" java.lang.IndexOutOfBoundsException: position is beyond the end of the buffer 372 > -190495716
at net.openhft.lang.io.NativeBytes.checkEndOfBuffer(NativeBytes.java:518)
at net.openhft.lang.io.AbstractBytes.writeObject(AbstractBytes.java:1897)
at main.ChronicleTest.main(ChronicleTest.java:31)

导入的版本是3.2.1

<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle</artifactId>
<version>3.2.1</version>
</dependency>

最佳答案

当我用 Chronicle 3.2.1 尝试这个时

public class SO25623856Main {
public static void main(String[] args) throws IOException {
Chronicle vcron = new VanillaChronicle("vanilla");
ExcerptAppender app = vcron.createAppender();
app.startExcerpt();
app.writeObject(new MessageKey("type", 123L));
app.finish();

ExcerptTailer vtail = vcron.createTailer();
while (vtail.nextIndex()) {
MessageKey key = (MessageKey) vtail.readObject();
System.out.println("key " + key);
}
vcron.close();
}
}

class MessageKey implements Serializable {

private String type;
private long l;

public MessageKey(String type, long l) {

this.type = type;
this.l = l;
}

@Override
public String toString() {
return "MessageKey{" +
"type='" + type + '\'' +
", l=" + l +
'}';
}
}

它打印

key MessageKey{type='type', l=123}

顺便说一句,我建议您使用 Externalizable 或 ByteMarshallable 来提高性能和缩小消息。

关于java - 如何写一个 Vanilla 编年史,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25623856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com