2014-09-02 17 views
2

有一個非常簡單的POC像這樣的:如何寫一個VanillaChronicle

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); 
    } 

給了我一個IndexOutOfBoundsException在上VanillaAppenderwriteObject方法。

不過有一點區別,並沒有什麼特別的不同docs

任何人都可以表明,它應該如何使用?

更新:

我重新安排代碼,以便它成爲相同彼得斯(在複製它,實際上),但我仍然得到此異常:

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> 
+0

你能給整個堆棧跟蹤嗎?我假設你有默認設置,並且你的信息相對較小。 – 2014-09-04 17:26:34

回答

1

當我嘗試這與紀事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} 

順便說一句,我建議你使用外部化或ByteMarshallable以提高性能和更小的消息。

+0

我明白了外部化的意義,謝謝,但我還在玩耍。 – 2014-09-05 10:20:37