1 /*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002, 2014 Oracle and/or its affiliates. All rights reserved. 5 * 6 */ 7 8 package com.sleepycat.je.log; 9 10 import java.nio.ByteBuffer; 11 12 /** 13 * A class that implements Loggable knows how to read and write itself into 14 * a ByteBuffer in a format suitable for the JE log or JE replication 15 * messages. 16 * 17 * <p>Classes that implement {@code Loggable} and are included in replication 18 * data should implement {@code VersionedWriteLoggable}. 19 */ 20 public interface Loggable { 21 22 /* 23 * Writing to a byte buffer 24 */ 25 26 /** 27 * @return number of bytes used to store this object. 28 */ getLogSize()29 public int getLogSize(); 30 31 /** 32 * Serialize this object into the buffer. 33 * @param logBuffer is the destination buffer 34 */ writeToLog(ByteBuffer logBuffer)35 public void writeToLog(ByteBuffer logBuffer); 36 37 /* 38 * Reading from a byte buffer 39 */ 40 41 /** 42 * Initialize this object from the data in itemBuf. 43 * @param itemBuffer the source buffer 44 * @param entryVersion the log version of the data 45 */ readFromLog(ByteBuffer itemBuffer, int entryVersion)46 public void readFromLog(ByteBuffer itemBuffer, int entryVersion); 47 48 /** 49 * Write the object into the string buffer for log dumping. Each object 50 * should be dumped without indentation or new lines and should be valid 51 * XML. 52 * @param sb destination string buffer 53 * @param verbose if true, dump the full, verbose version 54 */ dumpLog(StringBuilder sb, boolean verbose)55 public void dumpLog(StringBuilder sb, boolean verbose); 56 57 /** 58 * @return the transaction id embedded within this loggable object. Objects 59 * that have no transaction id should return 0. 60 */ getTransactionId()61 public long getTransactionId(); 62 63 /** 64 * @return true if these two loggable items are logically the same. 65 * Used for replication testing. 66 */ logicalEquals(Loggable other)67 public boolean logicalEquals(Loggable other); 68 } 69