1 package com.sleepycat.je.log;
2 
3 import java.nio.ByteBuffer;
4 
5 /**
6  * LogBufferSegment is used by a writer to access
7  * a portion of a LogBuffer.
8  *
9  */
10 class LogBufferSegment {
11     private final LogBuffer logBuffer;
12     private final ByteBuffer data;
13 
LogBufferSegment(LogBuffer lb, ByteBuffer bb)14     public LogBufferSegment(LogBuffer lb, ByteBuffer bb) {
15         logBuffer = lb;
16         data = bb;
17     }
18 
19     /**
20      * Copies the data into the underlying LogBuffer
21      * and decrements the LogBuffer pin count.
22      * @param dataToCopy data to copy into the underlying
23      *        LogBuffer.
24      */
put(ByteBuffer dataToCopy)25     public void put(ByteBuffer dataToCopy) {
26 
27         /*
28          * The acquisition of the log buffer latch is
29          * done to guarantee the java happens-before
30          * semantic. There is no other reason to take the
31          * latch here.
32          */
33         logBuffer.latchForWrite();
34         data.put(dataToCopy);
35         logBuffer.release();
36         logBuffer.free();
37     }
38 }