KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > log > CheckpointMonitor


1 /*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002-2005
5 * Sleepycat Software. All rights reserved.
6 *
7 * $Id: CheckpointMonitor.java,v 1.5 2004/12/22 14:11:33 linda Exp $
8 */

9
10 package com.sleepycat.je.log;
11
12 import com.sleepycat.je.DatabaseException;
13 import com.sleepycat.je.config.EnvironmentParams;
14 import com.sleepycat.je.dbi.EnvironmentImpl;
15
16 /**
17  * The checkpoint monitor saves information about log writes to decide when a
18  * checkpoint is needed.
19  */

20 class CheckpointMonitor {
21     private int bytesWritten;
22     private long periodInBytes;
23     private EnvironmentImpl envImpl;
24
25     CheckpointMonitor(EnvironmentImpl envImpl)
26         throws DatabaseException {
27             
28         bytesWritten = 0;
29         periodInBytes = envImpl.getConfigManager().getLong
30         (EnvironmentParams.CHECKPOINTER_BYTES_INTERVAL);
31
32         /*
33          * The period is reset each activation and is not synchronized with the
34          * interval counted by the Checkpointer. Use a small enough period to
35          * invoke the Checkpointer within 10% of its interval.
36          */

37         periodInBytes /= 10;
38         this.envImpl = envImpl;
39     }
40
41     /**
42      * Update checkpoint driving information. Call from within the log write
43      * latch.
44      *
45      * @return true if a checkpoint is needed.
46      */

47     boolean recordLogWrite(int entrySize, LoggableObject item) {
48         bytesWritten += entrySize;
49         return (bytesWritten >= periodInBytes);
50     }
51
52     /**
53      * Wake up the checkpointer. Note that the check on bytesWritten is
54      * actually within a latched period.
55      */

56     void activate() {
57         envImpl.getCheckpointer().wakeup();
58         bytesWritten = 0;
59     }
60 }
61
Popular Tags