KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: LatchedLogManager.java,v 1.16 2006/11/03 03:07:50 mark Exp $
7  */

8
9 package com.sleepycat.je.log;
10
11 import java.io.IOException JavaDoc;
12 import java.nio.ByteBuffer JavaDoc;
13 import java.util.List JavaDoc;
14
15 import com.sleepycat.je.DatabaseException;
16 import com.sleepycat.je.cleaner.TrackedFileSummary;
17 import com.sleepycat.je.cleaner.UtilizationTracker;
18 import com.sleepycat.je.dbi.EnvironmentImpl;
19
20 /**
21  * The LatchedLogManager uses the latches to implement critical sections.
22  */

23 public class LatchedLogManager extends LogManager {
24                                            
25     /**
26      * There is a single log manager per database environment.
27      */

28     public LatchedLogManager(EnvironmentImpl envImpl,
29                             boolean readOnly)
30         throws DatabaseException {
31
32         super(envImpl, readOnly);
33     }
34
35     protected LogResult logItem(LoggableObject item,
36                                 boolean isProvisional,
37                                 boolean flushRequired,
38                 boolean forceNewLogFile,
39                                 long oldNodeLsn,
40                                 int oldNodeSize,
41                                 boolean marshallOutsideLatch,
42                                 ByteBuffer JavaDoc marshalledBuffer,
43                                 UtilizationTracker tracker)
44         throws IOException JavaDoc, DatabaseException {
45
46         logWriteLatch.acquire();
47         try {
48             return logInternal
49                 (item, isProvisional, flushRequired, forceNewLogFile,
50                  oldNodeLsn, oldNodeSize, marshallOutsideLatch,
51                  marshalledBuffer, tracker);
52         } finally {
53             logWriteLatch.release();
54         }
55     }
56
57     protected void flushInternal()
58         throws LogException, DatabaseException {
59
60         logWriteLatch.acquire();
61         try {
62             logBufferPool.writeBufferToFile(0);
63         } catch (IOException JavaDoc e) {
64             throw new LogException(e.getMessage());
65         } finally {
66             logWriteLatch.release();
67         }
68     }
69     
70     /**
71      * @see LogManager#getUnflusableTrackedSummary
72      */

73     public TrackedFileSummary getUnflushableTrackedSummary(long file)
74         throws DatabaseException {
75
76         logWriteLatch.acquire();
77         try {
78             return getUnflushableTrackedSummaryInternal(file);
79         } finally {
80             logWriteLatch.release();
81         }
82     }
83
84     /**
85      * @see LogManager#countObsoleteLNs
86      */

87     public void countObsoleteNode(long lsn, LogEntryType type, int size)
88         throws DatabaseException {
89
90         UtilizationTracker tracker = envImpl.getUtilizationTracker();
91         logWriteLatch.acquire();
92         try {
93             countObsoleteNodeInternal(tracker, lsn, type, size);
94         } finally {
95             logWriteLatch.release();
96         }
97     }
98
99     /**
100      * @see LogManager#countObsoleteNodes
101      */

102     public void countObsoleteNodes(TrackedFileSummary[] summaries)
103         throws DatabaseException {
104
105         UtilizationTracker tracker = envImpl.getUtilizationTracker();
106         logWriteLatch.acquire();
107         try {
108             countObsoleteNodesInternal(tracker, summaries);
109         } finally {
110             logWriteLatch.release();
111         }
112     }
113
114     /**
115      * @see LogManager#countObsoleteINs
116      */

117     public void countObsoleteINs(List JavaDoc lsnList)
118         throws DatabaseException {
119
120         logWriteLatch.acquire();
121         try {
122             countObsoleteINsInternal(lsnList);
123         } finally {
124             logWriteLatch.release();
125         }
126     }
127 }
128
Popular Tags