001: /*
002: * See the file LICENSE for redistribution information.
003: *
004: * Copyright (c) 2002,2008 Oracle. All rights reserved.
005:
006: */
007: package com.sleepycat.je.utilint;
008:
009: import java.nio.ByteBuffer;
010:
011: import com.sleepycat.je.log.LogException;
012: import com.sleepycat.je.log.Loggable;
013:
014: public class VLSN implements Loggable {
015:
016: public static final int LOG_SIZE = 16;
017:
018: /*
019: * A replicated log entry is identified by
020: * generationId/environmentId/VLSN sequence id. We may change the VLSN
021: * implementation so it's not a first-class object, in order to reduce its
022: * in-memory footprint. In that case, the VLSN value would be a long, and
023: * this class would provide static utility methods.
024: */
025: private int generationId; // make unsigned?
026: private int environmentId; // do we really need this?
027: private long sequence; // sequence number
028:
029: public VLSN(int generationId, int environmentId, long sequence) {
030: this .generationId = generationId;
031: this .environmentId = environmentId;
032: this .sequence = sequence;
033: }
034:
035: /**
036: * Constructor for VLSNs that are read from disk.
037: */
038: public VLSN() {
039: }
040:
041: /**
042: * @see Loggable#getLogSize
043: */
044: public int getLogSize() {
045: return LOG_SIZE;
046: }
047:
048: /**
049: * @see Loggable#writeToLog
050: */
051: public void writeToLog(ByteBuffer buffer) {
052: buffer.putInt(generationId);
053: buffer.putInt(environmentId);
054: buffer.putLong(sequence);
055: }
056:
057: /*
058: * Reading from a byte buffer
059: */
060:
061: /**
062: * @see Loggable#writeToLog
063: */
064: public void readFromLog(ByteBuffer buffer, byte entryTypeVersion)
065: throws LogException {
066: generationId = buffer.getInt();
067: environmentId = buffer.getInt();
068: sequence = buffer.getLong();
069: }
070:
071: /**
072: * @see Loggable#dumpLog
073: */
074: public void dumpLog(StringBuffer sb, boolean verbose) {
075: sb.append("VLSN: ").append("generation id=").append(
076: generationId).append(" environmentId=").append(
077: environmentId).append(" sequence=").append(sequence)
078: .append("\n");
079:
080: }
081:
082: /**
083: * @see Loggable#getTransactionId
084: */
085: public long getTransactionId() {
086: return 0;
087: }
088:
089: public int getContentSize() {
090: return getLogSize();
091: }
092:
093: /**
094: * @param buffer is the destination buffer
095: */
096: public void writeToBuffer(ByteBuffer buffer) {
097: writeToLog(buffer);
098: }
099:
100: /**
101: * BOZO, remove this
102: */
103: public void readFromBuffer(ByteBuffer buffer) throws LogException {
104: readFromLog(buffer, (byte) 0);
105: }
106: }
|