KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > recovery > CheckpointStart


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: CheckpointStart.java,v 1.27 2006/10/30 21:14:22 bostic Exp $
7  */

8
9 package com.sleepycat.je.recovery;
10
11 import java.nio.ByteBuffer JavaDoc;
12 import java.sql.Timestamp JavaDoc;
13 import java.util.Calendar JavaDoc;
14
15 import com.sleepycat.je.log.LogEntryType;
16 import com.sleepycat.je.log.LogException;
17 import com.sleepycat.je.log.LogReadable;
18 import com.sleepycat.je.log.LogUtils;
19 import com.sleepycat.je.log.LoggableObject;
20
21 /**
22  * CheckpointStart creates a log entry that marks the beginning of a
23  * checkpoint.
24  */

25 public class CheckpointStart implements LoggableObject, LogReadable {
26
27     private Timestamp JavaDoc startTime;
28     private long id;
29
30     /*
31      * invoker is just a way to tag each checkpoint in the log for easier log
32      * based debugging. It will tell us whether the checkpoint was invoked by
33      * recovery, the daemon, the api, or the cleaner.
34      */

35     private String JavaDoc invoker;
36
37     public CheckpointStart(long id, String JavaDoc invoker) {
38         Calendar JavaDoc cal = Calendar.getInstance();
39         this.startTime = new Timestamp JavaDoc(cal.getTime().getTime());
40         this.id = id;
41         if (invoker == null) {
42             this.invoker = "";
43         } else {
44             this.invoker = invoker;
45         }
46     }
47
48     /* For logging only. */
49     public CheckpointStart() {
50     }
51
52     /*
53      * Logging support for writing.
54      */

55
56     /**
57      * @see LoggableObject#getLogType
58      */

59     public LogEntryType getLogType() {
60         return LogEntryType.LOG_CKPT_START;
61     }
62
63     /**
64      * @see LoggableObject#marshallOutsideWriteLatch
65      * Can be marshalled outside the log write latch.
66      */

67     public boolean marshallOutsideWriteLatch() {
68         return true;
69     }
70
71     /**
72      * @see LoggableObject#countAsObsoleteWhenLogged
73      */

74     public boolean countAsObsoleteWhenLogged() {
75         return false;
76     }
77
78     /**
79      * @see LoggableObject#postLogWork
80      */

81     public void postLogWork(long justLoggedLsn) {
82     }
83
84     /**
85      * @see LoggableObject#getLogSize
86      */

87     public int getLogSize() {
88         return LogUtils.getTimestampLogSize() +
89             LogUtils.getLongLogSize() +
90             LogUtils.getStringLogSize(invoker);
91     }
92
93     /**
94      * @see LoggableObject#writeToLog
95      */

96     public void writeToLog(ByteBuffer JavaDoc logBuffer) {
97         LogUtils.writeTimestamp(logBuffer, startTime);
98         LogUtils.writeLong(logBuffer, id);
99         LogUtils.writeString(logBuffer, invoker);
100     }
101
102     /**
103      * @see LogReadable#readFromLog
104      */

105     public void readFromLog(ByteBuffer JavaDoc logBuffer, byte entryTypeVersion)
106     throws LogException {
107
108         startTime = LogUtils.readTimestamp(logBuffer);
109         id = LogUtils.readLong(logBuffer);
110         invoker = LogUtils.readString(logBuffer);
111     }
112
113     /**
114      * @see LogReadable#dumpLog
115      */

116     public void dumpLog(StringBuffer JavaDoc sb, boolean verbose) {
117         sb.append("<CkptStart invoker=\"").append(invoker);
118         sb.append("\" time=\"").append(startTime);
119         sb.append("\" id=\"").append(id);
120         sb.append("\"/>");
121     }
122
123     /**
124      * @see LogReadable#logEntryIsTransactional
125      */

126     public boolean logEntryIsTransactional() {
127     return false;
128     }
129
130     /**
131      * @see LogReadable#getTransactionId
132      */

133     public long getTransactionId() {
134     return 0;
135     }
136 }
137
Popular Tags